Im trying to get a lua mod running that will disable SK for a player after the player has committed 3 selfkills. Thought I had it working but it turned out that after player reaches the selfkill limit, no players are able to selfkill. Which is kinda logical when I think about it, Ive tried to fix it, not for too long though, but ATM I haven't got any more ideas on how to fix it, so thought Id ask
ATM the script looks like this, I think the problem has to do with the "if skcount[cno] == (selfkill_limit + 3) then" etc part, and whats following, seeing that everything works fine until that command kicks in for the first time.
Anyone got an idea on how to fix this?
(I want it to be 3 selfkills = that single player can no longer selfkill..)
Code: Select all
--Disable selfkill after 3 selfkills
-- Naturally, the amount can be changed by changing the number 3 to the amount u want on line 39 & 52
--By Dinius
-- Credits to GhosT:McSteve for original
-- selfkill penalty which this is based on
selfkill_limit = 0
--on game initialise, get the maxclients and initialise the skcount array
function et_InitGame( levelTime, randomSeed, restart )
maxclients = tonumber( et.trap_Cvar_Get( "sv_maxClients" ) )
skcount = {}
for i = 0, maxclients - 1 do
skcount[i] = 0
end
end
--on client disconnect, empty the skcount for that slot
function et_ClientDisconnect( clientNum )
skcount[clientNum] = 0
end
--on a player death, check the meansofdeath and increment skcount if player selfkilled
function et_Obituary( victim, killer, meansOfDeath )
--if selfkill (=37) then increment skcount for the client
if meansOfDeath == 37 then
skcount[victim] = skcount[victim] + 1
--issue warnings on death rather than on spawn as in previous version
if skcount[victim] == 1 then
et.trap_SendServerCommand( victim, "b 32 \"^9Selfkills ^81/3\n\"" )
elseif skcount[victim] == 2 then
et.trap_SendServerCommand( victim, "b 32 \"^9Selfkills ^82/3\n\"" )
elseif skcount[victim] == 3 then
et.trap_SendServerCommand( victim, "b 32 \"^8You have reached the selfkill limit!\n\"" ) end
end
end
--on a player spawn, set any selfkill punishments
function et_ClientSpawn(cno, revived)
if skcount[cno] == 0 then return 0 end --if player's skcount = 0 then do nothing
if revived == 0 then
-- Action to perform when limit reached
if skcount[cno] == (selfkill_limit + 3) then
--set the new conditions MUHAHA! ;)
function et_ClientCommand(clientNum, command)
if string.lower(command) == "kill" then
et.trap_SendServerCommand( clientNum, "b 32 \"^8You have selfkilled enough for this map...\n\"" )
return 0
end
end
end
end
end