I need help with making intregers
#1

Hello everyone! I'm trying to script anti-bike fall off on my script, and I know how to do it with using OnPlayerStateChange() function, etc...


But, the problem is with intregers... I want the player to have anti-fall off on bikes only... I tried to store the intregers using arrays:

Код:
new BikeModels[5][] =
{
     "448",
     "461",
     "462",
     "463",
     "468"
};
But, another problem is that I wasn't even able to make the stock that would check if the player is in a vehicle that has any of those models, and if he is, It should return a TRUE value...

I'd really like you guys to help me with this, thanks in advance.
Reply
#2

You don't need strings, you need numbers:

pawn Код:
new BikeModels[5] = {
     448,
     461,
     462,
     463,
     468
};
Then read up about loops and you're set
Reply
#3

First of all, never use 2D arrays when working with numbers. Also don't put them inside quotes "". They aren't strings. Just advising...
Edit: Misiur w0s fuster xD
pawn Код:
stock IsPlayerInBike(playerid)    //First way:
{
    static const BikeModels[] = {448, 461, 462, 463, 468};
    if(!IsPlayerInAnyVehicle(playerid)) return false;
    new veh = GetPlayerVehicleID(playerid);
    for(new i = 0; i < sizeof(BikeModels); i++)
    {
        if(GetVehicleModel(veh) == BikeModels[i]) return true;
    }
    return false;
}

stock IsPlayerInBike(playerid)    //Second way:
{
    if(!IsPlayerInAnyVehicle(playerid)) return false;
    new veh = GetPlayerVehicleID(playerid);
    switch(GetVehicleModel(veh))
    {
        case: 448, 461, 462, 463, 468: return true;
        default: return false;
    }
    return false;
}
Usage:
pawn Код:
if(IsPlayerInBike(playerid)) return SendClientMessage(playerid, -1, "You are in a bike");
if(!IsPlayerInBike(playerid)) return SendClientMessage(playerid, -1, "You are not in a bike");
Reply
#4

pawn Код:
stock IsPlayerInBike(playerid) {
    new model = GetVehicleModel(GetPlayerVehicleID(playerid));
    return (model == 448 || model == 461 || model == 462 || model == 463 || model == 468);
}
Reply
#5

Thank you all for all of your responses! I appreciate it.

+rep
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)