SA-MP Forums Archive
What's wrong with this code? - 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: What's wrong with this code? (/showthread.php?tid=284922)



What's wrong with this code? - Jack_Leslie - 21.09.2011

pawn Код:
if(strcmp(cmdtext, "/fixcar", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "* Usuage: /fixcar [Player ID/part of name]");
            return 1;
        }
        print("Before giveplayerid returnuser");
        giveplayerid = ReturnUser(tmp);
        print("After giveplayerid return user");
        if(IsPlayerConnected(giveplayerid))
        {
            if(PlayerInfo[playerid][pAdmin] >= 99999)
            {
                if(PlayerInfo[giveplayerid][pVehicle] == 1)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 0;
                    format(string, sizeof(string), "* You set %s's car value to 0.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 0.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
                if(PlayerInfo[giveplayerid][pVehicle] == 0)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 1;
                    format(string, sizeof(string), "* You set %s's car value to 1.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 1.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
            }
            else SendClientMessage(playerid, COLOR_GREY, "* User is not connected !");
        }
        return 1;
    }
So I have that code (tried using dcmd & sscanf but sscanf is f**ked for me, "u" won't work properly.), I done some debugging, printing etc. and it stops at the first bit, if(!strlen(tmp))...

If I do "/fixcar *nothing here*" then it sends me the usuage message, but if I do "/fixcar *something here*" it does nothing and prints nothing. :S


Re: What's wrong with this code? - Cowboy - 21.09.2011

Give this code a try

pawn Код:
COMMAND:fixcar(playerid, params[])
{
    new giveplayerid;
    if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid,  COLOR_GREY, "* Usuage: /fixcar [Player ID/part of name]");
    if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
    if(PlayerInfo[playerid][pAdmin] >=! 99999) return SendClientMessage(playerid, COLOR_RED, "You are not an admin");
    if(PlayerInfo[giveplayerid][pVehicle] == 1)
    {
        PlayerInfo[giveplayerid][pVehicle] = 0;
        format(string, sizeof(string), "* You set %s's car value to 0.", PlayerName(giveplayerid));
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "* Admin %s set your car value to 0.", PlayerName(playerid));
        SendClientMessage(giveplayerid, COLOR_GREY, string);
    }
    else if(PlayerInfo[giveplayerid][pVehicle] == 0)
    {
        PlayerInfo[giveplayerid][pVehicle] = 1;
        format(string, sizeof(string), "* You set %s's car value to 1.", PlayerName(giveplayerid));
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "* Admin %s set your car value to 1.", PlayerName(playerid));
        SendClientMessage(giveplayerid, COLOR_GREY, string);
    }
    return 1;
}



Re: What's wrong with this code? - Elmin - 21.09.2011

Код:
if(strcmp(cmdtext, "/fixcar", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "* Usuage: /fixcar [Player ID/part of name]");
            return 1;
        }
        print("Before giveplayerid returnuser");
        giveplayerid = ReturnUser(tmp);
        print("After giveplayerid return user");
        if(IsPlayerConnected(giveplayerid))
        {
            if(PlayerInfo[playerid][pAdmin] >= 99999) /////=========>are you level 99999
            {
                if(PlayerInfo[giveplayerid][pVehicle] == 1)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 0;
                    format(string, sizeof(string), "* You set %s's car value to 0.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 0.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
                if(PlayerInfo[giveplayerid][pVehicle] == 0)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 1;
                    format(string, sizeof(string), "* You set %s's car value to 1.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 1.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
            }
            else SendClientMessage(playerid, COLOR_GREY, "* User is not connected !");//======>this cant go here i think
        }
        return 1;
    }
perhaps like this

Код:
if(strcmp(cmdtext, "/fixcar", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "* Usuage: /fixcar [Player ID/part of name]");
            return 1;
        }
        print("Before giveplayerid returnuser");
        giveplayerid = ReturnUser(tmp);
        print("After giveplayerid return user");
        if(IsPlayerConnected(giveplayerid))
        {
            if(PlayerInfo[playerid][pAdmin] >= 99999)
            {
                if(PlayerInfo[giveplayerid][pVehicle] == 1)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 0;
                    format(string, sizeof(string), "* You set %s's car value to 0.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 0.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
                if(PlayerInfo[giveplayerid][pVehicle] == 0)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 1;
                    format(string, sizeof(string), "* You set %s's car value to 1.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 1.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
            } else return SendClientMessage(playerid, COLOR_GREY, "* you are not lvl 99999 admin !");
            
        } else return SendClientMessage(playerid, COLOR_GREY, "* player not connected !");
        //return 1;
    }
btw do u have any updater for if PlayerInfo[giveplayerid][pVehicle] = 1; to fix a car, something like a timer, cus this command alone wont work .


Re: What's wrong with this code? - Jack_Leslie - 21.09.2011

Quote:
Originally Posted by Elmin
Посмотреть сообщение
Код:
if(strcmp(cmdtext, "/fixcar", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "* Usuage: /fixcar [Player ID/part of name]");
            return 1;
        }
        print("Before giveplayerid returnuser");
        giveplayerid = ReturnUser(tmp);
        print("After giveplayerid return user");
        if(IsPlayerConnected(giveplayerid))
        {
            if(PlayerInfo[playerid][pAdmin] >= 99999) /////=========>are you level 99999
            {
                if(PlayerInfo[giveplayerid][pVehicle] == 1)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 0;
                    format(string, sizeof(string), "* You set %s's car value to 0.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 0.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
                if(PlayerInfo[giveplayerid][pVehicle] == 0)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 1;
                    format(string, sizeof(string), "* You set %s's car value to 1.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 1.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
            }
            else SendClientMessage(playerid, COLOR_GREY, "* User is not connected !");//======>this cant go here i think
        }
        return 1;
    }
perhaps like this

Код:
if(strcmp(cmdtext, "/fixcar", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "* Usuage: /fixcar [Player ID/part of name]");
            return 1;
        }
        print("Before giveplayerid returnuser");
        giveplayerid = ReturnUser(tmp);
        print("After giveplayerid return user");
        if(IsPlayerConnected(giveplayerid))
        {
            if(PlayerInfo[playerid][pAdmin] >= 99999)
            {
                if(PlayerInfo[giveplayerid][pVehicle] == 1)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 0;
                    format(string, sizeof(string), "* You set %s's car value to 0.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 0.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
                if(PlayerInfo[giveplayerid][pVehicle] == 0)
                {
                    PlayerInfo[giveplayerid][pVehicle] = 1;
                    format(string, sizeof(string), "* You set %s's car value to 1.", PlayerName(giveplayerid));
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, sizeof(string), "* Admin %s set your car value to 1.", PlayerName(playerid));
                    SendClientMessage(giveplayerid, COLOR_GREY, string);
                    return 1;
                }
            } else return SendClientMessage(playerid, COLOR_GREY, "* you are not lvl 99999 admin !");
            
        } else return SendClientMessage(playerid, COLOR_GREY, "* player not connected !");
        //return 1;
    }
btw do u have any updater for if PlayerInfo[giveplayerid][pVehicle] = 1; to fix a car, something like a timer, cus this command alone wont work .
Didn't work... and yes, I am admin, and if I wasn't I'd get the not authorized message, but I get nothing unless I put nothing after "fixcar"


Re: What's wrong with this code? - admantis - 21.09.2011

I had this problem before, I think it was caused by a function returning a value, in your case it's strok so make sure it doesn't return anything in the very end ( because not returning anything would make it obsolete .. ), but I don't know if this is even your problem.


Re: What's wrong with this code? - Jack_Leslie - 22.09.2011

Nah I use a shit load of other commands just like this.. like I said it doesn't print the debug I done, it doesn't even read "giveplayerid = str..."


Re: What's wrong with this code? - Jefff - 22.09.2011

pawn Код:
if(strcmp(cmdtext, "/fixcar", true, 7) == 0) // or cmd and delete 7, if not cmdtext
{
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /fixcar [Player ID/part of name]");
    print("Before giveplayerid returnuser");
    giveplayerid = ReturnUser(tmp);
    print("After giveplayerid return user");
    if(IsPlayerConnected(giveplayerid))
    {
        if(PlayerInfo[playerid][pAdmin] >= 99999)
        {
            new value = (PlayerInfo[giveplayerid][pVehicle] == 1) ? 0 : 1;
            format(string, sizeof(string), "* You set %s's car value to %d.",PlayerName(giveplayerid),value);
            SendClientMessage(playerid, COLOR_LIGHTRED, string);
            format(string, sizeof(string), "* Admin %s set your car value to %d.",PlayerName(playerid),value);
            SendClientMessage(giveplayerid, COLOR_GREY, string);
            PlayerInfo[giveplayerid][pVehicle] = value;
        }
    }else SendClientMessage(playerid, COLOR_GREY, "* User is not connected !");
    return 1;
}