How to get attacked user/mob
#1
Hi,

Can't find in the API how to register the user or mob that is attacked by a cPlayer. Do I miss anything or is it impossible to log?

Code:
function OnTakeDamage(Receiver, TDI)
    
    if ((TDI.Attacker ~= nil) and TDI.Attacker:IsA("cPlayer")) then
        TDI.FinalDamage = 999;
        LOG("Player attacked a")
        LOG(Receiver);
    end

end
Reply
Thanks given by:
#2
Try:
ReceiverPlayer = tolua.cast(Receiver, "cPlayer")
Or
ReceiverMob = tolua.cast(Receiver, " cMonster")
Reply
Thanks given by:
#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:




Users browsing this thread: 2 Guest(s)