So I've finally started implementing some SourceOP stuff in Lua. What this means is that you will be able to customize or add commands and other things in SourceOP. Here's an example of e_kill.
Code:
function drawkillbeam( startpos, endpos )
local beamindex = util.PrecacheModel("effects/laser1.vmt");
effects.Beam(startpos, endpos, beamindex, 0, 0, 0, 0.2, 5, 5, 0, 5, math.random(200,255), math.random(0,15), math.random(0,15), 255, 20)
effects.Beam(startpos, endpos, beamindex, 0, 0, 0, 0.2, 5, 5, 0, 1, math.random(200,255), math.random(100,146), math.random(32,96), 255, 20)
end
// specifies entities that are not valid for killing
function validkillent( classname )
if(string.sub(classname, 1, 12) == "prop_vehicle") then
return false
end
return true
end
function ekill( playerid, command, arguments )
local pPlayer = player.GetByID(playerid)
if(pPlayer) then
if(pPlayer:IsAdmin(1024, "e_kill")) then
if(!pPlayer:IsEntMoving()) then
local ent, endpos = pPlayer:FindEntityForward(MASK_ALL)
if(ent) then
local classname = ent:GetClassname()
if(validkillent(classname)) then
drawkillbeam(pPlayer:GetAbsOrigin(), endpos)
if(classname != "player") then
// kill the entity with explosion sound
ent:EmitSound("^weapons/explode" .. math.random(3,5) .. ".wav", 60, math.random(90,110))
ent:Kill()
else
// slay the player
local pDeadPlayer = player.GetByID(ent:EntIndex())
pDeadPlayer:Kill()
end
end
end
else
pPlayer:SayText("You are currently moving an entity and cannot run " .. command .. ".\n")
end
else
pPlayer:SayText("You do not have access to the command " .. command .. ".\n", HUD_PRINTCONSOLE)
end
else
// command run at server console
// kill each entity id specified on command line
for k,v in pairs(arguments) do
if k >= 1 then
local ent = ents.GetByIndex(tonumber(v))
ent:Kill()
end
end
end
end
if(sourceop.FeatureStatus(FEAT_ENTCOMMANDS)) then
concommand.Add("e_kill", ekill)
end
What can you do with this?
Well, one example I thought of is if I or anybody else wanted, we could add another command (e.g e_kill_fromplayer) based off this code that allows an admin to force a player to run e_kill. This command could be run from the server console or executed by event scripts or something to force a player to e_kill. In fact, such a command would be simple:
Code:
function ekillfromplayer( playerid, command, arguments )
local pPlayer = player.GetByID(arguments[1])
if(pPlayer) then
local ent, endpos = pPlayer:FindEntityForward(MASK_ALL)
if(ent) then
local classname = ent:GetClassname()
if(validkillent(classname)) then
drawkillbeam(pPlayer:GetAbsOrigin(), endpos)
if(classname != "player") then
// kill the entity with explosion sound
ent:EmitSound("^weapons/explode" .. math.random(3,5) .. ".wav", 60, math.random(90,110))
ent:Kill()
else
// slay the player
local pDeadPlayer = player.GetByID(ent:EntIndex())
pDeadPlayer:Kill()
end
end
end
end
end
concommand.Add("e_kill_fromplayer", ekillfromplayer)
I haven't tested that e_kill_fromplayer code, but it should work. Almost all of this code was reused from e_kill.
This is just a preview of things to come. Any comments?