[HELP] Command Bug.
#1

Hey, I added Neon System on my GM, and I added command /neon for turn on or turn off the neon, it's worked when I outside the vehicle, but, when I Inside the vehicle, it's say command not found.
This is the command:
pawn Код:
CMD:neon(playerid, params[])
{
    new vehid = GetPlayerVehicleID(playerid);
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            if(PlayerVehicleInfo[playerid][vehid][pvNeon] >= 1)
            {
                if(Neon[vehid] == 1)
                {
                    UnloadNeon(playerid, vehid);
                    SendClientMessageEx(playerid, COLOR_GREY, "Neon turned off.");
                    Neon[vehid] = 0;
                }
                else
                {
                    LoadNeon(playerid, vehid);
                    SendClientMessageEx(playerid, COLOR_GREY, "Neon turned on.");
                    Neon[vehid] = 1;
                }
            }
            else SendClientMessageEx(playerid, COLOR_GREY, "This vehicle doesn't have neon!");
        }
        else SendClientMessageEx(playerid, COLOR_GREY, "You are not the driver!");
    }
    else SendClientMessageEx(playerid, COLOR_GREY, "You are not inside Vehicle!");
    return 1;
}
Please Help
Reply
#2

have you tried to put something like SendClientMessageEx(playerid, COLOR_GREY, "Neon Check."); in the script to check till where it goes right and where it got stuck on?

for instance if it dont show up after if(PlayerVehicleInfo[playerid][vehid][pvNeon] >= 1) but it does before you know something goes wrong with the info
Reply
#3

Im Using
pawn Код:
new Neon[MAX_PLAYERS]
doesnt work then I Change to
pawn Код:
new Neon[MAX_PLAYERS] = INVALID_VEHICLES_ID;
doesnt work too, what function should I use ?
Reply
#4

Try this:
Код:
CMD:neon(playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new vehid = GetPlayerVehicleID(playerid);
            if(PlayerVehicleInfo[playerid][vehid][pvNeon] >= 1)
            {
                if(Neon[vehid] == 1)
                {
                    UnloadNeon(playerid, vehid);
                    SendClientMessageEx(playerid, COLOR_GREY, "Neon turned off.");
                    Neon[vehid] = 0;
                }
                else if(Neon[vehid] == 0)
                {
                    LoadNeon(playerid, vehid);
                    SendClientMessageEx(playerid, COLOR_GREY, "Neon turned on.");
                    Neon[vehid] = 1;
                }
            }
            else return SendClientMessageEx(playerid, COLOR_GREY, "This vehicle doesn't have neon!");
        }
        else return SendClientMessageEx(playerid, COLOR_GREY, "You are not the driver!");
    }
    else return SendClientMessageEx(playerid, COLOR_GREY, "You are not inside a Vehicle!");
    return 1;
}
Where did you go wrong?
Код:
 if(Neon[vehid] == 1)
                {
                    UnloadNeon(playerid, vehid);
                    SendClientMessageEx(playerid, COLOR_GREY, "Neon turned off.");
                    Neon[vehid] = 0;
                }
                else if(Neon[vehid] == 0)
                {
                    LoadNeon(playerid, vehid);
                    SendClientMessageEx(playerid, COLOR_GREY, "Neon turned on.");
                    Neon[vehid] = 1;
                }
You use else instead of an else if statement, otherwise you would be setting the variable to 0, therefore the code just resets.
Reply
#5

The problem is, when i use the command inside the vehicle, its say unknown command, but when i outside the vehicle it's say You Must Inside Vehicle aka Work.
Reply
#6

Try using a switch statement instead of multiple 'ifs.' It's clearer and helps you get the problem easily.
Also, as 'HireMe' said, Put print messages after everyline, like print("Check 1."); to see where you script stops working.
Reply
#7

switch like what ?
Reply
#8

Switch something like this https://sampwiki.blast.hk/wiki/Control_Structures#switch_2
Reply
#9

Give a try.

PHP код:
CMD:neon(playeridparams[])
{
     if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER) return SendClientMessageEx(playeridCOLOR_GREY"You are not the driver!");
     if(
PlayerVehicleInfo[playerid][vehid][pvNeon] < _:true) return SendClientMessageEx(playeridCOLOR_GREY"This vehicle doesn't have neon!");
     if(
Neon[vehid] == _:true) return (UnloadNeon(playeridvehid),SendClientMessageEx(playeridCOLOR_GREY"Neon turned off."),Neon[vehid] = false,true);
     return (
LoadNeon(playeridvehid),SendClientMessageEx(playeridCOLOR_GREY"Neon turned on."),Neon[vehid] = true,true);

Reply
#10

I Think the error is this.
pawn Код:
new Neon[MAX_VEHICLES];
The command stop when
pawn Код:
if(Neon[vehid] == 1)
Is the
pawn Код:
new Neon[MAX_VEHICLES];
wrong ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)