Simple /flipcoin command [ZCMD, sscanf, foreach] -
NotYoMama - 10.07.2015
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
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>
Put the define under all of the #includes or wherever your color defines are.
Make sure you don't already have it defined
PHP Code:
#define COLOR_LIGHTBLUE 0x33CCFFAA
You should put your stocks at the end of the script or wherever your other stocks are. Search if you already have some of these stocks, then just change their name in CMD:flipcoin & CMD:rpchance
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;
}
}
}
Replacing the "_" with a blank space " ", so instead of Joseph_Colton it will show Joseph Colton
PHP Code:
stock GetName(playerid)
{
new name[24];
GetPlayerName(playerid, name, sizeof(name));
strreplace(name, '_', ' ');
return name;
}
The ProxDetector is used to send a message to the players who are near the player who is sending a message.
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);
}
}
}
If you compile it, you should not get errors.
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>
You will need all of the stocks from the /flipcoin part, so just copy them from there.
PHP Code:
#define COLOR_GREYRED 0x70825BFF
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
Place the forward at your other forwards or above the public function.
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;
}
The timer is in miliseconds, 1.000 miliseconds = 1 second, so it' s set to 3 seconds.
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;
}
Your feedback/suggestions are welcome!
Re: Simple /flipcoin command [ZCMD, sscanf, foreach] -
reyisgod - 15.07.2015
lol?
PHP Code:
stock randomex(min, max) { return random(max - min) + min; }
YCMD:coin(playerid, params[], help){
#pragma unused help, params
new kint = randomex(1, 3);
if( kint == 1 )
SendClientMessage(playerid, -1, "1");
else
SendClientMessage(playerid, -1, "2");
return 1;
}
Re: Simple /flipcoin command [ZCMD, sscanf, foreach] -
Calgon - 15.07.2015
You missed the most important thing... checking if they even have a coin to flip.
Re: Simple /flipcoin command [ZCMD, sscanf, foreach] - Emmet_ - 15.07.2015
Also, try spamming /rpchance and your server will be full of timers!
Did this tutorial take 6 months to make, by any chance?
Re: Simple /flipcoin command [ZCMD, sscanf, foreach] -
MellikJKE - 01.08.2015
lol!(2)
PHP Code:
CMD:flipcoin(playerid, params[])
{
new rand = random(2);
if(rand == 1 ) return SendClientMessage(playerid, -1, "+1 to CHANCE");
else return SendClientMessage(playerid, -1, "Chance is = '0'");
return true;
}
Re: Simple /flipcoin command [ZCMD, sscanf, foreach] -
Calgon - 01.08.2015
Quote:
Originally Posted by MellikJKE
lol!(2)
PHP Code:
CMD:flipcoin(playerid, params[])
{
new rand = random(2);
if(rand == 1 ) return SendClientMessage(playerid, -1, "+1 to CHANCE");
else return SendClientMessage(playerid, -1, "Chance is = '0'");
return true;
}
|
Defeats the point when other local players can't see the reaction.