/flipcoin
#1

Hey there!

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.

Here's mine:
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 also have a single player version, but it's far to simple
Reply
#2

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.

pawn Код:
//I'm not going to assume that the scripter is using any pre-existing assemblies (sscanf, zcmd, etc)
if(!strcmp(cmdtext,"/flipcoin",true))
    return SendClientMessage(playerid,-1,(random(2))?("The coin landed on heads."):("The coin landed on tails.") );

EDIT:
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 )
Reply
#3

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)