SA-MP Forums Archive
variable question - 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: variable question (/showthread.php?tid=346055)



variable question - Stuneris - 27.05.2012

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?


Re: variable question - Gangs_Rocks - 27.05.2012

EDIT: Fail reply


Re: variable question - MP2 - 27.05.2012

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.


Re: variable question - Stuneris - 27.05.2012

Код:
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


Re: variable question - MP2 - 27.05.2012

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.


Re: variable question - Stuneris - 27.05.2012

Код:
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.


Re: variable question - MP2 - 27.05.2012

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


Re: variable question - Stuneris - 27.05.2012

how?


Re: variable question - MP2 - 27.05.2012

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.