Jump to content

How can I get the player who killed me with hunter rocket?


GTX

Recommended Posts

maybe ..

  
addEventHandler("onPlayerWasted",root,function(ammo,killer) 
     if killer and getElementType(killer) == "vehicle" then 
             vehOwner = getVehicleOccupant(killer,0) 
                if vehOwner then 
                     outputChatBox(getPlayerName(vehOwner).." has killed you .",source,255,100,100,true) 
                end 
     end 
end )  
  

or ..

-- Client

  
addEventHandler("onClientProjectileCreation",root,function(creator) 
     if creator then 
             setElementData(source,"creator",creator) 
     end 
end )  
end )  
  

-- Server

  
addEventHandler("onPlayerWasted",root,function(ammo,killer) 
     if killer and getElementType(killer) == "projectile" then 
             proCar = getElementData(killer,"creator") 
                if proCar then 
                               vehOwner = getVehicleOccupant(proCar ,0) 
                if vehOwner then 
                     outputChatBox(getPlayerName(vehOwner).." has killed you .",source,255,100,100,true) 
                end 
                end 
     end 
end )  
  

Link to comment

Maybe this?

addEventHandler("onPlayerWasted", root,  
function(source, killer) 
     if killer and 
getElementType(killer) =="player" then 
     if getPedOccupiedVehicle(killer) == "theIdOfHunter" then -- put the id of hunter sorry i dont remember that. 
outputChatBox(getPlayerName(killer).." has killed you.", source, 255, 100, 100, true) 
                end 
     end 
end) 

Link to comment
This question has been made more than two times, and the answer always been that you can't get the killer of the rocket that hit you, because you die when the vehicle explodes.

It is possible. I have already seen that script in TG server.

Link to comment

There is no certain way to get the killer, but you can use onClientExplosion and check distance from the explosion to the other vehicle that got exploded in a time frame of 50-250milisecs.

I did that for my achievements script and it is working pretty good actually.

Link to comment

Ok, here is some shitty old code:

  
-- client sided 
addEventHandler("onClientExplosion", getRootElement(), 
function(x, y, z, theType) 
    triggerServerEvent("onRequestShowKiller", source, x, y, z, theType) 
end) 
  

-- server sided 
addEvent("onRequestShowKiller", true) 
addEventHandler("onRequestShowKiller", getRootElement(), 
function(x, y, z, theType) 
    if(x == nil)then return end 
    local player = getElementsByType("player") 
    for i = 1, #player do 
        local vehX, vehY, vehZ = getElementPosition(player[i]) 
        if(getDistanceBetweenPoints3D(x, y, z, vehX, vehY, vehZ) <= 20)then 
            kira[source][#kira[source]+1] = player[i] 
        end 
    end 
end) 

and then onVehicleExplode i write who killed who.

You will need to edit the code because it is shi**y

Link to comment
Ok, here is some :~ old code:
  
-- client sided 
addEventHandler("onClientExplosion", getRootElement(), 
function(x, y, z, theType) 
    triggerServerEvent("onRequestShowKiller", source, x, y, z, theType) 
end) 
  

-- server sided 
addEvent("onRequestShowKiller", true) 
addEventHandler("onRequestShowKiller", getRootElement(), 
function(x, y, z, theType) 
    if(x == nil)then return end 
    local player = getElementsByType("player") 
    for i = 1, #player do 
        local vehX, vehY, vehZ = getElementPosition(player[i]) 
        if(getDistanceBetweenPoints3D(x, y, z, vehX, vehY, vehZ) <= 20)then 
            kira[source][#kira[source]+1] = player[i] 
        end 
    end 
end) 

and then onVehicleExplode i write who killed who.

You will need to edit the code because it is shi**y

Thank you, but how can I get attacker?

Link to comment

The way I did it for TG:

When you fire a projectile, mark it with setElementData (store the player that fired it)

Then, there are collision spheres around every player. If the missile enters the collision shape of the player, the player is marked with that missile's ID. Now, if the player dies a few moments later, you can simply use getElementData on the missile to find the player that fired the rocket. If the player didn't die within, say, 500 milliseconds, clear the rocket's ID from the player.

Not a very reliable way to do it, but it works decently.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...