SA-MP Forums Archive
Command works for all ID's except ID 0 - 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: Command works for all ID's except ID 0 (/showthread.php?tid=299156)



Command works for all ID's except ID 0 - HondaCBR - 24.11.2011

Basically you can do /adminjail ANYID time reason, apart from /adminjail 0 time reason.
If you do it for ID 0, you get a message: SendClientMessage(playerid, COLOR_GREY, " Time needs to be between 1 and 120 min !");

pawn Код:
if(strcmp(cmd, "/adminjail", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "Użyj: /adminjail [ID] [TIME] [REASON]");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if (PlayerInfo[playerid][pAdmin] >= 2000)
            {
                if(IsPlayerConnected(giveplayerid))
                {
                    if(giveplayerid != INVALID_PLAYER_ID)
                    {
                        GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                        GetPlayerName(playerid, sendername, sizeof(sendername));
                        new length = strlen(cmdtext);
                        while ((idx < length) && (cmdtext[idx] <= ' '))
                        {
                            idx++;
                        }

                        new time = strval(tmp);
                        if(time <= 1 || time >= 120) { SendClientMessage(playerid, COLOR_GREY, "   Time needs to be between 1 and 120 min !"); return 1; }
                        tmp = strtok(cmdtext, idx);
                        if(!strlen(tmp))
                        {
                            SendClientMessage(playerid, COLOR_GRAD2, "Użyj: /adminjail [ID] [TIME] [REASON]");
                            return 1;
                        }

                        new offset = idx;
                        new result[64];
                        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
                        {
                            result[idx - offset] = cmdtext[idx];
                            idx++;
                        }
                        result[idx - offset] = EOS;
                        if(!strlen(result))
                        {
                            SendClientMessage(playerid, COLOR_GRAD2, "Użyj: /adminjail [ID] [TIME] [REASON]");
                            return 1;
                        }
                        format(string, sizeof(string), "USER: %s has been taken in to Admin Jail by admin: %s. For %d min. Reason: %s ", giveplayer, sendername, time, (result));
                        SendClientMessageToAll(COLOR_LIGHTRED, string);

                        SetPlayerPos(giveplayerid,1478.5525,-1365.3551,125.9121);
                        SetPlayerFacingAngle(giveplayerid, 90);
                        PlayerInfo[giveplayerid][pAJTime] = time * 60;
                        PlayerInfo[giveplayerid][pAJ] = 1;

                        return 1;
                    }
                }
            }
            else
            {
                format(string, sizeof(string), "%d is not active.", giveplayerid);
                SendClientMessage(playerid, COLOR_GRAD1, string);
            }
        }
        return 1;
    }



Re: Command works for all ID's except ID 0 - MP2 - 24.11.2011

Players can't type commands if they aren't on the server; IsPlayerConnected is unnecessary.

Use sscanf.


Re: Command works for all ID's except ID 0 - HondaCBR - 24.11.2011

it doesnt matter about isplayerconnected im on about id 0, you cant put id 0 in jail it comes up that the time needs to be betwin 1 and 120, it doesnt matter what time you choose


Re: Command works for all ID's except ID 0 - Vince - 24.11.2011

pawn Код:
new time = strval(tmp);
At this point, the target playerid is still stored in this variable. As said, use sscanf to make these kind of commands with ease.


Re: Command works for all ID's except ID 0 - HondaCBR - 24.11.2011

could you just edit mine command so it works for all ID's?