[Need]GetPlayerWantedLevel
#1

I need some help again. I need a command like this;

/getwanted [playerid]

It will show player's wanted level..

Please Help Me..
Reply
#2

https://sampwiki.blast.hk/wiki/GetPlayerWantedLevel
https://sampwiki.blast.hk/wiki/Using_strcmp()
Reply
#3

Here you go:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
That is called whenever the player types a /command.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

if(!strcmp(cmdtext, "/getwanted"))
This will compare two strings, in this case cmdtext(the /command the player typed), and "/getwanted". So, if the player types "/getwanted" it will trigger the callback(OnPlayerCommandText), and go down the list of strcmps, when it reaches this on, "/getwanted", it will continue into what this command does.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

if(!strcmp(cmdtext, "/getwanted")) {
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, Red1, "Error: /getwanted [Player ID]");
return 1;
}
}
This will see if they typed anything after the command(the ID, "/getwanted 13", for example) and return them back if they did not.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

if(!strcmp(cmdtext, "/getwanted")) {
new tmp[128] = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, Red1, "Error: /getwanted [Player ID]");
return 1;
}
new string[128], Wanted, CheckID = strval(tmp);
Wanted = GetPlayerWantedLevel(playerid);
format(string, 128, "This player has a %d Wanted Level", Wanted);
SendClientMessage(playerid, COLOR, string);
return 1;
}
Now what this last bit of code does, is declare string, Wanted, and CheckID(and also converts tmp into an integer instead of a string). Then it "puts" the players wanted level into the variable Wanted. It edits the variable string and makes a nice message including their wanted level, and it sends that to the player who entered the command. It then returns the player so they don't get an unknown command message.

There you go, a simple wanted command.
Reply
#4

oups..

I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(579) : error 017: undefined symbol "strtok"
I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(579) : error 008: must be a constant expression; assumed zero
I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(581) : error 017: undefined symbol "Red1"
I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(587) : error 017: undefined symbol "COLOR"
I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(584) : warning 204: symbol is assigned a value that is never used: "CheckID"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.


I can correct color errors.. But other two??
Reply
#5

Forgot, you need strtok.

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
#6

Quote:
Originally Posted by TraNe15
oups..

I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(579) : error 017: undefined symbol "strtok"
I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(579) : error 008: must be a constant expression; assumed zero
I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(581) : error 017: undefined symbol "Red1"
I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(587) : error 017: undefined symbol "COLOR"
I:\Documents and Settings\OrKo\Desktop\Gta Sa-Mp Server\OrKo's Server\gamemodes\Stunt.pwn(584) : warning 204: symbol is assigned a value that is never used: "CheckID"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.


I can correct color errors.. But other two??
Fixed an error:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

if(!strcmp(cmdtext, "/getwanted")) {
new tmp[128] = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_RED, "Error: /getwanted [Player ID]");
return 1;
}
new string[128], Wanted, CheckID = strval(tmp);
Wanted = GetPlayerWantedLevel(CheckID);
format(string, 128, "This player has a %d Wanted Level", Wanted);
SendClientMessage(playerid, COLOR, string);
return 1;
}
Also, in COLOR you put your own color.
Reply
#7

Quote:
Originally Posted by zallomallo
Forgot, you need strtok.

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;
}
What will I do with this?? Where will I put?
Reply
#8

put that anywhere in your sript, but outside any command and publics etc.
Reply
#9

Again I couldn't do it Hey can anyone wrote command without strtok || like that
Reply
#10

Quote:
Originally Posted by TraNe15
Again I couldn't do it Hey can anyone wrote command without strtok || like that
what do you mean you couldn't do it? they gave u the code, paste the strtok function right at the bottom of your script thats it!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)