variable question
#1

Hello all, I have problem. I use variable pd[55] in "if" I use:

Код:
if(vid == pd[0]||vid == pd[1]||vid == pd[2]||vid == pd[3]||vid == pd[4]||vid == pd[5]||vid == pd[6]||vid == pd[7]||vid == pd[8]||vid == pd[9]||vid == pd[10]||vid == pd[11]||vid == pd[12]||vid == pd[13]||vid == pd[14]||vid == pd[15]||
		vid == pd[16]||vid == pd[17]||vid == pd[18]||vid == pd[19]||vid == pd[20]||vid == pd[21]||vid == pd[22]||vid == pd[23]||vid == pd[24]||vid == pd[25]||vid == pd[26]||vid == pd[27]||vid == pd[28]||vid == pd[29]||vid == pd[30]||
		vid == pd[31]||vid == pd[32]||vid == pd[33]||vid == pd[34]||vid == pd[35]||vid == pd[36]||vid == pd[37]||vid == pd[38]||vid == pd[39]||vid == pd[40]||vid == pd[41]||vid == pd[42]||vid == pd[43]||vid == pd[44]||vid == pd[45]||
		vid == pd[46]||vid == pd[47]||vid == pd[48]||vid == pd[49]||vid == pd[50]||vid == pd[51]||vid == pd[52]||vid == pd[53]||vid == pd[54]||)
how to shorten this script?
Reply
#2

EDIT: Fail reply
Reply
#3

Wow. That's a lot of code!

pawn Код:
new pd[?];

// To check if they are in any of the pd[] vehicles:

new vid = GetPlayerVehicleID(playerid);
new found;
for(new i=0; i<sizeof(pd); i++) // Loop through all pd[x] vehicle IDs
{
    if(vid == pd[i]) // If they are in that vehicle
    {
        found = 1;
        break; // End loop
    }
}
if(found)
{
    // They are in one of the pd[x] vehicles
}
else
{
    // They are not
}
A word of advice - name your vehicles better. When you come back in the future you'll be like 'what the fuck is pd[]' and end up looking all through your code trying to work it out. For example, gPoliceVehicleID[] instead.
Reply
#4

Код:
for(new i=0; i<sizeof(taxi); i++)
		{
		    if(vid == taxi[i])
		    {
			    if(IsPlayerInVehicle(playerid, i))
				{
				    if(pInfo[playerid][specialybe] != SPEC_TAXI)
				    {
				        SendClientMessage(playerid, 0xFF0000FF, "Negalite vairuoti љio transporto, nes nedirbate taksistu.");
				        SetVehicleToRespawn(GetPlayerVehicleID(playerid));
				        return 1;
				    }
				    else
				    {
				        SendClientMessage(playerid, 0x99FF00FF, "Sveikas, taksiste, vairuodamas љį transportą ir veћiodamas ћmonės, gausite 50LT/min.");
						darbo_timer = SetTimerEx("Dirba", 60000, true, "i", playerid);
					}
				}
			}
		}
with this code not work
Reply
#5

You don't need to use IsPlayerInVehicle, just the vid variable, which is GetPlayerVehicleID. Debug your code with SendClientMessage so you can see what's happening.
Reply
#6

Код:
for(new i=0; i<sizeof(taxi); i++)
		{
		    if(vid == taxi[i])
		    {
		    	if(pInfo[playerid][specialybe] != SPEC_TAXI)
		    	{
      				SendClientMessage(playerid, 0xFF0000FF, "Negalite vairuoti šio transporto, nes nedirbate taksistu.");
      				SetVehicleToRespawn(GetPlayerVehicleID(playerid));
      				return 1;
		    	}
		    	else
		    	{
      				SendClientMessage(playerid, 0x99FF00FF, "Sveikas, taksiste, vairuodamas šį transportą ir vežiodamas žmonės, gausite 50LT/min.");
					darbo_timer = SetTimerEx("Dirba", 60000, true, "i", playerid);
				}
			}
		}
not working yet.
Reply
#7

Why do people ignore me?

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'

'Debug your code with SendClientMessage so you can see what's happening.'
Reply
#8

how?
Reply
#9

pawn Код:
for(new i=0; i<sizeof(taxi); i++)
        {
            if(vid == taxi[i])
            {
                        SendClientMessage(playerid, -1, "vehicle found");
                if(pInfo[playerid][specialybe] != SPEC_TAXI)
                {
                    SendClientMessage(playerid, 0xFF0000FF, "Negalite vairuoti љio transporto, nes nedirbate taksistu.");
                    SetVehicleToRespawn(GetPlayerVehicleID(playerid));
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, 0x99FF00FF, "Sveikas, taksiste, vairuodamas љį transportą ir veћiodamas ћmonės, gausite 50LT/min.");
                    darbo_timer = SetTimerEx("Dirba", 60000, true, "i", playerid);
                }
            }
        }
See if it sends that message to you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)