Is there way to get list of layers in vehicle?
#1

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

Something like this, maybe?

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

Thanks, I didnt know Player was global variable.
Reply
#4

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

Thanks again.
Reply
#6

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)