16.10.2013, 09:13
(
Last edited by Blademaster680; 30/01/2015 at 11:08 PM.
)
A few useful commands for a RP server
What will this teach me?
This tutorial will teach you how to make a
* Blademaster680 command for an action
/do command for a OOC action
/shout command to allow you to shout
/b command for OOC chat.
Step 1:
First we need to include foreach, ZCMD and sscanf which I will put the download link at the bottom of the tutorial.
Step 2:
We need to make a strreplace which we can use to replace the "_" in their names for eg. "Jackie_Chan" will change to "Jackie Chan". See so we will be replacing the "_" with a space.
Step 3:
We need to make a ProxDetector and a GetName stock.
A ProxDetector is a stock that will make the chat fade the further away you are from the person talking and the GetName will just get the player's name.
Ok so now what does that mean?
Were are declaring the float x, y, and z.
We are getting the Player's Position for later use.
That is checking if the player is in range, and if he is he will receive the message.
Defining the "name".
Getting the players name.
That will replace the "_" in their name.
For example if their name is "John_Smith" it will make it "John Smith".
This is returning the new name.
Step 4:
Ok so now onto the commands, first we will do the /me command.
What this code does is it will check if the player typed /me and then the action, else it will tell them "USAGE: /me [action]".
This code is saying if he did put an action then it will do this piece.
This is just using a string and the first %s will get the players name and the second %s will be the action he typed in.
This is using the ProxDetector which we made earlier. The range is 30m and everyone within that 30m will see the action and it will display in purple.
Step 5:
Lets get onto the /do command.
Dont need to explain this it is exactly the same as the /me command except this just has the OOC brackets "(( ))".
Step 6:
Now for the shout command.
This command is similar to the /me and /do command's except it has a few different things.
Now the new range is 50m. So everyone will see this if they are within 50m of the person who shouted the message and it will desplay in grey.
This is optional, What this means is instead of typing the whole /shout you can just type /s and it will return the whole shout command. It is just a shortcut.
Step 7:
Now onto the last command, the /b command.
Ok so now this one is a little different.
We are declaring the strings that we will use.
It will check if the person has said a message after he typed /b, and if he/she hasnt it will send "USAGE: /b [TEXT]" back to them.
This is just formatting the string like we did earlier but this one will say "(( %s says: %s ))" because all the text will be in the OOC brackets.
The ProxDetector range here is 30m and the messages will desplay in grey.
Downloads:
foreach:
https://sampforum.blast.hk/showthread.php?tid=92679
ZCMD:
https://sampforum.blast.hk/showthread.php?tid=91354
sscanf:
https://sampforum.blast.hk/showthread.php?tid=120356
Hope this helped and I hope you guys learned a few things and that you understand.
Leave a comment if you see I left something out or if you want me to explain something.
What will this teach me?
This tutorial will teach you how to make a
* Blademaster680 command for an action
/do command for a OOC action
/shout command to allow you to shout
/b command for OOC chat.
Step 1:
First we need to include foreach, ZCMD and sscanf which I will put the download link at the bottom of the tutorial.
Code:
#include <foreach> #include <ZCMD> #include <sscanf2>
We need to make a strreplace which we can use to replace the "_" in their names for eg. "Jackie_Chan" will change to "Jackie Chan". See so we will be replacing the "_" with a space.
Code:
stock strreplace(string[], find, replace) { for(new i=0; string[i]; i++) { if(string[i] == find) { string[i] = replace; } } }
We need to make a ProxDetector and a GetName stock.
A ProxDetector is a stock that will make the chat fade the further away you are from the person talking and the GetName will just get the player's name.
Code:
stock ProxDetector(Float:radi, playerid, string[],color) { new Float:x,Float:y,Float:z; GetPlayerPos(playerid,x,y,z); foreach(Player,i) { if(IsPlayerInRangeOfPoint(i,radi,x,y,z)) { SendClientMessage(i,color,string); } } }
Code:
new Float:x, Float:y, Float:z;
Code:
GetPlayerPos(playerid,x,y,z);
Code:
foreach(Player,i) { if(IsPlayerInRangeOfPoint(i,radi,x,y,z)) { SendClientMessage(i,color,string); } }
Code:
stock GetName(playerid) { new name[24]; GetPlayerName(playerid, name, sizeof(name)); strreplace(name, '_', ' '); return name; }
Code:
new name[24];
Code:
GetPlayerName(playerid, name, sizeof(name));
Code:
strreplace(name, '_', ' ');
For example if their name is "John_Smith" it will make it "John Smith".
Code:
return name;
Step 4:
Ok so now onto the commands, first we will do the /me command.
Code:
CMD:me(playerid, params[]) { new string[128], action[100]; if(sscanf(params, "s[100]", action)) { SendClientMessage(playerid, -1, "USAGE: /me [action]"); return 1; } else { format(string, sizeof(string), "* %s %s", GetName(playerid), action); ProxDetector(30, playerid, string, COLOR_PURPLE); } return 1; } if(sscanf(params, "s[100]", action)) { SendClientMessage(playerid, -1, "USAGE: /me [action]"); return 1; }
Code:
else { format(string, sizeof(string), "* %s %s", GetName(playerid), action); ProxDetector(30, playerid, string, COLOR_PURPLE); }
Code:
format(string, sizeof(string), "* %s %s", GetName(playerid), action);
Code:
ProxDetector(30, playerid, string, COLOR_PURPLE);
Step 5:
Lets get onto the /do command.
Code:
CMD:do(playerid, params[]) { new string[128], action[100]; if(sscanf(params, "s[100]", action)) { SendClientMessage(playerid, -1, "USAGE: /do [action]"); return 1; } else { format(string, sizeof(string), "* %s (( %s ))", action, GetName(playerid)); ProxDetector(30, playerid, string, COLOR_PURPLE); } return 1; }
Step 6:
Now for the shout command.
Code:
CMD:shout(playerid, params[]) { new string[128], shout[100]; if(sscanf(params, "s[100]", shout)) { SendClientMessage(playerid, -1, "USAGE: /(s)hout [message]"); return 1; } else { format(string, sizeof(string), "%s shouts: %s!",GetName(playerid),shout); ProxDetector(50.0, playerid, string, -1); } return 1; }
Code:
ProxDetector(50.0, playerid, string, -1);
Code:
CMD:s(playerid, params[]) return cmd_shout(playerid, params);
Step 7:
Now onto the last command, the /b command.
Code:
CMD:b(playerid, params[]) { new string[128], text[100]; if(sscanf(params, "s[100]", text)) return SendClientMessage(playerid, -1, "USAGE: /b [TEXT]"); format(string, sizeof(string), "(( %s says: %s ))", GetName(playerid), text); ProxDetector(30.0, playerid, string, COLOR_GREY); return 1; }
Code:
new string[128], text[100];
Code:
if(sscanf(params, "s[100]", text)) return SendClientMessage(playerid, -1, "USAGE: /b [TEXT]");
Code:
format(string, sizeof(string), "(( %s says: %s ))", GetName(playerid), text); ProxDetector(30.0, playerid, string, COLOR_GREY);
The ProxDetector range here is 30m and the messages will desplay in grey.
Downloads:
foreach:
https://sampforum.blast.hk/showthread.php?tid=92679
ZCMD:
https://sampforum.blast.hk/showthread.php?tid=91354
sscanf:
https://sampforum.blast.hk/showthread.php?tid=120356
Hope this helped and I hope you guys learned a few things and that you understand.
Leave a comment if you see I left something out or if you want me to explain something.