[Tutorial] /setwanted command.
#1

Hello, this is my first tutorial, and i will teach you(hopefully..), how to create a /setwanted command :]
Alright, first thing that you will need is "sscanf" and "zcmd"
Links:
zCMD: https://sampforum.blast.hk/showthread.php?tid=91354

sscanf: https://sampforum.blast.hk/showthread.php?tid=120356
Alrighty, now that you've downloaded them, added them in your pawno/includes folder, and #Included them in your pawno, (#include <zcmd> // #include <sscanf2> under the a_samp include)
you will need to set these color defines ->
#define COLOR_RED 0xAA3333AA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_BLUE 0x0000BBAA
[paste them under your #include(s)]
Alright, now you want to scroll down to your bottom, and add this line:

Code:
	CMD:setwanted(playerid, params[]) {
This is basically the start of everything.
setwanted is the command.. (You can change the commands name, to for an example: setwantedlevel etc.)
Under those, you will need to add these lines:
Code:
        new id;
	new wantedlevel;
	new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
	GetPlayerName(playerid, name, sizeof(name));
        GetPlayerWantedLevel(playerid);
new id -> Basically the "Target ID".
Without it, you won't be able to set someones/other players wanted level.
new wantedlevel -> With this you will be able to set the wantedlevel you want.
For an example -> /setwanted(Command) 1(id) 2(wantedlevel)
GetPlayerName/New name is for a following string message.
GetPlayerWantedLevel is for the 'new wantedlevel' to work.

Code:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You're not allowed to use this command!");
	if(sscanf(params, "ui", id, wantedlevel)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /setwanted [ID] [WantedLevel]");
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ORANGE, "Target is offline.");
if(!IsPlayerAdmin(playerid)) etc etc. means that if the player is NOT an admin, then it will return the message
"return SendClientMessage(playerid, COLOR_RED, "You're not allowed to use this command!");"

if(sscanf(params, "ui", id, wantedlevel)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /setwanted [ID] [WantedLevel]"); This will check if you've typed the command fully / correctly.
If it's typed "/setwanted ID" then it will show "/setwanted [ID] [WantedLevel]"
If you've typed "/setwanted WantedLevel", then it will show "/setwanted [ID] [WantedLevel]" again.
And "if(!IsPlayerConnected(id))" will check if the player ID is online/"valid".
If the ID isn't "valid", it will show "Target is offline."
[NOTE: you can also use -> "if(!IsPlayerConnected(id) || id == playerid) return SendClientMessage(playerid, COLOR_ORANGE, "Target is offline, or you're trying to use the command on yourself.");"
That will check if the ID you typed is your ID, if it will be your ID, it will send the message seen above]

Last thing ->

Code:
	SetPlayerWantedLevel(id, wantedlevel);
	SetPlayerColor(id, COLOR_RED);
	format(string, sizeof(string), "%s is now wanted!", name);
	SendClientMessageToAll(COLOR_BLUE, string);
	return 1;
}
SetPlayerWantedLevel(id, wantedlevel) -> It will set the id's(Targets / other players id.) wanted level to (wantedlevel here).
SetPlayerColor will set the wanted players color to RED, for the cops (if you have those..) to notice.

format(string, sizeof(string), ....
... SendClientMessageToAll was for the "new name ... GetPlayerName"
It isn't fully needed, but that's just for the message :]
Full script:


Code:
	CMD:setwanted(playerid, params[]) { //command itself.
	new id; //will "allow" you to set the Target ID.
	new wantedlevel; // will "allow" you to set the wanted level, for the target.
	new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
	GetPlayerName(playerid, name, sizeof(name)); //This is optional(needed for the "SendClientMessageToAll at the scripts end".
	GetPlayerWantedLevel(playerid); //Will get the playerids wanted level, for "new wantedlevel;"
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You're not allowed to use this command!"); //If the player is NOT an admin, he will receive this ^ 
	if(sscanf(params, "ui", id, wantedlevel)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /setwanted [ID] [WantedLevel]"); //If there aren't enough 'options' typed, it will show this ^
        if(wantedlevel < 1 || wantedlevel > 6) return SendClientMessage(playerid, COLOR_RED, "Error: Max wanted is 6 and the minimum is 0."); //Thanks to Danish - People won't be able to /setwanted ID 0, or /setwanted ID 6253.
Basically Minimum is "1" and Max is "6".
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ORANGE, "Target is offline."); //If the target isn't a "valid" ID.
	SetPlayerWantedLevel(id, wantedlevel); //If everything is typed correctly, it will set the targets wantedlevel that you typed in /setwanted
	SetPlayerColor(id, COLOR_RED); //Sets targets color, so the cops can easily notice him.
	format(string, sizeof(string), "%s is now wanted!", name);
	SendClientMessageToAll(COLOR_BLUE, string); //Sends a message to everyone, saying that %s (the targets id)
	return 1;
}
[This was only tested on my 'localhost' server, so sadly it isn't tested fully.]
Thanks Danish for the level fix
Reply
#2

What if we did:
Code:
/setwanted [ID] [2155115]
What would happen then?
Just asking.

Anyway try to improve your tutorial by explaining more, other than that, good job and good luck!
Reply
#3

Quote:
Originally Posted by JimmyCh
View Post
What if we did:
Code:
/setwanted [ID] [2155115]
What would happen then?
Just asking.

Anyway try to improve your tutorial by explaining more, other than that, good job and good luck!
I suppose that it would set the wanted level to 2155115..
Will try to find a way to make 6 max..
Also, thanks :]
Reply
#4

pawn Code:
if(sscanf(params, "ui", id, wantedlevel)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /setwanted [ID] [WantedLevel]");
Add this under that line:

pawn Code:
if(wantedlevel < 0 || wantedlevel > 6) return SendClientMessage(playerid, COLOR_RED, "Error: Max wanted is 6 and the minimum is 0.");
Reply
#5

Thanks Danish, will edit and add you for helping me :]
Also, i needed to change it to:
if(wantedlevel < 1 || wantedlevel > 6) return SendClientMessage(playerid, COLOR_RED, "Error: Max wanted is 6 and the minimum is 0.");
Cause, if it would be < 0 it would show me the
"format(string, sizeof(string), "%s is now wanted!", name);" string/message
EDIT: Sadly i need to spread some reputation to +rep you :\
Reply
#6

Actually, you could just replace these lines:

pawn Code:
SetPlayerColor(id, COLOR_RED); //Sets targets color, so the cops can easily notice him.
format(string, sizeof(string), "%s is now wanted!", name);
With this:

pawn Code:
if(wantedlevel > 0)
    {
        SetPlayerColor(id, COLOR_WHITE); //Sets targets color, so the cops can easily notice him.
        format(string, sizeof(string), "%s is no longer wanted!", name);
    }
    else
    {
        SetPlayerColor(id, COLOR_RED); //Sets target color so the cops can easily notice him.
        format(string, sizeof(string), "%s is now wanted!", name);
    }
Keep it how you want, I'm just improving your knowledge :P.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)