How to check if there is a driver in the car or not?
#1

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    new playerState = GetPlayerState(killerid); // Get the killer's state
 
    if (playerState == PLAYER_STATE_PASSENGER ) // If the killer was in a vehicle,alright. What about and there were no drivers in it?
    {
// do the stuff.
    }
    return 1;
}
Read the if statement. How can I manage to do a thing like this?

So simply it will check if there is no players in the car of the killerid (a driver) if there is a driver it won't do anything.
Reply
#2

1. Get the vehicle id
2. Loop through all players (except for killer), and check if they are inside this car, and their state is "teh driver"
3.
4. Profit
Reply
#3

Something like this would work:

pawn Код:
stock DoesVehicleHaveDriver(vehicleid)
{
    #if defined foreach
    foreach(new i : Player)
    #else
    for(new i = 0; i < MAX_PLAYERS; i++)
    #endif 
    {
        if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER) return true;
    }
    return false;
}
Reply
#4

pawn Код:
new playerState = GetPlayerState(killerid); // Get the killer's state
    if (playerState == PLAYER_STATE_PASSENGER ) // If the killer was in a vehicle,alright. What about and there were no drivers in it?
    {
    if(DoesVehicleHaveDriver(vehicleid)) return 0;
    }
pawn Код:
stock DoesVehicleHaveDriver(vehicleid)
{
    #if defined foreach
    foreach(new i : Player)
    #else
    for(new i = 0; i < MAX_PLAYERS; i++)
    #endif  
    {
        if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER) return true;
    }
    return false;
}
Код:
C:\Users\Tamer\Desktop\pwn\AVT scripting\gamemodes\GameMode.pwn(3588) : error 017: undefined symbol "vehicleid"
C:\Users\Tamer\Desktop\pwn\AVT scripting\gamemodes\GameMode.pwn(3617) : warning 217: loose indentation
C:\Users\Tamer\Desktop\pwn\AVT scripting\gamemodes\GameMode.pwn(3618) : warning 217: loose indentation
C:\Users\Tamer\Desktop\pwn\AVT scripting\gamemodes\GameMode.pwn(9245) : error 017: undefined symbol "foreach"
C:\Users\Tamer\Desktop\pwn\AVT scripting\gamemodes\GameMode.pwn(9245) : error 029: invalid expression, assumed zero
C:\Users\Tamer\Desktop\pwn\AVT scripting\gamemodes\GameMode.pwn(9245) : error 017: undefined symbol "i"
C:\Users\Tamer\Desktop\pwn\AVT scripting\gamemodes\GameMode.pwn(9245) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
Reply
#5

In your code, replace vehicleid with GetPlayerVehicleID(playerid)

In mine, remove the things with a # in front and then remove the foreach line.
Reply
#6

Yes,I tried to do this on my own and worked,thanks for the help,no errors now. I need to test it thought.

Posting incase someone would like to learn how this works
pawn Код:
new playerState = GetPlayerState(killerid);
    if (playerState == PLAYER_STATE_PASSENGER )
    {
    new vehicleid = GetPlayerVehicleID(killerid);
    if(DoesVehicleHaveDriver(vehicleid)) return 0;
    }
pawn Код:
stock DoesVehicleHaveDriver(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER) return true;
    }
    return false;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)