Help with detecting vehicle damage
#1

Hi, I have a problem. I want to do something when player damage vehicle. For test I want to SetPlayerMessage.

Top in my script:
Код:
new Float:dhp[MAX_PLAYERS];
public OnGameModeInit:
Код:
SetTimer("DamageUpdate", 1000, true);
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger):
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
		new vehiclepid;
		vehiclepid = GetPlayerVehicleID(playerid);
                dhp[playerid] = GetVehicleHealth(vehiclepid, dhp[playerid]);
		return 1;
}
Down in my script:
Код:
forward DamageUpdate(playerid);
public DamageUpdate(playerid)
{
		new vehicleid;
		vehicleid = GetPlayerVehicleID(playerid);
		new Float:nhp;
		nhp = GetVehicleHealth(vehicleid, nhp);
		if(nhp != dhp[playerid]) SendClientMessage(playerid,-1,"{FFFFFF}Damage"), dhp[playerid] = nhp;

}
It show message only when I get in/out vehicle. But I want to show when I damage a vehicle.
Sorry for my bad english. ; <
Reply
#2

Change This:
pawn Код:
public DamageUpdate(playerid)
{
        new vehicleid;
        vehicleid = GetPlayerVehicleID(playerid);
        new Float:nhp;
        nhp = GetVehicleHealth(vehicleid, nhp);
        if(nhp != dhp[playerid]) SendClientMessage(playerid,-1,"{FFFFFF}Damage"), dhp[playerid] = nhp;

}
To This:
pawn Код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
new vehicleid;
        vehicleid = GetPlayerVehicleID(playerid);
        new Float:nhp;
        nhp = GetVehicleHealth(vehicleid, nhp);
        if(nhp != dhp[playerid]) SendClientMessage(playerid,-1,"{FFFFFF}Damage"), dhp[playerid] = nhp;
          return 1;
}
EDIT: and delete
pawn Код:
forward DamageUpdate(playerid);
Reply
#3

huh why you write like that
Код:
dhp[playerid] = GetVehicleHealth(vehiclepid, dhp[playerid]);
and
Код:
nhp = GetVehicleHealth(vehicleid, nhp);
?

only should be like that

Код:
GetVehicleHealth(vehiclepid, dhp[playerid]);
and
Код:
GetVehicleHealth(vehicleid, nhp);
Reply
#4

why you dont just use this
https://sampwiki.blast.hk/wiki/OnVehicleDamageStatusUpdate
Reply
#5

Okey, thanks guys. I use OnVehicleDamageStatusUpdate and all it's working, THANKS!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)