10.07.2015, 17:21
Getting started
I haven't seen any tutorials about this, so I've decided to make one. It's pretty easy, anyone can do it and it can be useful in situations. What I have is a /flipcoin command, which will randomly select one of the textes to show to players that are near each other. I also have a /rpchance command which will determine whether the previous roleplay action was a success or a failure after 3 seconds. How is /rpchance helpful? Well, in every RP server there will always be arguments about if a certain action would suceed or not. This will decide which of the players will succeed. Let's say, they are roleplaying a shootout and Player 1 goes:
* NotYoMama aims for Player 2's head and shoots.
/do What would be the result of Player 1's shooting? ((Player 1))
Player 2 goes:
/do Player 1 would miss Player 2
and they start arguing, an admin comes, they waste his time and so on and on.
And /flipcoin is just a small detail that makes your server better.
Here are the images of the final result:


A player is determining the action, for the reason of needing a proof. If it doesn't have a name, then anyone can just /rpchance and troll. Plus, it doesn't who types in the command, because it's random
Coding
/flipcoin command
The includes are:
PHP Code:
#include <a_samp>
#include <ZCMD>
#include <sscanf2>
#include <foreach>
Make sure you don't already have it defined
PHP Code:
#define COLOR_LIGHTBLUE 0x33CCFFAA
The following stock will be used to replace characters in a string
PHP Code:
stock strreplace(string[], find, replace)
{
for(new i=0; string[i]; i++)
{
if(string[i] == find)
{
string[i] = replace;
}
}
}
PHP Code:
stock GetName(playerid)
{
new name[24];
GetPlayerName(playerid, name, sizeof(name));
strreplace(name, '_', ' ');
return name;
}
PHP 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);
}
}
}
Finally, the command. I prefer using ZCMD. You should place this line above the stocks. That's at least where I place them. The command is pretty self-explanatory.
PHP Code:
CMD:flipcoin(playerid, params[])
{
new string[128], rand = random(2);
if(rand == 0)
{
format(string, sizeof(string), "* %s throws a coin and it lands on the obverse side of it. (HEADS)", GetName(playerid));
ProxDetector(20, playerid, string, COLOR_LIGHTBLUE);
}
else
{
format(string, sizeof(string), "* %s throws a coin and it lands on the reverse side of it. (TAILS)", GetName(playerid));
ProxDetector(20, playerid, string, COLOR_LIGHTBLUE);
}
return 1;
}
/rpchance command
Don't double include them if you already have them included.
The includes are:
PHP Code:
#include <a_samp>
#include <ZCMD>
#include <sscanf2>
#include <foreach>
PHP Code:
#define COLOR_GREYRED 0x70825BFF
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
Place the public function somewhere under main(), near your other public functions
PHP Code:
forward RPChance(playerid);
public RPChance(playerid)
{
new rand = random(2);
new string[128];
if(rand == 0)
{
format(string, sizeof(string), "The previous roleplay action was a success!");
ProxDetector(20, playerid, string, COLOR_GREEN);
}
else
{
format(string, sizeof(string), "The previous roleplay action was a failure.");
ProxDetector(20, playerid, string, COLOR_RED);
}
return 1;
}
PHP Code:
CMD:rpchance(playerid, params[])
{
new string[128];
format(string, sizeof(string), "%s is determining how the previous roleplay action should go...", GetName(playerid));
ProxDetector(20, playerid, string, COLOR_GREYRED);
SetTimerEx("RPChance", 3000, 0, "i", playerid);
return 1;
}