SA-MP Forums Archive
Just a simple question. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Just a simple question. (/showthread.php?tid=192378)



Just a simple question. - Lars_Frederiksen - 22.11.2010

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?


Re: Just a simple question. - Gamer_Z - 22.11.2010

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;
}



Re: Just a simple question. - LarzI - 22.11.2010

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


Re: Just a simple question. - MP2 - 21.09.2011

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


Re: Just a simple question. - Dr - 22.09.2011

Why not just onplayerdeath get the killerid.