PDA

View Full Version : Just a simple question.


Lars_Frederiksen
22/11/2010, 11:58 AM
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?

Gamer_Z
22/11/2010, 12:12 PM
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:

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):

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,ispassenge r){
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;
}

LarzI
22/11/2010, 12:30 PM
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

MP2
21/09/2011, 11:47 PM
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.)

Dr
22/09/2011, 03:49 AM
Why not just onplayerdeath get the killerid.