associate vehicle health to a certain player? -
PawnoQ - 27.11.2011
hi,
just wondering, how could i check on a derby gamemode after some time what vehicle has the most health left and associate this to a certain player?
I know how to check what vehicle has the most health left by looping but how would i get the players name that is driving the vehicle with the most health?
I hope u get what i mean
thx.
Re: associate vehicle health to a certain player? -
Ash. - 27.11.2011
You'd need "GetVehicleDriver" which is not a SAMP native, though can be created:
pawn Код:
stock GetVehicleDriver(vehicleid)
{
for(new i; i < GetMaxPlayers(); i++)
{
if(GetPlayerVehicleID(i) == vehicleid) return i;
}
return INVALID_PLAYER_ID;
}
Bare in mind that vehicle health can go upto 1000, whereas player health can only go up to 100.
So:
pawn Код:
//Get the vehicle with the most health - store it in a variable called "MostHealth".
//Get the vehicles health - store it in a variable called "VehicleHealth".
new vDriver = GetVehicleDriver(MostHealth);
SetPlayerHealth(vDriver, VehicleHealth / 10);
//Dividing it by 10, as 10% of 1000 ( MAX VEH HEALTH ) = 100 (MAX PLAYER HEALTH).
Re: associate vehicle health to a certain player? -
PawnoQ - 27.11.2011
so vDriver would be the playerID of the vehicle with the most health?
Could i get the vehicle with the most health with this algorithm correctly?
pawn Код:
new highesth;
for(new i = 0; i < sizeof(MostHealth); i++)
if(MapsToVote[i] > highesth)
highesth = MostHealth[i];
thx already for ur help
Re: associate vehicle health to a certain player? -
Ash. - 27.11.2011
pawn Код:
new Float:MostHealth, Float:vHealth, vDriver, veh;
for(new i; i < MAX_VEHICLES; i++)
{
GetVehicleHealth(i, vHealth);
if(vHealth > MostHealth)
{
MostHealth = vHealth;
veh = i;
}
}
vDriver = GetVehicleDriver(veh);
SetPlayerHealth(vDriver, (MostHealth/10));
That should, in theory, work. However it will work for all vehicles, not just ones in a certain area or assigned to a certain array, for example.
Modify it to suit your needs.
Re: associate vehicle health to a certain player? -
PawnoQ - 27.11.2011
thx, i think that should help me
+rep ofc.
Re: associate vehicle health to a certain player? -
PawnoQ - 28.11.2011
sorry for double post but i think we missunderstood in the previous post...
I would like to get the player that is driving the vehicle with the most health.
The health of the player itself doesnt matter here.
Would be good if someone could help me once again
Re: associate vehicle health to a certain player? -
Ash. - 28.11.2011
Just take out the "SetPlayerHealth" part, and "vDriver" is the driver of the vehicle with the most health!
Re: associate vehicle health to a certain player? -
PawnoQ - 28.11.2011
ah, ok thx then

and sorry for disturbing
If there should be probs imma post again