Posts: 73
Threads: 27
Joined: Oct 2010
Reputation:
0
Okay guys I was wondering how to Detect the player who hit you to blow you your car.
For example: Two players hit me when I'm in my car, my car catches on fire. My car blows up. How can I detect the player who got the winning hit?
Posts: 1,047
Threads: 23
Joined: Jun 2009
22.11.2010, 12:12
(
Последний раз редактировалось Gamer_Z; 22.11.2010 в 12:33.
)
Quote:
pawn Код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid) { printf("Vehicle ID %d was damaged by playerid %d.", vehicleid, playerid); return 1; }
|
At least you can use this..
My sugestion:
pawn Код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
new Float:h;
GetVehicleHealth(vehicleid,h);
if(h =< 0){//car is burning
printf("Player %s has set the car with id %d on fire",playerid,vehicleid);
}
return 1;
}
Then you just search for an GetVehicleDriver function and voila.
or put this in your script(Made by me,
not bug-free due to
code-limitations):
pawn Код:
new vehicledriverid[MAX_VEHICLES] = {-1,...};
stock GetVehicleDriver(vehicleid)return vehicledriverid[vehicleid];//returns -1 if vehicle has no driver
/*
ALT:
*/
/*
public OnPlayerStateChange(playerid,newstate,oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)vehicledriverid[GetPlayerVehicleID(playerid)] = playerid;
if(oldstate == PLAYER_STATE_DRIVER && newstate != PLAYER_STATE_DRIVER)vehicledriverid[GetPlayerVehicleID(playerid)] = -1;
return 1;
}
*/
/*
RECOMMENDED YOU USE:
*/
public OnPlayerEnterVehicle(playerid,vehicleid,ispassenger){
if(!ispassenger) vehicledriverid[vehicleid] = playerid;
return 1;
}
public OnPlayerExitVehicle(playerid,vehicleid){
//Important Note: Not called if the player falls off a bike or is removed from a vehicle by other means such as using SetPlayerPos
if(GetVehicleDriver(vehicleid) == playerid)vehicledriverid[vehicleid] = -1;
return 1;
}
Posts: 2,628
Threads: 32
Joined: Apr 2007
Reputation:
0
If you set vehicle HP to 100 it starts to burn, so I would increase the vehicle health check to atleast 100(100.0) instead of 0
Posts: 6,236
Threads: 310
Joined: Jan 2011
Reputation:
0
Vehicles burn from 250 downwards. OnVehicleDamageStatusUpdate only gets called when VISUAL damage is inflicted - you can't detect when someone shoots your vehicle (okay perhaps a highly in-accurate one with complicated maths and the camera functions, but a native function would be better tbh.)
Posts: 120
Threads: 22
Joined: Jul 2011
Reputation:
0
Why not just onplayerdeath get the killerid.