SA-MP Forums Archive
not working :x - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: not working :x (/showthread.php?tid=201168)



not working :x - MestreKiller - 20.12.2010

why isnt this working?
pawn Код:
public nearpos(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid,20.0,-2034.8167,-85.6803,35.5156))
    {
        if(IsPlayerInAnyVehicle(playerid) != 571)
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid,orange,"You cant be near kart circuit here with a vehicle");
        }
    }
    return 1;
}
if im on foot it says
You cant be near kart circuit here with a vehicle
why?


Re: not working :x - Alex_Valde - 20.12.2010

Because IsPlayerInAnyVehicle doesn't return a value(like number) it just returns: true of false, so you can't actually compare it with something.

You will need GetPlayerVehicleID and then compare it to some value, like Cart ID (571).


Re: not working :x - Benjo - 20.12.2010

The IsPlayerInAnyVehicle function will only ever return 0 or 1. You are comparing it to 571, which it will never be. This is why your != statement always passes and goes on to show the client message.

I believe the correct usage of the IsPlayerInAnyVehicle function in this case would be:
pawn Код:
if(IsPlayerInAnyVehicle(playerid)) // if this is true(1), it will pass. if this is false(0), it will fail.
{
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 571) // check to see if the vehicle is a kart
    {
        RemovePlayerFromVehicle(playerid);
        SendClientMessage(playerid,orange,"You cant be near kart circuit here with a vehicle");
    }
}
GetPlayerVehicleID will return the in-game vehicle ID that a player is in.
GetVehicleModel will return the model ID of a vehicle

Remember that vehicle ID and model ID are different things!