[Help]Guys i need help plz with jail command
#1

I made a jail command. But when i type it, it jails me and not the player.

Код:
	if (strcmp("/jail", cmdtext, true, 10) == 0)
	{
		SetPlayerPos(playerid,2042.7137,988.9628,10.6719);
		return 1;
	}
  	return 0;
}
Reply
#2

Quote:
Originally Posted by zack3021
Посмотреть сообщение
I made a jail command. But when i type it, it jails me and not the player.

Код:
	if (strcmp("/jail", cmdtext, true, 10) == 0)
	{
		SetPlayerPos(playerid,2042.7137,988.9628,10.6719);
		return 1;
	}
  	return 0;
}
Use this
Код:
if (strcmp("/jail", cmdtext, true, 10) == 0)
	{
      tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) {
                    SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /jail [playerid]");
                    return 1;
                }
                new playa;
                playa = ReturnUser(tmp);
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) {
                    SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /jail [playerid]");
                    return 1;
                }
               SetPlayerPos(playa,2042.7137,988.9628,10.6719);
              return 1;
              }
}
Reply
#3

Quote:
Originally Posted by zack3021
Посмотреть сообщение
I made a jail command. But when i type it, it jails me and not the player.

Код:
	if (strcmp("/jail", cmdtext, true, 10) == 0)
	{
		SetPlayerPos(playerid,2042.7137,988.9628,10.6719);
		return 1;
	}
  	return 0;
}
Don't use the code above; it has missing things that you need in order to use that.

Yes, thats because you put "playerid" which means you are telling the script to jail the person typing the cmd.

You need to use strtok; or sscanf.

Under OnPlayerCommandText:
pawn Код:
new
        cmd[256],
        tmp[256],
        idx
    ;
    cmd = strtok(cmdtext, idx);
    if(!strcmp(cmd, "/jail", true))
    {
        new id;
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /jail <id>");
       
        id = strval(tmp);
       
        SetPlayerPos(id, 2042.7137,988.9628,10.6719);
        return 1;
    }
Your welcome
Reply
#4

I get errors

Should i add to the top new(then whatever is new)

Код:
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(56) : error 017: undefined symbol "cmdtext"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(58) : error 017: undefined symbol "tmp"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(58) : error 017: undefined symbol "strtok"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(59) : warning 217: loose indentation
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(59) : error 017: undefined symbol "tmp"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(60) : error 017: undefined symbol "COLOR_GRAD2"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(64) : error 017: undefined symbol "ReturnUser"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(65) : error 017: undefined symbol "tmp"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(65) : error 017: undefined symbol "strtok"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(66) : error 017: undefined symbol "tmp"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(67) : error 017: undefined symbol "COLOR_GRAD2"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(70) : warning 217: loose indentation
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(71) : warning 217: loose indentation
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(73) : warning 209: function "OnPlayerConnect" should return a value
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(74) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


11 Errors.
Reply
#5

Quote:
Originally Posted by The Toni
Посмотреть сообщение
Yes, thats because you put "playerid" which means you are telling the script to jail the person typing the cmd.

You need to use strtok; or sscanf.

pawn Код:
new
        cmd[256],
        tmp[256],
        idx
    ;
    cmd = strtok(cmdtext, idx);
    if(!strcmp(cmd, "/jail", true))
    {
        new id;
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /jail <id>");
       
        id = strval(tmp);
       
        SetPlayerPos(id, 2042.7137,988.9628,10.6719);
        return 1;
    }
Your welcome
Use this one.
Reply
#6

The errors are not with Toni's script, i need to test his. Sorry for doublepost.
Reply
#7

Here are the errors with Toni's script:

Код:
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(99) : error 017: undefined symbol "strtok"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(99) : error 033: array must be indexed (variable "tmp")
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(95) : warning 203: symbol is never used: "idx"
C:\Program Files\Rockstar Games\GTA San Andreas\Pawno 0.3b\filterscripts\jail.pwn(92) : warning 204: symbol is assigned a value that is never used: "cmd"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Reply
#8

You need the strtok code at the bottom of your script, if i had it on me i would give it to you, im sure somone in here will give it to you
Reply
#9

Thanks and i would love to know what stroke means but for now i will wait for somone to give me
Reply
#10

Put this at the bottem of your script:
pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)