07-02-2012, 09:28 PM
So I added the DoWithPlayer() function in Rev 639, here's an actual code that kills a player specified:
Code:
function HandleKill(Split, InitiatorPlayer)
-- InitiatorPlayer is valid throughout this function, even within the local function KillPlayer()
local World = cRoot:Get():GetDefaultWorld()
local PlayerName = Split[2] or ""
if (PlayerName == "") then
InitiatorPlayer:SendMessage(cChatColor.Green .. "Expected the player name to kill as the parameter")
return true
end
local KillPlayer = function(Player)
-- Player is valid only within this function, it cannot be stord and used later!
Player:SendMessage("Incoming gift from " .. InitiatorPlayer:GetName() .. " to " .. PlayerName .. ": " .. (Split[3] or ""))
Player:TakeDamage(100, InitiatorPlayer)
HasFound = true
end
if (not(World:DoWithPlayer(PlayerName, KillPlayer))) then
InitiatorPlayer:SendMessage(cChatColor.Green .. "Could not find player " .. PlayerName)
end
return true
end