How to get attacked user/mob
#3
The TDI.Attacker represents the attacker, it can be either a cPlayer object or a cMonster descendant. So you should first test it with the IsA() function and if it is a cPlayer, then cast it:
function OnTakeDamage(a_Receiver, a_TDI)
    if ((a_TDI.Attacker == nil) or not(a_TDI.Attacker:IsA("cPlayer"))) then
        -- The attacker is not a player
        return
    end

    -- Get the true cPlayer object out of a_TDI.Attacker:
    local Player = tolua.cast(a_TDI.Attacker, "cPlayer")

    -- Just show off what we can do with it:
    LOG("Player " .. Player:GetName() .. " attacked a " .. a_Receiver:GetClass())

    -- If the player attacked a cow, kick them
    if (a_Receiver:IsA("cCow")) then
        Player:Kick("The cow is a sacred animal")
    end
end
Reply
Thanks given by:


Messages In This Thread
How to get attacked user/mob - by Nathanchunkie - 12-21-2014, 01:22 PM
RE: How to get attacked user/mob - by tonibm19 - 12-21-2014, 06:54 PM
RE: How to get attacked user/mob - by xoft - 12-22-2014, 12:29 AM



Users browsing this thread: 2 Guest(s)