associate vehicle health to a certain player?
#1

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.
Reply
#2

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).
Reply
#3

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
Reply
#4

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.
Reply
#5

thx, i think that should help me

+rep ofc.
Reply
#6

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
Reply
#7

Just take out the "SetPlayerHealth" part, and "vDriver" is the driver of the vehicle with the most health!
Reply
#8

ah, ok thx then
and sorry for disturbing

If there should be probs imma post again
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)