[Include] gCasino - Scripted Casino's
#1

While working on an RP script last year, I made a simple script to re-create the single player poker casino game.

This is my first attempt at making an include, if I have made any mistakes please help me learn by suggesting ways to do it better instead of pointing out flaws.

Should now be fixed!

The current version 1.0.0.2 only re-creates the poker game, but has the flexibility to add other casino games in the future.

Video:
http://www.youtube.com/watch?v=Fe8FEUoXDmE

To add a new casino game object:
pawn Code:
CreateCasinoMachine(_type, Float:_lX, Float:_lY, Float:_lZ, Float:_rX, Float:_rY, Float:_rZ, useDynamicObj=0);

// _type is the Casino Type (Currently only CASINO_MACHINE_POKER)
// _lX, _lY, _lZ is the Position X/Y/Z
// _rX, _rY, _rZ is the Rotation X/Y/Z
// useDynamicObj=0 is to use the DynamicObject in incognito's streamer (Requires the <streamer> be included prior to <GrimCasino> )

//Returns: _machineID
To remove a casino object:
pawn Code:
RemoveCasinoMachine(_machineID); //Safely destroy a casino object
Other functions:
pawn Code:
IsValidCasinoMachineType(_type); //Is this casino type valid?
GetMachineType(_machineID, &_type); //Gets the casino machine type (Returns 0 if its an invalid machine id)
ClosestCasinoMachine(playerid); //Machine ID they are near (INVALID_CASINO_MACHINE_ID if by none)
IsPlayerAtAnyCasinoMachine(playerid); //Is player currently using any machine
IsPlayerAtCasinoMachine(playerid, _machineID); //is player currently using a machine
RemoveAllFromMachine(_machineID); //Remove all players using a machine
RemoveFromMachine(playerid, _machineID); //Remove a player from a machine
RemoveAllFromAllMachines(); //Kick all players from all machines
Callbacks:
pawn Code:
forward OnCasinoMoney(playerid, machineid, amount, result); //Casino Money Event
//result = CASINO_MONEY_CHARGE ~ This is called when they place a bet
//result = CASINO_MONEY_WIN ~ This is called if they win some money
//result = CASINO_MONEY_NOTENOUGH ~ This is called if they don't have enough to place the desired bet

forward OnCasinoStart(playerid, machineid); //Called when a Casino interface is opened
forward OnCasinoEnd(playerid, machineid); //Called when a Casino interface is closed
forward OnCasinoMessage(playerid, machineid, message[]); //Called when the casino has some text for the player, such as "Hold any or all of your cards"
Note:
So this can work with any existing anti-cheats, the following must be added in your code:
pawn Code:
stock CasinoGetPlayerMoney(playerid) {
    return GetPlayerMoney(playerid);
}
This allows you to control how the players money is checked.

Example:

pawn Code:
#include <a_samp>
    #include <core>
    #include <float>
    #include <GrimCasino>
     
    main() {
            print("----------------------------------");
            print("  Bare Script");
            print("----------------------------------");
    }
     
    public OnGameModeInit() {
            CreateCasinoMachine(CASINO_MACHINE_POKER, 2034.9810, 1340.2120, 10.6517, 0.0000, 0.0000, -90.0000);
            return 1;
    }
     
    public OnCasinoStart(playerid, machineid) {
            new _type;
            if (GetMachineType(machineid, _type)) {
                if (_type == CASINO_MACHINE_POKER) {
                            SendClientMessage(playerid, 0xFFFFFFFF, "[CASINO] Welcome to the Poker machine");
                            SendClientMessage(playerid, 0xFFFFFFFF, " > How to play:");
                            SendClientMessage(playerid, 0xFFFFFFFF, " >  Select how many coins to wager, the more you wager, the higher your winnings");
                            SendClientMessage(playerid, 0xFFFFFFFF, " >  If you wager 1 coin ($100) and your hand is a Straight, you will win $400");
                            SendClientMessage(playerid, 0xFFFFFFFF, " >  For information on poker hands see: http://en.wikipedia.org/wiki/List_of_poker_hands");
                    }
            }
    }
     
    public OnCasinoEnd(playerid, machineid) {
        SendClientMessage(playerid, 0xFFFFFFFF, "[CASINO] Goodbye, Thanks for playing!");
    }
     
    public OnCasinoMessage(playerid, machineid, message[]) {
            new _msg[128];
            format(_msg, 128, "[CASINO] %s", message);
            SendClientMessage(playerid, 0xFFFFFFFF, _msg);
    }
     
    public OnCasinoMoney(playerid, machineid, amount, result) {
            new message[128];
            if (result == CASINO_MONEY_CHARGE) {
                    GivePlayerMoney(playerid, (amount * -1));
                    format(message, 128, "[CASINO] You have been charged $%i", amount);
            } else if (result == CASINO_MONEY_WIN) {
                    GivePlayerMoney(playerid, amount);
                    format(message, 128, "[CASINO] You have won $%i", amount);
            } else {/*if (result == CASINO_MONEY_NOTENOUGH) {*/
                    format(message, 128, "[CASINO] You dont have $%i to place a bet!", amount);
            }
            SendClientMessage(playerid, 0xFFFFFFFF, message);
    }
     
    stock CasinoGetPlayerMoney(playerid) {
            return GetPlayerMoney(playerid);
    }

Downloads:

GrimCasino.inc SolidFiles V1.0.0.2 PasteBin
Example: http://pastebin.com/MAhK0zhh

Any questions feel free to ask
Reply
#2

This is beautiful! Im building an RP server and would love this include! My suggestion to you is add more games of course! Suggestions:
Track Betting (Like in singleplayer)
Blackjack
Texas Hold 'em

That's just off the top of my head. MAy I ask you send me a PM with each new update? That would be amazing!

EDIT
More suggestions (maybe too complicated):
7-card no peek
Slots (how could I forget that? I always lose my money on those things...)
Roulette(?) I never was a fan of it though.
Reply
#3

Looks great! I suggest you to improve the textdraw colors and also make those column separator's color to a custom one. Overall, it's really good.
Reply
#4

Thanks


If I get some time ill work on the other casino games.

About the download, its the source as a pastebin, ill upload the file, and update the thread, thanks
Reply
#5

Quote:
Originally Posted by Grimrandomer
View Post
Thanks


If I get some time ill work on the other casino games.

About the download, its the source as a pastebin, ill upload the file, and update the thread, thanks
Yeah, I figured out how to "compile" it, Im dumb lol

EDIT
After setting it up I'm getting these errors:
Code:
C:\Users\AEROTA~1\Desktop\LS-RP\pawno\include\GrimCasino.inc(1172) : warning 201: redefinition of constant/macro (symbol "OnGameModeInit")
C:\Users\AEROTA~1\Desktop\LS-RP\pawno\include\GrimCasino.inc(1173) : warning 201: redefinition of constant/macro (symbol "OnPlayerConnect")
C:\Users\Aerotactics' PC\Desktop\LS-RP\gamemodes\LS-RP.pwn(108) : error 017: undefined symbol "useDynamicObj"
C:\Users\Aerotactics' PC\Desktop\LS-RP\gamemodes\LS-RP.pwn(108) : warning 215: expression has no effect
C:\Users\Aerotactics' PC\Desktop\LS-RP\gamemodes\LS-RP.pwn(108) : error 001: expected token: ";", but found ")"
C:\Users\Aerotactics' PC\Desktop\LS-RP\gamemodes\LS-RP.pwn(108) : error 029: invalid expression, assumed zero
C:\Users\Aerotactics' PC\Desktop\LS-RP\gamemodes\LS-RP.pwn(108) : fatal error 107: too many error messages on one line
And line 108 in my script is:
Code:
CreateCasinoMachine(CASINO_MACHINE_POKER,1565.4,-2330.8,13.2, 0, 0, 0, useDynamicObj=1);
And it's under OnGamemodeInit.

EDIT 2
I fixed line 108 by removing "useDynamicObj=1" but I must point out the other errors to you.

EDIT 3
Anytime I try to join my server I'm DCed and this hasnt happened without the plugin. I'm gonna have to remove it for now until all the bugs are fixed. Keep me posted though!
Reply
#6

Its ok I should have uploaded it as a file anyway

The hardest bit about this was the checking of a players "hand" for poker:

pawn Code:
cPoker_checkGame(playerid) {
   
    new suit_a = cPoker_checkGameContains(playerid, CARD_ACE, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_a: %i", suit_a);
    new suit_2 = cPoker_checkGameContains(playerid, 2, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_2: %i", suit_2);
    new suit_3 = cPoker_checkGameContains(playerid, 3, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_3: %i", suit_3);
    new suit_4 = cPoker_checkGameContains(playerid, 4, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_4: %i", suit_4);
    new suit_5 = cPoker_checkGameContains(playerid, 5, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_5: %i", suit_5);

    if (c_suitsEqual(suit_a,suit_2,suit_3,suit_4,suit_5)) {
        ////print("CHECK_ROYALFLUSH");
        return CHECK_ROYALFLUSH;
    }
   
    new suit_10 = cPoker_checkGameContains(playerid, 10, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_10: %i", suit_10);
    new suit_j = cPoker_checkGameContains(playerid, CARD_JACK, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_j: %i", suit_j);
    new suit_q = cPoker_checkGameContains(playerid, CARD_QUEEN, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_q: %i", suit_q);
    new suit_k = cPoker_checkGameContains(playerid, CARD_KING, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_k: %i", suit_k);
   
    if (c_suitsEqual(suit_10,suit_j,suit_q,suit_k,suit_a)) {
        ////print("CHECK_ROYALFLUSH");
        return CHECK_ROYALFLUSH;
    }
   
    new suit_6 = cPoker_checkGameContains(playerid, 6, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_6: %i", suit_6);
    new suit_7 = cPoker_checkGameContains(playerid, 7, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_7: %i", suit_7);
    new suit_8 = cPoker_checkGameContains(playerid, 8, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_8: %i", suit_8);
    new suit_9 = cPoker_checkGameContains(playerid, 9, CARD_TYPE_NONE, CPOKER_CHECKMODE_CARDSUIT);
    ////printf("suit_9: %i", suit_9);
   
    ////print("CHECK_STRAIGHTFLUSH - START");
    if (c_suitsEqual(suit_2,suit_3,suit_4,suit_5,suit_6)) {
        return CHECK_STRAIGHTFLUSH;
    } else if (c_suitsEqual(suit_3,suit_4,suit_5,suit_6,suit_7)) {
        return CHECK_STRAIGHTFLUSH;
    } else if (c_suitsEqual(suit_4,suit_5,suit_6,suit_7,suit_8)) {
        return CHECK_STRAIGHTFLUSH;
    } else if (c_suitsEqual(suit_5,suit_6,suit_7,suit_8,suit_9)) {
        return CHECK_STRAIGHTFLUSH;
    } else if (c_suitsEqual(suit_6,suit_7,suit_8,suit_9,suit_10)) {
        return CHECK_STRAIGHTFLUSH;
    } else if (c_suitsEqual(suit_7,suit_8,suit_9,suit_10,suit_j)) {
        return CHECK_STRAIGHTFLUSH;
    } else if (c_suitsEqual(suit_8,suit_9,suit_10,suit_j,suit_q)) {
        return CHECK_STRAIGHTFLUSH;
    } else if (c_suitsEqual(suit_9,suit_10,suit_j,suit_q,suit_k)) {
        return CHECK_STRAIGHTFLUSH;
    }
    ////print("CHECK_STRAIGHTFLUSH - END");
   
    new countC[13];
    ////print("CHECK_FOUROFAKIND - START");
    for (new _c=0; _c<5; _c++) {
        new _n = cPokerGame[playerid][_c][1];
        ////printf("_n: %i", _n);
        countC[_n-1]++;
        if (countC[_n-1]==4) {
            ////print("CHECK_FOUROFAKIND");
            return CHECK_FOUROFAKIND;
        }
    }
    ////print("CHECK_FOUROFAKIND - END");
   
    ////print("CHECK_FULLHOUSE - START");
    for (new _card=1; _card<=13; _card++) {
        if (countC[_card-1]==3) {
            for (new _subCard=1; _subCard<=13; _subCard++) {
                if (_subCard != _card) {
                    if (countC[_subCard-1]==2) {
                        //print("CHECK_FULLHOUSE");
                        return CHECK_FULLHOUSE;
                    }
                }
            }
        }
    }
    ////print("CHECK_FULLHOUSE - END");
   
    if (c_Equal(cPokerGame[playerid][0][0],cPokerGame[playerid][1][0],cPokerGame[playerid][2][0],cPokerGame[playerid][3][0],cPokerGame[playerid][4][0])) {
        ////print("CHECK_FLUSH");
        return CHECK_FLUSH;
    }

    ////print("CHECK_STRAIGHT - START");
    if (c_anySuits(suit_a,suit_2,suit_3,suit_4,suit_5)) {
        return CHECK_STRAIGHT;
    } else if (c_anySuits(suit_2,suit_3,suit_4,suit_5,suit_6)) {
        return CHECK_STRAIGHT;
    } else if (c_anySuits(suit_3,suit_4,suit_5,suit_6,suit_7)) {
        return CHECK_STRAIGHT;
    } else if (c_anySuits(suit_4,suit_5,suit_6,suit_7,suit_8)) {
        return CHECK_STRAIGHT;
    } else if (c_anySuits(suit_5,suit_6,suit_7,suit_8,suit_9)) {
        return CHECK_STRAIGHT;
    } else if (c_anySuits(suit_6,suit_7,suit_8,suit_9,suit_10)) {
        return CHECK_STRAIGHT;
    } else if (c_anySuits(suit_7,suit_8,suit_9,suit_10,suit_j)) {
        return CHECK_STRAIGHT;
    } else if (c_anySuits(suit_8,suit_9,suit_10,suit_j,suit_q)) {
        return CHECK_STRAIGHT;
    } else if (c_anySuits(suit_9,suit_10,suit_j,suit_q,suit_k)) {
        return CHECK_STRAIGHT;
    } else if (c_anySuits(suit_10,suit_j,suit_q,suit_k,suit_a)) {
        return CHECK_STRAIGHT;
    }
    ////print("CHECK_STRAIGHT - END");
   
    ////print("CHECK_THREEOFAKIND - START");
    for (new _card=1; _card<=13; _card++) {
        if (countC[_card-1]==3) {
            for (new _subCard=1; _subCard<=13; _subCard++) {
                if (_subCard != _card) {
                    if (countC[_subCard-1]==1) {
                        for (new _subSubCard=1; _subSubCard<=13; _subSubCard++) {
                            if (_subCard != _card && _subSubCard != _card && _subCard != _subSubCard) {
                                if (countC[_subSubCard-1]==1) {
                                    return CHECK_THREEOFAKIND;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    ////print("CHECK_THREEOFAKIND - END");
   
    ////print("CHECK_TWOPAIRS - START");
    for (new _card=1; _card<=13; _card++) {
        ////printf("_card: %i", _card);
        if (countC[_card-1]==2) {
            ////printf("countC[_card-1]: %i", countC[_card-1]);
            for (new _subCard=1; _subCard<=13; _subCard++) {
                ////printf("_subCard: %i", _subCard);
                if (_subCard != _card) {
                    if (countC[_subCard-1]==2) {
                        ////printf("countC[_subCard-1]: %i", countC[_subCard-1]);
                        return CHECK_TWOPAIRS;
                    }
                }
            }
        }
    }
    ////print("CHECK_TWOPAIRS - END");
   
    ////print("CHECK_JACKORBETTER - START");
    for (new _c=0; _c<5; _c++) {
        new _c_v = cPokerGame[playerid][_c][1];
        if (_c_v >= CARD_JACK || _c_v == CARD_ACE) {
            return CHECK_JACKORBETTER;
        }
    }
    ////print("CHECK_JACKORBETTER - END");
   
    return CHECK_NONE;
}
Reply
#7

Code:
warning 201: redefinition of constant/macro (symbol "OnGameModeInit")
warning 201: redefinition of constant/macro (symbol "OnPlayerConnect")
warning 201: redefinition of constant/macro (symbol "OnPlayerClickTextDraw")
warning 201: redefinition of constant/macro (symbol "OnPlayerClickPlayerTextDraw")
Reply
#8

Quote:
Originally Posted by audriuxxx
View Post
Code:
warning 201: redefinition of constant/macro (symbol "OnGameModeInit")
warning 201: redefinition of constant/macro (symbol "OnPlayerConnect")
warning 201: redefinition of constant/macro (symbol "OnPlayerClickTextDraw")
warning 201: redefinition of constant/macro (symbol "OnPlayerClickPlayerTextDraw")
Hmm, Worked on my test game mode, Whats the code inside your OnGameModeInit?
Reply
#9

simple functions good!
Reply
#10

Very nice well

PS: what's the name of the song?
Reply
#11

You did a good design on the textdraw and the script looks good to me, I would suggest that you would use Normal Per-Player Array/Var instead of using PVar, you should look into this thread about PVar and its disadvantage and advantage: https://sampforum.blast.hk/showthread.php?tid=268499
Reply
#12

Hopefully now fixed, i followed the tutorial wrong :P


Quote:
Originally Posted by pds2k12
Посмотреть сообщение
You did a good design on the textdraw and the script looks good to me, I would suggest that you would use Normal Per-Player Array/Var instead of using PVar, you should look into this thread about PVar and its disadvantage and advantage: https://sampforum.blast.hk/showthread.php?tid=268499
I did consider removing the PVars, and i know i should, just did not get around to it, probably will in an update when i have lots off casino games.
Reply
#13

Not quite fixed, just ran "#include <GrimCasino>" with my script and got:

Quote:

C:\Users\AEROTA~1\Desktop\LS-RP\pawno\include\GrimCasino.inc(819) : error 017: undefined symbol "CasinoGetPlayerMoney"

Thanks for keeping me updated though! Looking forward to next update, will probably be in bed soon though so, tomorrow.
Reply
#14

Quote:
Originally Posted by Aerotactics
Посмотреть сообщение
Not quite fixed, just ran "#include <GrimCasino>" with my script and got:



Thanks for keeping me updated though! Looking forward to next update, will probably be in bed soon though so, tomorrow.
You need to add
pawn Код:
stock CasinoGetPlayerMoney(playerid) {
    return GetPlayerMoney(playerid);
}
To your script, so you can tell the script how you want it to get a players money to check they can place a bet, was in a "Note" on first post
Reply
#15

warning 201: redefinition of constant/macro (symbol "OnPlayerClickPlayerTextDraw")
Reply
#16

I get this in here:

Код:
#define OnPlayerClickPlayerTextDraw MP_OPCPTD
This code is in my gamemod. But then how to leave this code, and this system and don't get this warning?
Reply
#17

nice job

pawn Код:
native CountAllCasinoMachine();
Reply
#18

Quote:
Originally Posted by audriuxxx
Посмотреть сообщение
I get this in here:

Код:
#define OnPlayerClickPlayerTextDraw MP_OPCPTD
This code is in my gamemod. But then how to leave this code, and this system and don't get this warning?
Are you using this as an include?
Reply
#19

Yes your codes who was in include i left it. But this

#define OnPlayerClickPlayerTextDraw MP_OPCPTD

Is in my gamemode. But can i do that?

Where this code in your include:

Код:
public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid) {
	if (GetPVarInt(playerid, "ss_casino_use") == 1) {
		new _machineID = GetPVarInt(playerid, "ss_casino_using");
		switch (_machines[_machineID][cm_type]) {
			case CASINO_MACHINE_POKER: {
				for (new _b=0; _b<5; _b++) {
					if (playertextid == poker_hold[playerid][_b]) {
						cPoker_button(playerid, CASINO_POKER_BTN_HOLD, _b);
					}
				}
			}
		}
	}

	if (funcidx("_gCasino_OPCPTD") != -1){
		return CallLocalFunction("_gCasino_OPCPTD", "ii", playerid, _:playertextid);
	}
	return 1;
}
Upload this thing to my gamemode like this:

Код:
if (GetPVarInt(playerid, "ss_casino_use") == 1) {
		new _machineID = GetPVarInt(playerid, "ss_casino_using");
		switch (_machines[_machineID][cm_type]) {
			case CASINO_MACHINE_POKER: {
				for (new _b=0; _b<5; _b++) {
					if (playertextid == poker_hold[playerid][_b]) {
						cPoker_button(playerid, CASINO_POKER_BTN_HOLD, _b);
					}
				}
			}
		}
	}
Just a this code, and then delete from your include:

#if defined _ALS_OnPlayerClickPlayerTextDra
#undef OnPlayerClickPlayerTextDraw
#else
#define _ALS_OnPlayerClickPlayerTextDra
#endif

#define OnPlayerClickPlayerTextDraw _gCasino_OPCPTD

forward _gCasino_OPCPTD(playerid, PlayerTextlayertextid);
Reply
#20

Ok, I see, your trying to merge it into your game mode. As im new to includes im not quite sure if thats best way to do it, but if anyone else knows im sure they can answer.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)