lua selfkill question

Discussions about ET modding (sdk code, player/weapon modeling)

Moderators: Forum moderators, developers

Post Reply
Dinius
Posts: 3
Joined: Thu Oct 18, 2007 5:55 am

lua selfkill question

Post by Dinius »

Hey!

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 :o ;)


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



User avatar
Luk4ward
Posts: 236
Joined: Sun Jul 30, 2006 1:55 pm
Location: Poland
Contact:

Post by Luk4ward »

well, this is my idea and working script is here:

http://wolfwiki.anime.net/index.php/Use ... t_v1_1.lua

so i dnt see a reason to rewrite it, whats your addons then?

btw the last part should looks like:

Code: Select all

--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(cno, command)
              if string.lower(command) == "kill" then
                et.trap_SendServerCommand( cno, "b 32 \"^8You have selfkilled enough for this map...\n\"" )
                return 0
              end
            end
      end


   end
end
coz u r calling function with cno (client number) not with clientNum:

Code: Select all

function et_ClientSpawn(cno, revived)
And note#2: i dnt think so u can run function in the function ... You have to make some tricks on global vars then
wolFTeam.pl
Dinius
Posts: 3
Joined: Thu Oct 18, 2007 5:55 am

Post by Dinius »

The difference between the scripts is that mine won't inflict penalties etc, it will disable \kill for anyone who has done it 3 times.

Makes no diff wether or not I have client, clientNum or cno there, it does the same thing every time..

I want it to prevent that ONE player from to do any more \kills, but when ONE player has made 3 selfkills, ALL the players are prevented from selfkilling. aka I think there is something not right with the below part. Seeing that when initiated it will disable \kill for all players, how can I do so that it will disable only for ONE player?

Code: Select all

         --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
 
User avatar
=FF=im2good4u
Posts: 3821
Joined: Wed Feb 05, 2003 7:30 am
Location: The Netherlands, HOLLAND
Contact:

Post by =FF=im2good4u »

Code: Select all

function et_ClientCommand(clientNum, command)
what u are doing is overwriting the client command functionb

now this function get called for every player on the server only clientnum is different so what u realy want todo is now only check in command is "kill" but also check the clientNum if its from one of the players u wana block :roll:

so what do u need todo ? this
seperate the clientspawn function the skcount much be a globar variable
like this:

Code: Select all

--on a player spawn, set any selfkill punishments 
function et_ClientSpawn(cno, revived)     
  --u dont need this function
end 
 
         function et_ClientCommand(clientNum, command) 
              if string.lower(command) == "kill" and skcount[clientNum] >= (selfkill_limit + 3) then 

                et.trap_SendServerCommand( clientNum, "b 32 \"^8You have selfkilled enough for this map...\n\"" ) 
                return 0 
              end 
            end 
thats all since u cant just overwrite the et_ClientCommand function for 1 client it willl overwrite for all
Dinius
Posts: 3
Joined: Thu Oct 18, 2007 5:55 am

Post by Dinius »

Many many many thanks :D

Return needs to be 1, so it will prevent the selfkill, but else its working like a charm :D

Again, many thanks :wink:
Post Reply