SA-MP Forums Archive
strcmp(cmdtext) problem - 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: strcmp(cmdtext) problem (/showthread.php?tid=406852)



strcmp(cmdtext) problem - [rG]Cold - 11.01.2013

pawn Код:
if(strcmp(cmd, "/v", true) == 0 || strcmp(cmd, "/vehicle", true) == 0)
    {
        if(PlayerInfo[playerid][pPcarkey] != 0)
        {
        if(IsPlayerConnected(playerid))
        {
            new x_nr[256];
            x_nr = strtok(cmdtext, idx);
            if(!strlen(x_nr))
            {
                SendClientMessage(playerid, COLOR_WHITE, "HINT: (/v)ehicle [name]");
                SendClientMessage(playerid, COLOR_WHITE, "Available names: fix(1-2)");
                return 1;
            }
            if(strcmp(x_nr,"fix1",true) == 0)
            {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                            if(SBizzInfo[8][sbProducts] == 0)
                            {
                                GameTextForPlayer(playerid, "~r~Out Of Stock", 5000, 1);
                                return 1;
                            }
                            SendClientMessage(playerid, COLOR_GRAD1,"{00C8FF}» {2641FE}PersonalCar 1 was respawned !");
                            SetVehicleToRespawn(PlayerInfo[playerid][pPcarkey]);
                            PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                            SBizzInfo[8][sbTill] += 1000;
                            ExtortionSBiz(8, 1000);
                            SBizzInfo[8][sbProducts]--;
                            GivePlayerMoney(playerid, -1000);
                        }
                        else GameTextForPlayer(playerid, "~w~Car is~n~in ~r~use", 5000, 1);
                    }
                    else GameTextForPlayer(playerid, "~r~Not Enough Cash", 5000, 1);
                }
                if(strcmp(x_nr,"fix2",true) == 0)
                {
                if(!IsPlayerInAnyVehicle(playerid))
                        {
                            if(SBizzInfo[8][sbProducts] == 0)
                            {
                                GameTextForPlayer(playerid, "~r~Out Of Stock", 5000, 1);
                                return 1;
                            }
                            SendClientMessage(playerid, COLOR_GRAD1,"{00C8FF}» {2641FE}PersonalCar 2 was respawned !");
                            SetVehicleToRespawn(PlayerInfo[playerid][pPcarkey2]);
                            PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                            SBizzInfo[8][sbTill] += 1000;//towcar buisness
                            ExtortionSBiz(8, 1000);//ba codu e ok :|
                            SBizzInfo[8][sbProducts]--;
                            GivePlayerMoney(playerid, -1000);
                        }
                        else GameTextForPlayer(playerid, "~w~Car is~n~in ~r~use", 5000, 1);
                    }
                    else GameTextForPlayer(playerid, "~r~Not Enough Cash", 5000, 1);
                }
            }
A friend gave me this script to post here cuz he doesnt know english soo ermm the thing is that the error he gets is

Код:
undefined symbol: x_nr
On this line:
pawn Код:
if(strcmp(x_nr,"fix2",true) == 0)



Re: strcmp(cmdtext) problem - Vince - 11.01.2013

Rule N° 1: Do not copy shit from the godfather script. Now, if we were to properly indent the script, like this:
pawn Код:
if(strcmp(cmd, "/v", true) == 0 || strcmp(cmd, "/vehicle", true) == 0)
{
    if(PlayerInfo[playerid][pPcarkey] != 0)
    {
        if(IsPlayerConnected(playerid))
        {
            new x_nr[256];
            x_nr = strtok(cmdtext, idx);
            if(!strlen(x_nr))
            {
                SendClientMessage(playerid, COLOR_WHITE, "HINT: (/v)ehicle [name]");
                SendClientMessage(playerid, COLOR_WHITE, "Available names: fix(1-2)");
                return 1;
            }
            if(strcmp(x_nr,"fix1",true) == 0)
            {
                if(!IsPlayerInAnyVehicle(playerid))
                {
                    if(SBizzInfo[8][sbProducts] == 0)
                    {
                        GameTextForPlayer(playerid, "~r~Out Of Stock", 5000, 1);
                        return 1;
                    }
                    SendClientMessage(playerid, COLOR_GRAD1,"{00C8FF}» {2641FE}PersonalCar 1 was respawned !");
                    SetVehicleToRespawn(PlayerInfo[playerid][pPcarkey]);
                    PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                    SBizzInfo[8][sbTill] += 1000;
                    ExtortionSBiz(8, 1000);
                    SBizzInfo[8][sbProducts]--;
                    GivePlayerMoney(playerid, -1000);
                }
                else GameTextForPlayer(playerid, "~w~Car is~n~in ~r~use", 5000, 1);
            }
            else GameTextForPlayer(playerid, "~r~Not Enough Cash", 5000, 1);
        }
        if(strcmp(x_nr,"fix2",true) == 0)
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                if(SBizzInfo[8][sbProducts] == 0)
                {
                    GameTextForPlayer(playerid, "~r~Out Of Stock", 5000, 1);
                    return 1;
                }
                SendClientMessage(playerid, COLOR_GRAD1,"{00C8FF}» {2641FE}PersonalCar 2 was respawned !");
                SetVehicleToRespawn(PlayerInfo[playerid][pPcarkey2]);
                PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                SBizzInfo[8][sbTill] += 1000;//towcar buisness
                ExtortionSBiz(8, 1000);//ba codu e ok :|
                SBizzInfo[8][sbProducts]--;
                GivePlayerMoney(playerid, -1000);
            }
            else GameTextForPlayer(playerid, "~w~Car is~n~in ~r~use", 5000, 1);
        }
        else GameTextForPlayer(playerid, "~r~Not Enough Cash", 5000, 1);
    }
}
We would clearly see that the fix2 structure is out of scope. Oops!


Re: strcmp(cmdtext) problem - crouch010 - 11.01.2013

So,what can i do to that command to work? I still don`t understant why is not working,because i made that like another command that i have,that is working,this not....


Re: strcmp(cmdtext) problem - crouch010 - 11.01.2013

If i left there just the FIX1 command ,is working like a charm,but if i add the fix2 command, it give`s that error right on that line with fix2 :

if(strcmp(x_nr,"fix2",true) == 0)


Re: strcmp(cmdtext) problem - EAsT-OAK_510 - 11.01.2013

else if(strcmp(x_nr,"fix2",true) == 0) ?


Re: strcmp(cmdtext) problem - crouch010 - 11.01.2013

East-oak, at first when i created the command /vehicle i tried to put like u said, but it is the same error


Re: strcmp(cmdtext) problem - EAsT-OAK_510 - 11.01.2013

Check if this works:
pawn Код:
if(strcmp(cmd, "/v", true) == 0 || strcmp(cmd, "/vehicle", true) == 0)
{
    if(PlayerInfo[playerid][pPcarkey] != 0)
    {
        if(IsPlayerConnected(playerid))
        {
            new x_nr;
            if(sscanf(params, "d", x_nr))
            {
                SendClientMessage(playerid, COLOR_WHITE, "HINT: (/v)ehicle [name]");
                SendClientMessage(playerid, COLOR_WHITE, "Available names: fix(1-2)");
                return 1;
            }
            if(x_nr != fix1 && x_nr != fix2)
            {
                SendClientMessage(playerid, COLOR_WHITE, "HINT: (/v)ehicle [name]");
                SendClientMessage(playerid, COLOR_WHITE, "Available names: fix(1-2)");
                return 1;
            }
            if(x_nr == fix1)
            {
                if(!IsPlayerInAnyVehicle(playerid))
                {
                    if(SBizzInfo[8][sbProducts] == 0)
                    {
                        GameTextForPlayer(playerid, "~r~Out Of Stock", 5000, 1);
                        return 1;
                    }
                    SendClientMessage(playerid, COLOR_GRAD1,"{00C8FF}» {2641FE}PersonalCar 1 was respawned !");
                    SetVehicleToRespawn(PlayerInfo[playerid][pPcarkey]);
                    PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                    SBizzInfo[8][sbTill] += 1000;
                    ExtortionSBiz(8, 1000);
                    SBizzInfo[8][sbProducts]--;
                    GivePlayerMoney(playerid, -1000);
                }
                else GameTextForPlayer(playerid, "~w~Car is~n~in ~r~use", 5000, 1);
            }
            else GameTextForPlayer(playerid, "~r~Not Enough Cash", 5000, 1);
        }
        if(x_nr == fix2)
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                if(SBizzInfo[8][sbProducts] == 0)
                {
                    GameTextForPlayer(playerid, "~r~Out Of Stock", 5000, 1);
                    return 1;
                }
                SendClientMessage(playerid, COLOR_GRAD1,"{00C8FF}» {2641FE}PersonalCar 2 was respawned !");
                SetVehicleToRespawn(PlayerInfo[playerid][pPcarkey2]);
                PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                SBizzInfo[8][sbTill] += 1000;//towcar buisness
                ExtortionSBiz(8, 1000);//ba codu e ok :|
                SBizzInfo[8][sbProducts]--;
                GivePlayerMoney(playerid, -1000);
            }
            else GameTextForPlayer(playerid, "~w~Car is~n~in ~r~use", 5000, 1);
        }
        else GameTextForPlayer(playerid, "~r~Not Enough Cash", 5000, 1);
    }
}
Untested. I modified it with a similar command I use.


Re: strcmp(cmdtext) problem - crouch010 - 11.01.2013

This error gives me..

Quote:

C:\Users\Crouch\Desktop\FINAL\TESTE\gamemodes\blz. pwn(18235) : error 017: undefined symbol "params"
C:\Users\Crouch\Desktop\FINAL\TESTE\gamemodes\blz. pwn(18241) : error 017: undefined symbol "fix1"
C:\Users\Crouch\Desktop\FINAL\TESTE\gamemodes\blz. pwn(18247) : error 017: undefined symbol "fix1"
C:\Users\Crouch\Desktop\FINAL\TESTE\gamemodes\blz. pwn(1826 : error 017: undefined symbol "x_nr"




Re: strcmp(cmdtext) problem - EAsT-OAK_510 - 11.01.2013

ok hold on. Are you using ZCMD, DCMD?


Re: strcmp(cmdtext) problem - crouch010 - 11.01.2013

I fixed it,i just add IF isplayerconnect and i get only one error

CODE:
Quote:

if(strcmp(cmd, "/v", true) == 0 || strcmp(cmd, "/vehicle", true) == 0)

if(PlayerInfo[playerid][pPcarkey] != 0)

if(IsPlayerConnected(playerid))
{
new x_nr;
new fix1;
new fix2;
if(sscanf(params, "d", x_nr))
{
SendClientMessage(playerid, COLOR_WHITE, "HINT: (/v)ehicle [name]");
SendClientMessage(playerid, COLOR_WHITE, "Available names: fix(1-2)");
return 1;
}
if(x_nr != fix1 && x_nr != fix2)
{
SendClientMessage(playerid, COLOR_WHITE, "HINT: (/v)ehicle [name]");
SendClientMessage(playerid, COLOR_WHITE, "Available names: fix(1-2)");
return 1;
}
if(IsPlayerConnected(playerid))
{
if(x_nr == fix1)
{
if(!IsPlayerInAnyVehicle(playerid))
{
if(SBizzInfo[8][sbProducts] == 0)
{
GameTextForPlayer(playerid, "~r~Out Of Stock", 5000, 1);
return 1;
}
SendClientMessage(playerid, COLOR_GRAD1,"{00C8FF}» {2641FE}PersonalCar 1 was respawned !");
SetVehicleToRespawn(PlayerInfo[playerid][pPcarkey]);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
SBizzInfo[8][sbTill] += 1000;
ExtortionSBiz(8, 1000);
SBizzInfo[8][sbProducts]--;
GivePlayerMoney(playerid, -1000);
}
else GameTextForPlayer(playerid, "~w~Car is~n~in ~r~use", 5000, 1);
}
else GameTextForPlayer(playerid, "~r~Not Enough Cash", 5000, 1);
}
if(IsPlayerConnected(playerid))
{
if(x_nr == fix2)
{
if(!IsPlayerInAnyVehicle(playerid))
{
if(SBizzInfo[8][sbProducts] == 0)
{
GameTextForPlayer(playerid, "~r~Out Of Stock", 5000, 1);
return 1;
}
SendClientMessage(playerid, COLOR_GRAD1,"{00C8FF}» {2641FE}PersonalCar 2 was respawned !");
SetVehicleToRespawn(PlayerInfo[playerid][pPcarkey2]);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
SBizzInfo[8][sbTill] += 1000;//towcar buisness
ExtortionSBiz(8, 1000);//ba codu e ok
SBizzInfo[8][sbProducts]--;
GivePlayerMoney(playerid, -1000);
}
else GameTextForPlayer(playerid, "~w~Car is~n~in ~r~use", 5000, 1);
}
else GameTextForPlayer(playerid, "~r~Not Enough Cash", 5000, 1);
}
}

ERROR:
Quote:

error 017: undefined symbol "params"

On this line:
Quote:

if(sscanf(params, "d", x_nr))