SA-MP Forums Archive
Help - Dice Game - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help - Dice Game (/showthread.php?tid=271022)



Help - Dice Game - Compton - 22.07.2011

Hello, I never done such thing before So I have no Idea how to make this.

Well maybe some of you know on some RP servers there is a dice game, you go to the 24/7 buy the dice cubes and then you go and play with your friends on money. Im wondering if anyone could explain to me or make a dice game script?

-Thank you


Re: Help - Dice Game - Calgon - 22.07.2011

Basically, you mean a dice you can roll with 6 sides, you can roll it and it can land on any number between 1 and 6? If so:

pawn Код:
CMD:dice(playerid, params[]) { // zcmd command
    new
        Float: fPlayerPos[3], // create a variable to store a player's position
        szPlayerName[MAX_PLAYER_NAME], // create a variable to store a player's name
        szMessage[64]; // create a string we can use to format our message

    GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME); // get the player's name
    GetPlayerPos(playerid, fPlayerPos[0], fPlayerPos[1], fPlayerPos[2]); // get the player's position
    format(szMessage, sizeof(szMessage), "* %s has rolled a dice which landed on %d", szPlayerName, 1+random(6)); // format the string with our message
    // random(6) gets a number between 0 to 5, so I've added random(6) on to 1, so the number will be between 1 and 6.
    // the rest of the line above generally formats the message to send to the player, we show their name and the number the dice landed on
   
    // I'd advice usage of a function for this, like ProxDetector of whatever you have to your avail
    for(new i; i < MAX_PLAYERS; i++) { // loop through all players online
        if(IsPlayerConnected(i) && IsPlayerInRangeOfPoint(i, 10, fPlayerPos[0], fPlayerPos[1], fPlayerPos[2])) { // check if they're within 10 units of whatever distance is used as well as if the player slot # is connected
            SendClientMessage(i, 0, szMessage); // send the message to them if the above criteria is met
        }
    }
   
    return 1;
}
We don't really have any understanding of what your gamemode uses for 24/7 variables and whatnot, so this will work for anyone who types /dice.


Re: Help - Dice Game - Finn - 22.07.2011

random(5) selects a random number between 0-4.

Correct way would be random(6) + 1.