Begging for help (Important)
#1

Ok, i was too proud and didn't want to ask tried to make it all by myself but i simple couldn't do it...

I want to prevent a player to get into some vehicles... but i get some errors,

CODE:

pawn Код:
if(gClass == CLASS_PILOT)
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
    new veh, Float:x,Float:y,Float:z;
    veh = GetPlayerVehicleID(playerid);
    if(veh > 425 || 447 || 464 || 476 || 520)
    GetPlayerPos(playerid, x,y,z);
    SetPlayerPos(playerid, x,y,z+1);
    }else return SendClientMessage(playerid, red, "[ERROR]: You need to be a pilot to fly this vehicle");
    return 1;
    }
}
Errors:
pawn Код:
C:\Users\Guille\Desktop\Samp scripting\Server23\Server\gamemodes\WD.pwn(3406) : warning 219: local variable "str" shadows a variable at a preceding level
C:\Users\Guille\Desktop\Samp scripting\Server23\Server\gamemodes\WD.pwn(5815) : error 033: array must be indexed (variable "gClass")
C:\Users\Guille\Desktop\Samp scripting\Server23\Server\gamemodes\WD.pwn(5826) : error 010: invalid function or declaration
Line 3406: new str[300];
Line 5815: if(gClass == CLASS_SOLDIER)
Line 5826: }
}
}
Reply
#2

1. You already have 'str' declared somewhere else (either in a preceding level of that scope or globally)
2. The gClass variable is an array, so must be indexed. For example
pawn Код:
gClass[playerid]
3. You have an extra brace
Reply
#3

in the line
Код:
Line 3406: new str[300];
, the variable "str" got declared already, maybe global, or in the same function above.
either reuse the string without declaring it again, or use a different stringname, like str2 or Str.

the gClass variable is missing the index/cell. i assume it got declared for [MAX_PLAYERS], so this should work:
Код:
if(gClass[playedrid] == CLASS_PILOT)
...presuming that the playerid is the default parameter (you didnt declare "id" in a loop for playerids, did you?)

at line 5826, iam clueless. show more code plox.


edit: good morning, early birds
Reply
#4

I've fixed it, thank you both.

Both rep+
Reply
#5

anyway, i think your code doesn't work.. because you need to get vehicle model(GetVehicleModel(vehicleid)) not the vehicle id..
pawn Код:
if(gClass[playerid] == CLASS_PILOT)
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
    new veh, Float:x,Float:y,Float:z;
    veh = GetPlayerVehicleID(playerid);
    if(veh > 425 || 447 || 464 || 476 || 520)
    GetPlayerPos(playerid, x,y,z);
    SetPlayerPos(playerid, x,y,z+1);
    }else return SendClientMessage(playerid, red, "[ERROR]: You need to be a pilot to fly this vehicle");
    return 1;
    }
}



if your code is bugged then try This..
FIXED
pawn Код:
if(gClass[playerid] != CLASS_PILOT)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        new veh,model, Float:x,Float:y,Float:z;
        veh = GetPlayerVehicleID(playerid);
        model = GetVehicleModel(veh );
        if(model == 425 || model == 447 ||model ==  464 || model ==  476 || model == 520)
        {
        GetPlayerPos(playerid, x,y,z);
        SetPlayerPos(playerid, x,y,z+1);
        return SendClientMessage(playerid, red, "[ERROR]: You need to be a pilot to fly this vehicle");
        }
    }
}
Reply
#6

Good you got your problem fixed heres the code btw

Код:
if(gClass[playerid] == CLASS_PILOT)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
    new veh, Float:x,Float:y,Float:z;
    veh = GetPlayerVehicleID(playerid);
    if(veh > 425 || 447 || 464 || 476 || 520)
    {
    GetPlayerPos(playerid, x,y,z);
    SetPlayerPos(playerid, x,y,z+1);
    }
     else return SendClientMessage(playerid, red, "[ERROR]: You need to be a pilot to fly this vehicle");
    return 1;
    }
}
And you have str already defind as told by other ._o
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)