01.10.2013, 16:23
(
Last edited by Kyance; 01/10/2013 at 05:40 PM.
)
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:
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:
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.
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 ->
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:
[This was only tested on my 'localhost' server, so sadly it isn't tested fully.]
Thanks Danish for the level fix
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[]) {
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);
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.");
"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; }
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; }
Thanks Danish for the level fix