SA-MP Forums Archive
Is there way to get list of layers in vehicle? - 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: Is there way to get list of layers in vehicle? (/showthread.php?tid=409756)



Is there way to get list of layers in vehicle? - scriptit - 22.01.2013

Hello.


I would like to know if there is any good way to get all players who are in given vehicle. I want to give player score for killing someone in car but OnVehicleDeath you don't get player id. I could come up with looping trough all players for IsPlayerInVehicle but then again how do I get list of players.


Re: Is there way to get list of layers in vehicle? - Scenario - 22.01.2013

Something like this, maybe?

pawn Код:
foreach(new i : Player)
{
    if(IsPlayerInAnyVehicle(i))
    {
        new vehID = GetPlayerVehicleID(i);
        if(vehID == vehicleIDtoCheck)
        {
            // Do something...
        }
    }
}



Re: Is there way to get list of layers in vehicle? - scriptit - 22.01.2013

Thanks, I didnt know Player was global variable.


Re: Is there way to get list of layers in vehicle? - Jefff - 22.01.2013

pawn Код:
foreach(new i : Player)
{
    new vehID = GetPlayerVehicleID(i);
    if(vehID > 0 && vehID == VehicleIDToCheck)
    {
        // Do something...
    }
}



Re: Is there way to get list of layers in vehicle? - scriptit - 22.01.2013

Thanks again.


Re: Is there way to get list of layers in vehicle? - scriptit - 22.01.2013

2 problems still...

1)i is always 0 in that loop.
2) killerid is always 255

pawn Код:
public OnVehicleDeath(vehicleid, killerid)
{
    new string[200], killer[MAX_PLAYER_NAME];
    GetPlayerName(killerid, killer, sizeof(killer));
    format(string,sizeof(string),"OnVehicleDeath: vehicleid:%d killerid:%d -> %s",vehicleid, killerid, killer);
    foreach(new i : Player)
    {
        new vehID = GetPlayerVehicleID(i);
        if(vehID == vehicleid)
        {
            new veh_pl[200];
            new name[30];
            GetPlayerName(i,name,30);
            format(veh_pl,sizeof(veh_pl),"OnVehicleDeath -> pl_id = %i (%s)",i,name);
            DebugMsg(-1,0xFFFFFF,veh_pl);
        }
    }
    DebugMsg(-1,0xFFFFFF,string);
    return 1;
}
How do I get correct id of killer (player who shot or rammed that car)? I figured OnPlayerDeath gets called with 65535 killer id automatically which means those who die will loose score but killer don't get any. My intention is to increase score of player who caused wheel to explode by number of players who died in explosion.


Re: Is there way to get list of layers in vehicle? - Scenario - 22.01.2013

You may need to update your foreach include. Otherwise, change it to foreach(Player, i)

In regards to the callback returning the wrong killerid; I BELIEVE there is a bug with the callback in that it doesn't return the proper ID of the person who actually destroyed the vehicle. Instead, it returns the ID of the player who's client reported the vehicle's death. I would of said something earlier, but just remembered reading something about that when you mentioned it returning 255.


Re: Is there way to get list of layers in vehicle? - scriptit - 23.01.2013

Thank you for your reply.
So to get proper killer ID I just need to wait until new binaries are released? So server doesn't check anything and does only what client reports? So if hacker reports that all vehicles had blown up does that make server call OnPlayerDeath() for eveyone who were in cars? And that means score can be altered by hacker? If so I'd really like to see server having more control over players.