I was browsing today, and I found this thread. Basically it was the application form for NG:RP. However, one of the statements was "Create your own /flipcoin command" So, I'd like everyone to get involved. Just to see how scripting styles vary.
pawn Код:
#define Amount (1000)
COMMAND:flipcoin(playerid, params[])
{
new flip = random(2), pid, cStr[10 char];
pid = GetClosestPlayerToPlayer(playerid);
if(!GetClosestPlayerToPlayer(playerid)) return SendClientMessage(playerid, "No player nearby.");
if(sscanf(params, "s[10]", cStr))
{
new bool: call;
if(strcmp(cStr, "heads", true)) call = true;
if(strcmp(cStr, "tails", true)) call = false;
new String[40 + MAX_PLAYER_NAME char];
new Name[MAX_PLAYER_NAME];
new pName[MAX_PLAYER_NAME];
GetPlayerName(pid, pName, MAX_PLAYER_NAME);
GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
switch(flip)
{
case 0: // Heads
{
if(!call) // Incorrect :/
{
format(String, sizeof(String), "You beat %s and won Ј%d", Name, Amount);
SendClientMessage(pid, COLOR_YELLOW, String);
format(String, sizeof(String), "You lost Ј%d to %s", Amount, pName);
SendClientMessage(playerid, COLOR_YELLOW, String);
GivePlayerMoney(playerid, GetPlayerMoney(playerid) - Amount);
}
if(call)
{
format(String, sizeof(String), "You beat %s and won Ј%d", pName, Amount);
SendClientMessage(playerid, COLOR_YELLOW, String);
format(String, sizeof(String), "You lost Ј%d to %s", Amount, Name);
SendClientMessage(pid, COLOR_YELLOW, String);
GivePlayerMoney(pid, GetPlayerMoney(playerid) - Amount);
}
}
case 1: // Tails
{
if(call) // Incorrect :/
{
format(String, sizeof(String), "You beat %s and won Ј%d", Name, Amount);
SendClientMessage(pid, COLOR_YELLOW, String);
format(String, sizeof(String), "You lost Ј%d to %s", Amount, pName);
SendClientMessage(playerid, COLOR_YELLOW, String);
GivePlayerMoney(playerid, GetPlayerMoney(playerid) - Amount);
}
if(!call)
{
format(String, sizeof(String), "You beat %s and won Ј%d", pName, Amount);
SendClientMessage(playerid, COLOR_YELLOW, String);
format(String, sizeof(String), "You lost Ј%d to %s", Amount, Name);
SendClientMessage(pid, COLOR_YELLOW, String);
GivePlayerMoney(pid, GetPlayerMoney(playerid) - Amount);
}
}
}
}
else return SendClientMessage(playerid, -1, "Usage: /flipcoin heads or tails");
return 1;
}
I don't see the point of forcing any action on this other than the 50% roll. It should be up to the player the purpose of the roll, be it a bet or simply making a decision.
Also, your code is erroneous. The variable 'Amount' is undefined, you have no exception catch for if a player doesn't give any parameters ("/flipcoin"), and there is zero confirmation or permission granted from the second 'player', which could result in technical robbery (only a 50% chance though
Shit, yeah forgot the add the error line, however "Amount" Is defined at the top of the script. I simply forgot to add it to the code shown