SA-MP Forums Archive
Vehicles Owned by 1 person, Script Bug - 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: Vehicles Owned by 1 person, Script Bug (/showthread.php?tid=494104)



Vehicles Owned by 1 person, Script Bug - Aerotactics - 11.02.2014

I'm trying to make this simple, so while the code is elementary, all I need it to do is prevent other players from getting into the "gcars", yet this script causes ALL server cars to be unable to enter (except by "Jason_Budley" (server owner, me))

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new G_Check=GetPlayerVehicleID(playerid);
	if (G_Check==gcar||gcar2||gcar3||gcar4||gcar5||gcar6||gcar7||gcar8||gcar9)
	{
	    new PlayerName[24];
  		GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
    	if (strcmp(PlayerName,"Jason_Budley",true))
    	{
    	    ClearAnimations(playerid);
    	    return 1;
    	}
	}
	else
	{
	    return 1;
	}
	return 1;
}



Re: Vehicles Owned by 1 person, Script Bug - PowerPC603 - 11.02.2014

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    switch (vehicleid)
    {
        case gcar, gcar2, gcar3, gcar4, gcar5, gcar6, gcar7, gcar8, gcar9:
        {
            new PlayerName[24];
            GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
            if (strcmp(PlayerName,"Jason_Budley",true))
            {
                ClearAnimations(playerid);
                return 1;
            }
        }
    }

    return 1;
}



Re: Vehicles Owned by 1 person, Script Bug - Aerotactics - 11.02.2014

Код:
C:\Users\Aerotactics' PC\Desktop\LS-RP\filterscripts\[RP]LH.pwn(235) : error 008: must be a constant expression; assumed zero
I get this error.


Re: Vehicles Owned by 1 person, Script Bug - PowerPC603 - 11.02.2014

On which line?


Re: Vehicles Owned by 1 person, Script Bug - Aerotactics - 11.02.2014

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
On which line?
the "case ..." line


Re: Vehicles Owned by 1 person, Script Bug - PowerPC603 - 11.02.2014

My bad. Forgot that switch case needs constants, not variables.

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if ((vehicleid == gcar) || (vehicleid == gcar2) || (vehicleid == gcar3) || (vehicleid == gcar4) || (vehicleid == gcar5) || (vehicleid == gcar6) || (vehicleid == gcar7) || (vehicleid == gcar8) || (vehicleid == gcar9))
    {
            new PlayerName[24];
            GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
            if (strcmp(PlayerName,"Jason_Budley",true))
            {
                ClearAnimations(playerid);
                return 1;
            }
    }

    return 1;
}
If you used an array to store those vehicle id's, it would be simpler and shorter:
pawn Код:
new gcars[10];

// Somewhere:
gcars[0] = CreateVehicle(...
gcars[1] = Createvehicle(...
...
gcars[9] = CreateVehicle(...





public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    for (new i; i < sizeof(gcars); i++)
    {
        if (vehicleid == gcars[i])
        {
            new PlayerName[24];
            GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
            if (strcmp(PlayerName,"Jason_Budley",true))
            {
                ClearAnimations(playerid);
                return 1;
            }
        }
    }

    return 1;
}
If you increased the size of gcars to 20 for example, you don't even have to modify this code, as it loops through the entire array and checks if the vehicle you're trying to enter is one of those gcars.

With the first example, you would need to add 10 extra checks to that code and you risk another error to indicate your line has become too long.


Re: Vehicles Owned by 1 person, Script Bug - Aerotactics - 11.02.2014

Yeah, I figured it out, thanks for the help.