B*tch slapped lua
Moderators: Forum moderators, developers
-
- Posts: 47
- Joined: Sat Jan 14, 2006 6:31 am
B*tch slapped lua
Post content removed
Last edited by BenMcDermott on Thu Jul 31, 2014 7:19 am, edited 1 time in total.
-
- Posts: 47
- Joined: Sat Jan 14, 2006 6:31 am
Post content removed
Last edited by BenMcDermott on Thu Jul 31, 2014 7:19 am, edited 1 time in total.
-
- Posts: 47
- Joined: Sat Jan 14, 2006 6:31 am
Post content removed
Last edited by BenMcDermott on Thu Jul 31, 2014 7:19 am, edited 1 time in total.
- =FF=im2good4u
- Posts: 3821
- Joined: Wed Feb 05, 2003 7:30 am
- Location: The Netherlands, HOLLAND
- Contact:
oke here is wut u need
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
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 (clientnum >= 0) and (clientnum < 64) then
--now its a valid clien slo we check is there is nay client connected
if et.gentity_get(clientnum,"pers.connected") ~= 2 then
et.G_Print("You must enter a valid client slot number or name\n")
return
end
else
--print an error
et.G_Print("You must enter a valid client slot number or name\n")
return
end
--if clientnum isnt a number
else
--now we try to find the player his nanme amoung all the clients
clientnum = getPlayernameToId(client)
--check up is the function didnt return nil
if not clientnum then
et.G_Print("You must enter a valid client slot number or name\n")
return
end
end
--oke now we got a client slot to slap
--remove 5 health
et.gentity_set(clientnum,"health",(et.gentity_get(clientnum,"health")-5))
--print a message to all clients
et.trap_SendServerCommand(-1,"print \"".. et.gentity_get(clientnum,"pers.netname") .." ^1was slapped by the ^3Server Admin^7\n\"")
end
function getPlayernameToId(name)
local i
for i=0,63,1 do
if et.gentity_get(i,"pers.netname") == name then
return i
end
end
return nil
end
only no barbwire sound it should be posable but i never worked whit a lua sounds so im not gona struggle on it
<a href="http://bunnyherolabs.com/adopt/showpet. ... dQ=="><img src="http://petimage.bunnyherolabs.com/adopt ... Q0dQ==.png" width="80" height="100" border="0"></a>
Cleaned it up from some minor spelling errors and added sound option.
Added name color filtering and additional error handling.
Added name color filtering and additional error handling.
Code: Select all
function et_ConsoleCommand()
-- use string.lower to catch miscapitalized commands
if string.lower(et.trap_Argv(0)) == "slap" then
if (et.trap_Argc() < 2) then
et.G_Print("You need to enter a valid Client slotnumber or name\n")
return 1
end
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 NIL then the number is real.
-- Now check if its a valid client number. If not we cancel the operation.
if (clientnum >= 0) and (clientnum < 64) then
-- now its a valid client slot. Now we check if there is any client connected
if et.gentity_get(clientnum,"pers.connected") ~= 2 then
et.G_Print("You need to enter a valid Client slotnumber or name\n")
return
end
else
-- print error message
et.G_Print("You need to enter a valid Client slotnumber or name\n")
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(client)
end
-- check if the function didn't return NIL
if not clientnum then
-- print error message
et.G_Print("You need to enter a valid Client slotnumber or name\n")
return
end
end
-- ok now we got a clientslot to slap
-- remove 5 health
et.gentity_set(clientnum,"health",(et.gentity_get(clientnum,"health")-5))
-- play the sound
-- get the soundindex for the barbwire sound
soundindex = et.G_SoundIndex("sound/player/hurt_barbwire.wav" )
-- play the sound only to the player that got slapped and those near him
et.G_Sound( clientnum , soundindex )
-- print message to all clients
et.trap_SendServerCommand(-1,"print \"".. et.gentity_get(clientnum,"pers.netname") .." ^1was slapped by the ^3Server Admin^7\n\"")
end
-- returns clientslot for given name, or nil if no match found
-- added color stripping
function getPlayernameToId(name)
local i
for i=0,63,1 do
playeri = et.gentity_get(i,"pers.netname")
if playeri then
if et.Q_CleanStr( playeri ) == et.Q_CleanStr( name ) then
return i
end
end
end
return nil
end
-
- Posts: 47
- Joined: Sat Jan 14, 2006 6:31 am
Post content removed
Last edited by BenMcDermott on Thu Jul 31, 2014 7:20 am, edited 1 time in total.