B*tch slapped lua

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

Moderators: Forum moderators, developers

Post Reply
BenMcDermott
Posts: 47
Joined: Sat Jan 14, 2006 6:31 am

B*tch slapped lua

Post by BenMcDermott »

Post content removed
Last edited by BenMcDermott on Thu Jul 31, 2014 7:19 am, edited 1 time in total.
BenMcDermott
Posts: 47
Joined: Sat Jan 14, 2006 6:31 am

Post by BenMcDermott »

Post content removed
Last edited by BenMcDermott on Thu Jul 31, 2014 7:19 am, edited 1 time in total.
User avatar
ReyalP
Posts: 1663
Joined: Fri Jul 25, 2003 11:44 am

Post by ReyalP »

You are setting their health to -5, not taking 5 away from it.
send lawyers, guns and money
BenMcDermott
Posts: 47
Joined: Sat Jan 14, 2006 6:31 am

Post by BenMcDermott »

Post content removed
Last edited by BenMcDermott on Thu Jul 31, 2014 7:19 am, edited 1 time in total.
User avatar
=FF=im2good4u
Posts: 3821
Joined: Wed Feb 05, 2003 7:30 am
Location: The Netherlands, HOLLAND
Contact:

Post by =FF=im2good4u »

oke here is wut u need

Code: Select all

function et_ConsoleCommand()
	--if u use string.lower it will also match SLAP or Slap
	if string.lower(et.trap_Argv(0)) == "slap" then
		slap(et.trap_Argv(1))
		return 1
	else
		--for all other commands we return 0
		return 0
	end
end

function slap(client)
    --first check if client is a number
    local clientnum = tonumber(client)
    if clientnum then
        --if clientnum is not nill then the player entered a real number
		--now check its its a valid client nuber else we cancel the operation
		if &#40;clientnum >= 0&#41; and &#40;clientnum < 64&#41; then
			--now its a valid clien slo we check is there is nay client connected
			if et.gentity_get&#40;clientnum,"pers.connected"&#41; ~= 2 then
				et.G_Print&#40;"You must enter a valid client slot number or name\n"&#41;
				return
			end 
		else              
			--print an error
			et.G_Print&#40;"You must enter a valid client slot number or name\n"&#41;
			return
		end
	--if clientnum isnt a number
	else
	    --now we try to find the player his nanme amoung all the clients
        clientnum = getPlayernameToId&#40;client&#41;
        
        --check up is the function didnt return nil
        if not clientnum then
			et.G_Print&#40;"You must enter a valid client slot number or name\n"&#41;
			return
		end
	end
	
	--oke now we got a client slot to slap
	--remove 5 health
	et.gentity_set&#40;clientnum,"health",&#40;et.gentity_get&#40;clientnum,"health"&#41;-5&#41;&#41;
	
	--print a message to all clients
	et.trap_SendServerCommand&#40;-1,"print \"".. et.gentity_get&#40;clientnum,"pers.netname"&#41; .." ^1was slapped by the ^3Server Admin^7\n\""&#41;
end

function getPlayernameToId&#40;name&#41;
	local i
	for i=0,63,1 do
	    if et.gentity_get&#40;i,"pers.netname"&#41; == name then
	        return i
		end
	end
	return nil
end
it has wut u want + error checking on tthe value the player enters

only no barbwire sound it should be posable but i never worked whit a lua sounds so im not gona struggle on it :P
User avatar
Deus
Posts: 1053
Joined: Fri Mar 12, 2004 2:24 am
Location: Germany
Contact:

Post by Deus »

Cleaned it up from some minor spelling errors and added sound option.
Added name color filtering and additional error handling.

Code: Select all

function et_ConsoleCommand&#40;&#41; 
	-- use string.lower to catch miscapitalized commands
		if string.lower&#40;et.trap_Argv&#40;0&#41;&#41; == "slap" then 
			if &#40;et.trap_Argc&#40;&#41; < 2&#41; then
				et.G_Print&#40;"You need to enter a valid Client slotnumber or name\n"&#41;
				return 1
			end
			slap&#40;et.trap_Argv&#40;1&#41;&#41; 
		return 1 
		else 
		-- for all other commands we return 0 
		return 0 
   		end 
end 

function slap&#40;client&#41; 
	-- first check if client is a number 
	local clientnum = tonumber&#40;client&#41; 
	if clientnum then 
	-- If clientnum is not NIL then the number is real. 
	-- Now check if its a valid client number. If not we cancel the operation. 
		if &#40;clientnum >= 0&#41; and &#40;clientnum < 64&#41; then
		-- now its a valid client slot. Now we check if there is any client connected 
			if et.gentity_get&#40;clientnum,"pers.connected"&#41; ~= 2 then 
				et.G_Print&#40;"You need to enter a valid Client slotnumber or name\n"&#41; 
			return 
			end 
		else              
		-- print error message 
			et.G_Print&#40;"You need to enter a valid Client slotnumber or name\n"&#41; 
		return 
		end 
	-- if clientnum != a number, but a name
	else 
	-- now we try to find the players name among all the clients 
		if client then
			clientnum = getPlayernameToId&#40;client&#41;
		end
		-- check if the function didn't return NIL 
			if not clientnum then 
			-- print error message
			et.G_Print&#40;"You need to enter a valid Client slotnumber or name\n"&#41; 
			return 
			end 
	end 
    -- ok now we got a clientslot to slap 
		-- remove 5 health 
			et.gentity_set&#40;clientnum,"health",&#40;et.gentity_get&#40;clientnum,"health"&#41;-5&#41;&#41; 
	
		-- play the sound
		-- get the soundindex for the barbwire sound
			soundindex = et.G_SoundIndex&#40;"sound/player/hurt_barbwire.wav" &#41;
		
		-- play the sound only to the player that got slapped and those near him
			et.G_Sound&#40; clientnum , soundindex &#41;

		-- print message to all clients 
			et.trap_SendServerCommand&#40;-1,"print \"".. et.gentity_get&#40;clientnum,"pers.netname"&#41; .." ^1was slapped by the ^3Server Admin^7\n\""&#41; 
end 

-- returns clientslot for given name, or nil if no match found
-- added color stripping
function getPlayernameToId&#40;name&#41; 
	local i 
	for i=0,63,1 do
	playeri = et.gentity_get&#40;i,"pers.netname"&#41;
		if playeri then
			if et.Q_CleanStr&#40; playeri &#41; == et.Q_CleanStr&#40; name &#41; then 
			return i 
			end 
		end
	end
	return nil 
end
BenMcDermott
Posts: 47
Joined: Sat Jan 14, 2006 6:31 am

Post by BenMcDermott »

Post content removed
Last edited by BenMcDermott on Thu Jul 31, 2014 7:20 am, edited 1 time in total.
User avatar
Deus
Posts: 1053
Joined: Fri Mar 12, 2004 2:24 am
Location: Germany
Contact:

Post by Deus »

credits go to Im2good4u
Post Reply