Help with grouping vehicles.
#1

Hello everyone! I have a problem with OnPlayerEnterVehicle, i currently have two vehicle groups on my server, and they are rent vehicles(8 of them) and vehicles for a job(5 of them).


When a player trys to enter a job vehicle, and he is not an employee of that job, he will get kicked out of that vehicle, here's the code:
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(vehicleid == vmkamioni[0] || vmkamioni[1] || vmkamioni[2] || vmkamioni[3] || vmkamioni[4])
	{
		if(PlayerInfo[playerid][pPosao] != 1)
		{
			SCM, "[ E ] | {FFFFFF}Niste zaposleni kao vozac maltera.");
			ClearAnimations(playerid);
		}
	}
	return 1;
}
And that works perfectly, however, when somebody tries to enter the rent vehicle he can't enter it because he gets that same message from above: [ E ] | {FFFFFF}Niste zaposleni kao vozac maltera.");

The rent vehicle group is called BesplatnaAuta, and i did not include them in any callback, I just used BesplatnaAuta[0] = AddStaticVehicle(etc)


If
Reply
#2

pawn Код:
if(vehicleid == vmkamioni[0] || vmkamioni[1] || vmkamioni[2] || vmkamioni[3] || vmkamioni[4])
This is a valid code, but not what you have in mind. You have to repeat vehicleid == vmkamion1[1] etc etc
Reply
#3

Okay, thank you, I'll just try that and tell you is it working.

EDIT: I tested and it's working, I didn't know how simple was that, thank you again :P
Reply
#4

Pro tip: use a loop for these things. Even if there are only two or three. If you decide to add or remove vehicles to the array later then you don't have to rewrite the loop at all.

PHP код:
for(new isizeof vmkamionii++)
{
    if(
vehicleid == vmkamioni[i])
    {
        
// do your stuff
        
break;
    }

If you use the same structure more than once then you can even abstract the loop to a separate function so you don't have to repeat the entire loop structure each time.

PHP код:
stock bool:IsVehicleInArray(vehicleidvehicles[], size sizeof vehicles)
{
    for(new 
isizei++)
    {
        if(
vehicleid == vehicles[i])
        {
            return 
true;
        }
    }
    return 
false;

PHP код:
if(IsVehicleInArray(vehicleidvmkamioni))
{
    
// do your stuff

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)