/unjail Fix request
#1

Код:
if(strcmp(cmd, "/unjail", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_WHITE, "USAGE: /unjail [playerid/PartOfName] [reason]");
				return 1;
			}
			new playa;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			if(PlayerInfo[playerid][pAdmin] >= 2)
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
				        GetPlayerName(playa, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
      					new length = strlen(cmdtext);
						while ((idx < length) && (cmdtext[idx] <= ' '))
						{
							idx++;
						}
						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_WHITE, "USAGE: /unjail [playerid/PartOfName] [reason]");
							return 1;
						}
						format(string, sizeof(string), "AdmCmd: %s has been unjailed by an Admin, reason: %s", giveplayer, (result));
                		SendClientMessageToAll(COLOR_LIGHTRED, string);
                		PlayerInfo[giveplayerid][pJailed] = 0;
						SendClientMessage(giveplayerid, COLOR_GRAD1,"You have paid your debt to society.");
						format(string, sizeof(string), "~g~Freedom~n~~w~Try to be a better citizen");
						GameTextForPlayer(giveplayerid, string, 5000, 1);
						SetCameraBehindPlayer(giveplayerid);
						TogglePlayerControllable(giveplayerid, 1);
						SetPlayerInterior(giveplayerid, 0);
               			SetPlayerVirtualWorld(giveplayerid, 0);
                     	SetPlayerPos(giveplayerid, 1529.6, -1691.2, 13.3);
						SetPlayerToTeamColor(giveplayerid);
						format(string, sizeof(string), "You have been unjailed by Admin: %s", sendername);
						SendClientMessage(playa, COLOR_LIGHTBLUE, string);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, "   You are not authorized to use that command !");
			}
		}
		return 1;
	}
The problem I am getting is that when i type /unjail <id> <reason> it just shows me "USAGE: /unjail [playerid/PartOfName] [reason]"
When i type /unjail <id> <any letter or number here> <reason> then it works. What can be a possible fix to this?

I have been scripting for a while now but I haven't really been good at scripts that involve counting text to check if correct format is used.

Additionally, if anyone could provide an explanation of all the cmd, idx, tmp, strtok, cmdtext would be appriciated as they are mentioned multiple times in this code. I get it mostly but not completely. Thanks for any help i might get
Reply
#2

Well this is because you copy this from cmd:/jail, because /jail gives /jail[id][reason], I think you need to rescript the /unjail.
Reply
#3

Yes i did and i realized that all i had to do was remove tmp = strtok(cmdtext, idx); that was repeating itself
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)