forked from dnlowman/samp-poker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Poker_Utils.pwn
207 lines (176 loc) · 5.49 KB
/
Poker_Utils.pwn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
© Los Santos Role Play 2017
Texas Hold 'em Poker
Release Candidate 1
--------------------------------------------------------------------------------
Description:
A complete Texas Hold 'em Poker mini-game
for San Andreas Multiplayer.
--------------------------------------------------------------------------------
Author(s):
Noble -
Game scripting.
San Andreas Multiplayer plugin port.
Cactus Kev -
Hand Evaluator
(http://www.suffecool.net/poker/evaluator.html)
Paul Senzee -
Hash optimizations.
--------------------------------------------------------------------------------
Special Thanks:
Los Santos Role Play development team.
San Andreas Mutliplayer development team.
Los Santos Role Play tester team.
--------------------------------------------------------------------------------
License:
Please see the enclosed LICENSE file in the repository.
*/
stock Pkr_FormatNumber(number)
{
new _str[128];
format(_str, sizeof(_str), "%i", number);
new _len = strlen(_str);
if(_len > 3)
{
new _i;
if(_len >= 4) _i = 1;
if(_len >= 5) _i = 2;
if(_len >= 6) _i = 3;
if(_len >= 7) _i = 1;
if(_len >= 8) _i = 2;
if(_len >= 9) _i = 3;
while(_i < _len)
{
strins(_str, ",", _i);
_i += 4;
}
}
return _str;
}
stock Pkr_GetClientName(playerid) {
new _name[MAX_PLAYER_NAME];
GetPlayerName(playerid, _name, sizeof(_name));
return _name;
}
#if !defined POKER_LSRP
GetPlayerRealMoney(playerid) {
#pragma unused playerid
return 1000000;
}
#endif
new cardMap[13] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1 };
stock Pkr_ReturnCardSpriteName(value)
{
new
spriteName[16],
val = ((value >> 8) & 0xF);
if(value & 0x8000) format(spriteName, sizeof(spriteName), "LD_CARD:cd%ic", cardMap[val]);
else if(value & 0x4000) format(spriteName, sizeof(spriteName), "LD_CARD:cd%id", cardMap[val]);
else if(value & 0x2000) format(spriteName, sizeof(spriteName), "LD_CARD:cd%ih", cardMap[val]);
else format(spriteName, sizeof(spriteName), "LD_CARD:cd%is", cardMap[val]);
return spriteName;
}
stock PkrSys_ReturnRandomUnusedCard(const gameId)
{
new _f, _c, _i;
do
{
_f = 0;
_c = random(52);
for(_i = 0; _i < MAX_TABLE_CARDS; ++_i) if(g_rgCardDeck[_c] == g_rgPokerGames[gameId][TABLE_CARD_VALUES][_i]) ++_f;
for(_i = 0; _i < MAX_POKER_PLAYERS; ++_i) if(g_rgCardDeck[_c] == g_rgPokerGames[gameId][PLAYER_CARD_ONE_VALUE][_i] || g_rgCardDeck[_c] == g_rgPokerGames[gameId][PLAYER_CARD_TWO_VALUE][_i]) ++_f;
}
while(_f > 0);
return _c;
}
Pkr_IsNumeric(const string[])
{
for(new i = 0, j = strlen(string); i < j; i++) if (string[i] > '9' || string[i] < '0') return 0;
return 1;
}
stock Pkr_HandRank(const value)
{
if(value > 6185) return HIGH_CARD;
if(value > 3325) return ONE_PAIR;
if(value > 2467) return TWO_PAIR;
if(value > 1609) return THREE_OF_A_KIND;
if(value > 1599) return STRAIGHT;
if(value > 322) return FLUSH;
if(value > 166) return FULL_HOUSE;
if(value > 10) return FOUR_OF_A_KIND;
return STRAIGHT_FLUSH;
}
stock Pkr_ReturnHandName(const rank)
{
new _sz[128] = "ERROR_NO_NAME";
switch(rank)
{
case (HAND_TYPES: HIGH_CARD): format(_sz, sizeof(_sz), "High Card");
case (HAND_TYPES: ONE_PAIR): format(_sz, sizeof(_sz), "One Pair");
case (HAND_TYPES: TWO_PAIR): format(_sz, sizeof(_sz), "Two Pair");
case (HAND_TYPES: THREE_OF_A_KIND): format(_sz, sizeof(_sz), "Three of a Kind");
case (HAND_TYPES: STRAIGHT): format(_sz, sizeof(_sz), "Straight");
case (HAND_TYPES: FLUSH): format(_sz, sizeof(_sz), "Flush");
case (HAND_TYPES: FULL_HOUSE): format(_sz, sizeof(_sz), "Full House");
case (HAND_TYPES: FOUR_OF_A_KIND): format(_sz, sizeof(_sz), "Four of a Kind");
case (HAND_TYPES: STRAIGHT_FLUSH): format(_sz, sizeof(_sz), "Straight Flush");
}
return _sz;
}
Pkr_SendGameMessage(const gameId, const color, const message[])
{
Pkr_ForeachPlayer(player)
if(g_rgPokerGames[gameId][PLAYERS][player] != INVALID_PLAYER_ID)
SendClientMessage(g_rgPokerGames[gameId][PLAYERS][player], color, message);
Pkr_ForeachPlayerIdInPool(playerId)
if(GetPVarType(playerId, POKER_SPECTATE_VAR_NAME) != PLAYER_VARTYPE_NONE && GetPVarInt(playerId, POKER_SPECTATE_VAR_NAME) == gameId)
SendClientMessage(playerId, color, message);
return;
}
Pkr_SendFormattedGameMessage(const gameId, const color, fstring[], {Float, _}:...)
{
static const
STATIC_ARGS = 3;
new
n = (numargs() - STATIC_ARGS) * BYTES_PER_CELL;
if (n)
{
new
message[144],
arg_start,
arg_end;
#emit CONST.alt fstring
#emit LCTRL 5
#emit ADD
#emit STOR.S.pri arg_start
#emit LOAD.S.alt n
#emit ADD
#emit STOR.S.pri arg_end
do
{
#emit LOAD.I
#emit PUSH.pri
arg_end -= BYTES_PER_CELL;
#emit LOAD.S.pri arg_end
}
while (arg_end > arg_start);
#emit PUSH.S fstring
#emit PUSH.C 128
#emit PUSH.ADR message
n += BYTES_PER_CELL * 3;
#emit PUSH.S n
#emit SYSREQ.C format
n += BYTES_PER_CELL;
#emit LCTRL 4
#emit LOAD.S.alt n
#emit ADD
#emit SCTRL 4
Pkr_SendGameMessage(gameId, color, message);
return;
}
else
{
Pkr_SendGameMessage(gameId, color, fstring);
return;
}
}