SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 16/10/2013, 09:13 AM   #1
Blademaster680
Gangsta
 
Blademaster680's Avatar
 
Join Date: Jul 2013
Location: On my Yamaha R6
Posts: 609
Reputation: 26
Post Making a /me /do /shout /b command

A few useful commands for a RP server
What will this teach me?
This tutorial will teach you how to make a
/me 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>
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.
Code:
stock strreplace(string[], find, replace)
{
    for(new i=0; string[i]; i++)
    {
        if(string[i] == find)
        {
            string[i] = replace;
        }
    }
}
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.
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);
        }
    }
}
Ok so now what does that mean?
Code:
new Float:x, Float:y, Float:z;
Were are declaring the float x, y, and z.
Code:
GetPlayerPos(playerid,x,y,z);
We are getting the Player's Position for later use.
Code:
    foreach(Player,i)
    {
        if(IsPlayerInRangeOfPoint(i,radi,x,y,z))
        {
            SendClientMessage(i,color,string);
        }
    }
That is checking if the player is in range, and if he is he will receive the message.
Code:
stock GetName(playerid)
{
    new name[24];
    GetPlayerName(playerid, name, sizeof(name));
    strreplace(name, '_', ' ');
    return name;
}
Code:
new name[24];
Defining the "name".
Code:
GetPlayerName(playerid, name, sizeof(name));
Getting the players name.
Code:
strreplace(name, '_', ' ');
That will replace the "_" in their name.
For example if their name is "John_Smith" it will make it "John Smith".
Code:
return name;
This is returning the new 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;
    }
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]".
Code:
    
else
    {
        format(string, sizeof(string), "* %s %s", GetName(playerid), action);
        ProxDetector(30, playerid, string, COLOR_PURPLE);
    }
This code is saying if he did put an action then it will do this piece.
Code:
format(string, sizeof(string), "* %s %s", GetName(playerid), action);
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.
Code:
ProxDetector(30, playerid, string, COLOR_PURPLE);
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.
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;
}
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.
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;
}
This command is similar to the /me and /do command's except it has a few different things.
Code:
 ProxDetector(50.0, playerid, string, -1);
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.
Code:
CMD:s(playerid, params[]) return cmd_shout(playerid, params);
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.
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;
}
Ok so now this one is a little different.
Code:
new string[128], text[100];
We are declaring the strings that we will use.
Code:
if(sscanf(params, "s[100]", text)) return SendClientMessage(playerid, -1, "USAGE: /b [TEXT]");
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.
Code:
format(string, sizeof(string), "(( %s says: %s ))", GetName(playerid), text);
	ProxDetector(30.0, playerid, string, COLOR_GREY);
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:
http://forum.sa-mp.com/showthread.php?t=92679
ZCMD:
http://forum.sa-mp.com/showthread.php?t=91354
sscanf:
http://forum.sa-mp.com/showthread.php?t=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.






__________________


Last edited by Blademaster680; 30/01/2015 at 11:08 PM.
Blademaster680 is offline   Reply With Quote
Old 21/12/2013, 12:09 AM   #2
DemME
Huge Clucker
 
Join Date: Oct 2013
Location: forum.sa-mp.com Money: 1,982,120
Posts: 295
Reputation: 13
Default Re: Making a /me /do /shout /b command

We need the stock GetName, you know.
DemME is offline   Reply With Quote
Old 22/12/2013, 05:12 PM   #3
Blademaster680
Gangsta
 
Blademaster680's Avatar
 
Join Date: Jul 2013
Location: On my Yamaha R6
Posts: 609
Reputation: 26
Default Re: Making a /me /do /shout /b command

Ok added and updated with the Stock GetName for you guys
__________________

Blademaster680 is offline   Reply With Quote
Old 22/12/2013, 06:44 PM   #4
Emmet_
Guest
 
Posts: n/a
Default Re: Making a /me /do /shout /b command

You don't need to use "sscanf" for only one string.

pawn Code:
CMD:me(playerid, params[])
{
    new
        string[128];

    if (isnull(params))
    {
        SendClientMessage(playerid, -1, "USAGE: /me [action]");
    }
    else
    {
        format(string, sizeof(string), "* %s %s", GetName(playerid), params);
        ProxDetector(30, playerid, string, COLOR_PURPLE);
    }
    return 1;
}

Also, "ProxDetector" won't work as it should inside interiors and virtual worlds.
  Reply With Quote
Old 22/12/2013, 06:57 PM   #5
Hansrutger
Gangsta
 
Hansrutger's Avatar
 
Join Date: May 2011
Location: Sweden
Posts: 760
Reputation: 161
Default Re: Making a /me /do /shout /b command

Yo, didn't read through exactly everything and sorry for that. One thing that you should add in your proxdetector is to check if the player sending the string is in the same virtual world as the player near them:
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);
        }
    }
}
to

Code:
stock ProxDetector(Float:radio, 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)) && ((GetPlayerVirtualWorld(playerid)) == (GetPlayerVirtualWorld(i)))
        {
            SendClientMessage(i,color,string);
        }
    }
}
Why? Because people like me use different virtual worlds for different for instance bank interiors for role-play servers. Then I don't want someone in bank B see something that was written in bank A.
Hansrutger is offline   Reply With Quote
Old 16/01/2014, 09:15 PM   #6
anou1
Huge Clucker
 
Join Date: Dec 2013
Location: To infinity... and beyond
Posts: 417
Reputation: 31
Default Re : Making a /me /do /shout /b command

Hi

I got this: "error 017: undefined symbol "strreplace""
anou1 is offline   Reply With Quote
Old 17/01/2014, 05:43 AM   #7
Blademaster680
Gangsta
 
Blademaster680's Avatar
 
Join Date: Jul 2013
Location: On my Yamaha R6
Posts: 609
Reputation: 26
Default Re: Re : Making a /me /do /shout /b command

Quote:
Originally Posted by anou1 View Post
Hi

I got this: "error 017: undefined symbol "strreplace""
Ok lots of people have this already defined but I will update the tutorial now.
__________________

Blademaster680 is offline   Reply With Quote
Old 23/02/2014, 10:38 AM   #8
Guest4390857394857
Guest
 
Posts: n/a
Thumbs up Re: Making a /me /do /shout /b command

good one!
  Reply With Quote
Old 23/02/2014, 02:09 PM   #9
NL-Sultan
Big Clucker
 
NL-Sultan's Avatar
 
Join Date: Jul 2011
Posts: 90
Reputation: 10
Default Re: Making a /me /do /shout /b command

After placing the CMD:ME i get this:

Code:
C:\Users\Jan\Desktop\GM\gamemodes\NewOne.pwn(410) : error 035: argument type mismatch (argument 4)
C:\Users\Jan\Desktop\GM\gamemodes\NewOne.pwn(414) : error 010: invalid function or declaration
C:\Users\Jan\Desktop\GM\gamemodes\NewOne.pwn(417) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase


3 Errors.
NL-Sultan is offline   Reply With Quote
Old 25/02/2014, 07:10 AM   #10
Blademaster680
Gangsta
 
Blademaster680's Avatar
 
Join Date: Jul 2013
Location: On my Yamaha R6
Posts: 609
Reputation: 26
Default Re: Making a /me /do /shout /b command

What line is 410 and 414 and 417?
__________________

Blademaster680 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Small shout command Fierros Scripting Help 1 19/10/2012 03:51 AM
About my /shout command there is a weirdo bug. DeeCaay Scripting Help 4 09/07/2012 09:46 PM
Anti Command spam, /shout system Penait1 Help Archive 2 02/05/2011 09:26 PM
help with /me and /shout THE_KNOWN Help Archive 4 14/01/2011 05:03 AM
help me with /shout etc. coole210 Help Archive 6 09/06/2009 09:44 PM


All times are GMT. The time now is 06:25 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.