SA-MP Forums Archive
[Help]Player damage when vehicle damage - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Help]Player damage when vehicle damage (/showthread.php?tid=203531)



[Help]Player damage when vehicle damage - jujuv - 27.12.2010

Hi,

I'm making a Destruction Derby GM and i want the player health be equal at the vehicle health (i want : PlayerHealth == VehicleHealth).

i've made this easy with 5 lines but it's not works :

pawn Code:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)///when a vehicle is damage
{
    new Float:vehHealth;// we crate a new var (type Float value 0.0)
    GetVehicleHealth(vehicleid, vehHealth);//we get the vehicle damaged health and store the returned value in vehHealth(value returned e.g: 95.2)
    SetPlayerHealth(playerid, vehHealth);// we set the playerhealth at the value of vehHealth(value of VehHealth after passed in this function e.g : 95)
 /*
 NB: SetPlayerHealth() automaticaly transform vehHealth (Float) in an integer value
 */

}
When the vehicle get damage ,the player health come always at ~5HP .
When the vehicle get damage second , the player donsn't loose HP.

i've try this :

pawn Code:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)///when a vehicle is damage
{
    new Float:vehHealth;// we crate a new var (type Float value 0.0)
    vehHealth = GetVehicleHealth(vehicleid, vehHealth);//we get the vehicle damaged health and store the returned value  in vehHealth(value returned e.g: 95.2)
    SetPlayerHealth(playerid, vehHealth);// we set the playerhealth at the value of vehHealth(value of VehHealth after passed in this function e.g : 95)
 /*
 NB: SetPlayerHealth() automaticaly transform vehHealth (Float) in an integer value
 */

}
and :

pawn Code:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)///when a vehicle is damage
{
      new Float:vehHealth;
    new Float:vehHealth;// we crate a new var (type Float value 0.0)
    vehHealth = GetVehicleHealth(vehicleid, vehHealth);//we get the vehicle damaged health and store the returned value in vehHealth(value returned e.g: 95.2)
    SetPlayerHealth(playerid, vehHealth1);// we set the playerhealth at the value of vehHealth(value of VehHealth after passed in this function e.g : 95)
 /*
 NB: SetPlayerHealth() automaticaly transform vehHealth (Float) in an integer value
 */

}
but it's not work too , so i think the bug come of my SetPlayerHealth() calling.

Help me , please


Re: [Help]Player damage when vehicle damage - Sascha - 27.12.2010

pawn Code:
new Float:vehHealth;
GetVehicleHealth(vehicleid, vehHealth);
SetPlayerHealth(playerid, vehHealth);
should actually work, however you can't do it this way as the max player's health is 100 and the max vehicle's health is 1000....
you should write it in percents to get it working right.


Re: [Help]Player damage when vehicle damage - Hiddos - 27.12.2010

Quote:
Originally Posted by Sascha
View Post
pawn Code:
new Float:vehHealth;
GetVehicleHealth(vehicleid, vehHealth);
SetPlayerHealth(playerid, vehHealth);
should actually work, however you can't do it this way as the max player's health is 100 and the max vehicle's health is 1000....
you should write it in percents to get it working right.
Or simply:

pawn Code:
new Float:HP;
GetVehicleHealth(vehicleid, HP);
SetPlayerHealth(playerid, HP / 10);



Re : [Help]Player damage when vehicle damage - jujuv - 27.12.2010

Tanks , i'm so stupid :d


Re: [Help]Player damage when vehicle damage - jameskmonger - 27.12.2010

The vehicle has 10 times as much health


Re : [Help]Player damage when vehicle damage - jujuv - 28.12.2010

pawn Code:
public OnPlayerUpdate(playerid)// This is a part of a very simply script made by Jujuv
{
    if(GetPlayerState(playerid) == 2)
    {
        new Float:vehHealth;// we crate a new var (type Float value 0.0)
        new Float:playerArmour;//we create a new var (type floatvalue 0.0)
        new curentVeh = GetPlayerVehicleID(playerid);//Get the vehicle (id) of the player (and store it in curentVeh)
        GetVehicleHealth(curentVeh, vehHealth);//Get the vehicle health and store it in vehHealth(value returned e.g: 2500.2)
        vehHealth = vehHealth/10;// we divide the value of vehHealth per 10
        SetPlayerHealth(playerid, vehHealth);//Set the health of the vehicle at the health of the player(value e.g : 250)
        if(GetPlayerArmour(playerid,playerArmour) != 0)// if the armour of the playerArmour is not equal at 0 (player have armour)
        {
        SetPlayerArmour(playerid,0);//Set the armour ofthe player at 0 ("delete his armour")
        SetPlayerHealth(playerid, vehHealth);//Set the health of the vehicle at the health of the player
        }
    }

}
It's works but i think it use more bandwich :/


Re: Re : [Help]Player damage when vehicle damage - _rAped - 28.12.2010

Quote:
Originally Posted by jujuv
View Post
pawn Code:
public OnPlayerUpdate(playerid)
{
    if(GetPlayerState(playerid) == 2)
    {
        new Float:vehHealth;// we crate a new var (type Float value 0.0)
        new Float:playerArmour;
        new curentVeh = GetPlayerVehicleID(playerid);
        GetVehicleHealth(curentVeh, vehHealth);//we get the vehicle damaged health and store the returned value in vehHealth(value returned e.g: 95.2)
        vehHealth = vehHealth/10;
        SetPlayerHealth(playerid, vehHealth);// we set the playerhealth at the value of vehHealth(value of VehHealth after passed in this function e.g : 95)
        if(GetPlayerArmour(playerid,playerArmour) != 0)
        {
        SetPlayerArmour(playerid,0);
        SetPlayerHealth(playerid, vehHealth);
        }
    }

}
It's works but i think it use more bandwich :/
That's probably because you call it whenever the player updates, which is like several times a second depending on what the player is doing. I guess he's driving a vehicle out from the information you gave us. Make a callback and a timer or something.