Event when an npc gets killed / loop through all peds?


#1

Hey there,

i searched a lot of code for a “onPedKilled” event or similar, but couldn’t find anything.
I thought about just creating a thread that constantly checks all peds if they have been killed (via native functions).

I’m just wondering if i missed a very obvious way to know when a player/environment kills something (other than a player).


#2

Maybe this one will help you:

"PED::IS_PED_DEAD_OR_DYING

Hashes: 0x3317DEDB88C95038 0xCBDB7739
BOOL IS_PED_DEAD_OR_DYING(Ped ped, BOOL p1) // 0x3317DEDB88C95038 0xCBDB7739

Seems to consistently return true if the ped is dead.
p1 is always passed 1 in the scripts.
I suggest to remove “OR_DYING” part, because it does not detect dying phase.
That’s what the devs call it, cry about it.
"

PED::IS_PED_FATALLY_INJURED

Hashes: 0xD839450756ED5A80 0xBADA0093
BOOL IS_PED_FATALLY_INJURED(Ped ped) // 0xD839450756ED5A80 0xBADA0093
MulleDK19: Gets a value indicating whether this ped’s health is below its fatally injured threshold. The default threshold is 100.
If the handle is invalid, the function returns true.

function IsPedInCombat(ped, target)
return _in(0x4859F1FC66A6278E, ped, target, _r)
end


#3

Thanks, did the trick :slight_smile:


#4

actually, im quite stuck.

I didn’t find any way to get all peds, i guess that comes from the fact that peds aren’t synchronized betwenn clients…ups :stuck_out_tongue:
Anyway, i even failed at creating a random ped via createRandomPed(coords), where i get coords through
coords = getEntityCoords(GetPlayerPed(-1), true). Unfortunately coords always returns 0.0 for all coords (coords[‘x’] and so on)
Could anyone please point out to me how i can create a ped that is shared server wide, at the position of a player, and how i can get the player ped/object of the current player in a client script , since GetPlayerPed(-1) or other values than -1 always returns “invalid” when for example used with GetPlayerName(GetPlayerPed(-1)).
What am i doing wrong?

tl;dr: I want to get the location of the player on which a client script runs, and use this to create a ped that is shared on the server :slight_smile:


#5

@the_ch40s I guess it’s not working right now. A lot of natives are only client side don’t know if they can make them server side.


#6

You have to create your Ped Serverside and sync it to a client inside of a threat.

But Notice! Creating Serverside isn’t like “CreatePed” and so on you need variables in in case of this!

You need the following Plan:

Server ->
Create a Ped (maybe an array which includes the, model, posx, posy, poz, …)
TriggerClientEvent (-> Create The Ped in a function Client Side)
Client -> Handle the events from Server and create the Ped like this inside your Client Script

Your clientscript only need a function the check on Start of the Script( Event: OnClientResourceStart) if the server got Ped (TriggerServerEvent, Handlefunction on Server, use the same Event as for Creation.

If you now want to handel death or something else you also have to build these things for: “is the ped dead” or “the ped is gonna kill a player oh my god” and so on hope you see what I mean :stuck_out_tongue:

Last but not least it is possible but it’s a long way to script, because if you want that you ped keep walking around, you need to build waypoints server side or better you need to build the whole KI on Serverside!
But if you want to Create a Ped as a trader or something else -> keep the way I wrote down and be happy :smile:


#7

Da ihr beiden Deutsch seid, kann ich ja mal in deutsch antworten:
Erst mal danke das ihr so hilfsbereit seid.

Mein größtes Problem war dass ich einfach nicht an die Coords vom lokalen Spieler gekommen bin.
coords = getEntityCoords(GetPlayerPed(-1), true) war immer 0, 0, 0, weil GetPlayerPed(-1) wohl nicht funktioniert oO.
Wenn ich GetPlayerFromServerId(int) mache (für alle playerslots 0-31) bekomme ich ein player Objekt von dem ich auch die Coordinaten lesen kann.

Keine Ahnung warum das nicht funktioniert, da ich ja auch andere funktionierende scripts auf dem server habe die es genauso machen. Also iwas übersehe ich da einfach :confused:

Wenn man sich nur die Konsole mit dem gesamten output ausgeben lassen könnte statt der citizenFX.log.

Ich hab immerhin die javascript konsole sichtbar mittlerweile^^


#8

@the_ch40s Hey Ja ich antworte im auf Englisch im Englischen Forum damit das auch später anderen hilft :slight_smile:
daher mal in Deutsch und in Englisch :wink:

English:
Usage of “-1” only return the local ped AND only on client Side! It isn’t working on serverside!
But like I said in my last post, you have to write the whole ped controler serverside, and thats a lot of stuff to do.
But you could use this of course for create a traderped for all players or for doing something like that.

Deutsch:
-1 gibt immer das Ped des lokalen Spielers zurück UND das nur Clientseitig! Geht ergo auf dem Server gar nicht :wink:
Aber wie ich schon schrieb wenn du das wirklich machen willst die Peds Serverseitig steuern kommt vieeeeeel Arbeit auf dich zu außer du nutzt der/die/das Ped als so was wie ein Trader der eine “fixe” Position hat.


#9

@Yashiku
The usage is clientside. No matter what i do i can’t seem to get or set my coords.


#10

@Yashiku I’ve got a /engine (turn off vehicle engine) command working. With PlayerPed(-1) but the engine turning off on the server side too. It’s only for this command. All other are just client side. So I guess it’s not true that PlayerPed -1 is just client side. Or he’s ignoring the PlayerPed -1. Dunno.