Help me with my script.
#1

hye, today i tried to create a script which would check if there is a passenger in vehicle. i have tested this script with my friend and all the time i get " there is no passenger" even if there is. so please help me to fix this.

Код:
CMD:command(playerid)
{
	new 
		vehicleid = GetPlayerVehicleID(playerid),
		passengerID = INVALID_PLAYER_ID;
		
		if(AccountInfo[playerid][Job] == JOB_TAXI)
		{
			for(new p; p < MAX_PLAYERS; p++)
			{
				if(IsPlayerInVehicle(p, 438 && 420 ) && GetPlayerState(p) == PLAYER_STATE_PASSENGER)
				{
					passengerID = p;
					break;
				}	
			}
			if(passengerID == passengerID == INVALID_PLAYER_ID)
			{
				SendClientMessage(playerid, -1, "There is no passenger");
			}
			else
			{
				SendClientMessage(playerid, -1, "There is one");
			}
		}
	return true;
}
Reply
#2

pawn Код:
CMD:command(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "You must be in a vehicle to use this command.");
    new vehicleid = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(vehicleid) != 420 && GetVehicleModel(vehicleid) != 438) return SendClientMessage(playerid, 0xFF0000FF, "You must be in a taxi to use this command.");
    if(AccountInfo[playerid][Job] == JOB_TAXI)
    {
        new string[145];
        new count = 0;
        new pName[MAX_PLAYER_NAME];
        for(new p = 0; p < MAX_PLAYERS; p++)
        {
            if(IsPlayerConnected(p))
            {
                if(IsPlayerInVehicle(p, vehicleid))
                {
                    if(GetPlayerState(p) == PLAYER_STATE_PASSENGER)
                    {
                        GetPlayerName(p, pName, MAX_PLAYER_NAME);
                        format(string, sizeof(string), "%s(%d) is a passenger in this vehicle.", pName, p);
                        SendClientMessage(playerid, 0xFFFF00FF, string);
                        count++;
                    }
                }
            }
        }
        if(count == 0)
        {
            SendClientMessage(playerid, 0xFF0000FF, "There are no passengers in this vehicle.");
        }
        else
        {
            format(string, sizeof(string), "There are currently %d passenger(s) in this vehicle.", count);
            SendClientMessage(playerid, -1, string);
        }
    }
    return 1;
}
NOTE: This will also include you, if you are a passenger in the vehicle. No this was not copied from anywhere, I've just conjured it up for you.
Reply
#3

pawn Код:
for(new p = 0; p < MAX_PLAYERS; p++)
Why are you using a for loop for this? Foreach was invented for a reason, use it!
Reply
#4

I can't force someone to use foreach so I did a loop, but yes, if you get the opportunity you should use it.
(Not even sure if that was directed at me, but whatever)
Reply
#5

thanks you very much. You helped me a lot!
Reply
#6

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
I can't force someone to use foreach so I did a loop, but yes, if you get the opportunity you should use it.
(Not even sure if that was directed at me, but whatever)
No, you cannot force someone to use it. However, if you're going to provide code you should provide the most efficient code (i.e. using foreach, not a for loop). If someone is too lazy to download and include foreach (or y_iterate if you have the YSI library already), then that's their problem. You shouldn't enable people to use bad scripting methods!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)