1
0

poker.pwn 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Poker System
  11. Next Generation Gaming, LLC
  12. (created by Next Generation Gaming Development Team)
  13. * Copyright (c) 2016, Next Generation Gaming, LLC
  14. *
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without modification,
  18. * are not permitted in any case.
  19. *
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  25. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include <YSI\y_hooks>
  34. hook OnPlayerDisconnect(playerid, reason) {
  35. if(GetPVarType(playerid, "pkrTableID")) {
  36. new tableid = GetPVarInt(playerid, "pkrTableID")-1;
  37. // Convert prkChips to cgChips
  38. //SetPVarInt(playerid, "cgChips", GetPVarInt(playerid, "cgChips")+GetPVarInt(playerid, "pkrChips"));
  39. GivePlayerCashEx(playerid, TYPE_ONHAND, GetPVarInt(playerid, "pkrChips"));
  40. format(szMiscArray, sizeof(szMiscArray), "%s(%d) (IP:%s) has left the table with $%s (%d)", GetPlayerNameEx(playerid), GetPlayerSQLId(playerid), GetPlayerIpEx(playerid), number_format(GetPVarInt(playerid, "pkrChips")), tableid);
  41. Log("logs/poker.log", szMiscArray);
  42. PokerTable[tableid][pkrPot] -= GetPVarInt(playerid, "pkrChips"); // Poker Table Money Exploit fix.
  43. // De-occuply Slot
  44. PokerTable[tableid][pkrPlayers] -= 1;
  45. if(GetPVarInt(playerid, "pkrStatus")) PokerTable[tableid][pkrActivePlayers] -= 1;
  46. PokerTable[tableid][pkrSlot][GetPVarInt(playerid, "pkrSlot")] = -1;
  47. // Check & Stop the Game Loop if No Players at the Table
  48. if(PokerTable[tableid][pkrPlayers] == 0) {
  49. for(new i = 0, pid; i < 6; i++) {
  50. pid = PokerTable[tableid][pkrSlot][i];
  51. if(pid != INVALID_PLAYER_ID) {
  52. SetPVarInt(pid, "pkrChips", GetPVarInt(pid, "pkrChips")+PokerTable[tableid][pkrPot]); // Last one gets all.
  53. LeavePokerTable(pid);
  54. }
  55. }
  56. KillTimer(PokerTable[tableid][pkrPulseTimer]);
  57. new tmpString[64];
  58. format(tmpString, sizeof(tmpString), "Poker Table %d", tableid);
  59. Update3DTextLabelText(PokerTable[tableid][pkrText3DID], COLOR_YELLOW, tmpString);
  60. ResetPokerTable(tableid);
  61. }
  62. if(PokerTable[tableid][pkrRound] == 0 && PokerTable[tableid][pkrDelay] < 5) {
  63. ResetPokerRound(tableid);
  64. }
  65. SetPlayerInterior(playerid, PokerTable[tableid][pkrInt]);
  66. SetPlayerVirtualWorld(playerid, PokerTable[tableid][pkrVW]);
  67. SetPlayerPos(playerid, GetPVarFloat(playerid, "pkrTableJoinX"), GetPVarFloat(playerid, "pkrTableJoinY"), GetPVarFloat(playerid, "pkrTableJoinZ")+0.1);
  68. SetCameraBehindPlayer(playerid);
  69. TogglePlayerControllable(playerid, 1);
  70. ApplyAnimation(playerid, "CARRY", "crry_prtial", 2.0, 0, 0, 0, 0, 0);
  71. if(GetPVarInt(playerid, "pkrActiveHand")) {
  72. PokerTable[tableid][pkrActiveHands]--;
  73. }
  74. // Destroy Poker Memory
  75. DeletePVar(playerid, "pkrWinner");
  76. DeletePVar(playerid, "pkrCurrentBet");
  77. DeletePVar(playerid, "pkrChips");
  78. DeletePVar(playerid, "pkrTableJoinX");
  79. DeletePVar(playerid, "pkrTableJoinY");
  80. DeletePVar(playerid, "pkrTableJoinZ");
  81. DeletePVar(playerid, "pkrTableID");
  82. DeletePVar(playerid, "pkrSlot");
  83. DeletePVar(playerid, "pkrStatus");
  84. DeletePVar(playerid, "pkrRoomLeader");
  85. DeletePVar(playerid, "pkrRoomBigBlind");
  86. DeletePVar(playerid, "pkrRoomSmallBlind");
  87. DeletePVar(playerid, "pkrRoomDealer");
  88. DeletePVar(playerid, "pkrCard1");
  89. DeletePVar(playerid, "pkrCard2");
  90. DeletePVar(playerid, "pkrActivePlayer");
  91. DeletePVar(playerid, "pkrActiveHand");
  92. DeletePVar(playerid, "pkrHide");
  93. // Destroy GUI
  94. DestroyPokerGUI(playerid);
  95. }
  96. }
  97. PokerOptions(playerid, option)
  98. {
  99. switch(option)
  100. {
  101. case 0:
  102. {
  103. DeletePVar(playerid, "pkrActionOptions");
  104. PlayerTextDrawHide(playerid, PlayerPokerUI[playerid][38]);
  105. PlayerTextDrawHide(playerid, PlayerPokerUI[playerid][39]);
  106. PlayerTextDrawHide(playerid, PlayerPokerUI[playerid][40]);
  107. }
  108. case 1: // if(CurrentBet >= ActiveBet)
  109. {
  110. SetPVarInt(playerid, "pkrActionOptions", 1);
  111. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][38], "RAISE");
  112. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][39], "CHECK");
  113. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][40], "FOLD");
  114. PlayerTextDrawShow(playerid, PlayerPokerUI[playerid][38]);
  115. PlayerTextDrawShow(playerid, PlayerPokerUI[playerid][39]);
  116. PlayerTextDrawShow(playerid, PlayerPokerUI[playerid][40]);
  117. }
  118. case 2: // if(CurrentBet < ActiveBet)
  119. {
  120. SetPVarInt(playerid, "pkrActionOptions", 2);
  121. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][38], "CALL");
  122. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][39], "RAISE");
  123. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][40], "FOLD");
  124. PlayerTextDrawShow(playerid, PlayerPokerUI[playerid][38]);
  125. PlayerTextDrawShow(playerid, PlayerPokerUI[playerid][39]);
  126. PlayerTextDrawShow(playerid, PlayerPokerUI[playerid][40]);
  127. }
  128. case 3: // if(pkrChips < 1)
  129. {
  130. SetPVarInt(playerid, "pkrActionOptions", 3);
  131. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][38], "CHECK");
  132. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][39], "FOLD");
  133. PlayerTextDrawShow(playerid, PlayerPokerUI[playerid][38]);
  134. PlayerTextDrawShow(playerid, PlayerPokerUI[playerid][39]);
  135. }
  136. }
  137. }
  138. PokerCallHand(playerid)
  139. {
  140. ShowCasinoGamesMenu(playerid, DIALOG_CGAMESCALLPOKER);
  141. }
  142. PokerRaiseHand(playerid)
  143. {
  144. ShowCasinoGamesMenu(playerid, DIALOG_CGAMESRAISEPOKER);
  145. }
  146. PokerCheckHand(playerid)
  147. {
  148. if(GetPVarInt(playerid, "pkrActiveHand")) {
  149. SetPVarString(playerid, "pkrStatusString", "Check");
  150. }
  151. // Animation
  152. ApplyAnimation(playerid, "CASINO", "cards_raise", 4.1, 0, 1, 1, 1, 1, 1);
  153. }
  154. PokerFoldHand(playerid)
  155. {
  156. if(GetPVarInt(playerid, "pkrActiveHand")) {
  157. DeletePVar(playerid, "pkrCard1");
  158. DeletePVar(playerid, "pkrCard2");
  159. DeletePVar(playerid, "pkrActiveHand");
  160. DeletePVar(playerid, "pkrStatus");
  161. PokerTable[GetPVarInt(playerid, "pkrTableID")-1][pkrActiveHands]--;
  162. SetPVarString(playerid, "pkrStatusString", "Fold");
  163. // SFX
  164. GlobalPlaySound(5602, PokerTable[GetPVarInt(playerid, "pkrTableID")-1][pkrX], PokerTable[GetPVarInt(playerid, "pkrTableID")-1][pkrY], PokerTable[GetPVarInt(playerid, "pkrTableID")-1][pkrZ]);
  165. // Animation
  166. ApplyAnimation(playerid, "CASINO", "cards_out", 4.1, 0, 1, 1, 1, 1, 1);
  167. }
  168. }
  169. PokerDealHands(tableid)
  170. {
  171. new tmp = 0;
  172. // Loop through active players.
  173. for(new i = 0; i < 6; i++) {
  174. new playerid = PokerTable[tableid][pkrSlot][i];
  175. if(playerid != -1) {
  176. if(GetPVarInt(playerid, "pkrStatus") && GetPVarInt(playerid, "pkrChips") > 0) {
  177. SetPVarInt(playerid, "pkrCard1", PokerTable[tableid][pkrDeck][tmp]);
  178. SetPVarInt(playerid, "pkrCard2", PokerTable[tableid][pkrDeck][tmp+1]);
  179. SetPVarInt(playerid, "pkrActiveHand", 1);
  180. PokerTable[tableid][pkrActiveHands]++;
  181. // SFX
  182. PlayerPlaySound(playerid, 5602, 0.0, 0.0, 0.0);
  183. // Animation
  184. ApplyAnimation(playerid, "CASINO", "cards_in", 4.1, 0, 1, 1, 1, 1, 1);
  185. tmp += 2;
  186. }
  187. }
  188. }
  189. // Loop through community cards.
  190. for(new i = 0; i < 5; i++) {
  191. PokerTable[tableid][pkrCCards][i] = PokerTable[tableid][pkrDeck][tmp];
  192. tmp++;
  193. }
  194. }
  195. PokerShuffleDeck(tableid)
  196. {
  197. // SFX
  198. GlobalPlaySound(5600, PokerTable[tableid][pkrX], PokerTable[tableid][pkrY], PokerTable[tableid][pkrZ]);
  199. // Order the deck
  200. for(new i = 0; i < 52; i++) {
  201. PokerTable[tableid][pkrDeck][i] = i;
  202. }
  203. // Randomize the array (AKA Shuffle Algorithm)
  204. new rand, tmp, i;
  205. for(i = 52; i > 1; i--) {
  206. rand = random(52) % i;
  207. tmp = PokerTable[tableid][pkrDeck][rand];
  208. PokerTable[tableid][pkrDeck][rand] = PokerTable[tableid][pkrDeck][i-1];
  209. PokerTable[tableid][pkrDeck][i-1] = tmp;
  210. }
  211. }
  212. PokerFindPlayerOrder(tableid, index)
  213. {
  214. new tmpIndex = -1;
  215. for(new i = 0; i < 6; i++) {
  216. new playerid = PokerTable[tableid][pkrSlot][i];
  217. if(playerid != -1) {
  218. tmpIndex++;
  219. if(tmpIndex == index) {
  220. if(GetPVarInt(playerid, "pkrStatus") == 1)
  221. return playerid;
  222. }
  223. }
  224. }
  225. return -1;
  226. }
  227. PokerAssignBlinds(tableid)
  228. {
  229. if(PokerTable[tableid][pkrPos] == 6) {
  230. PokerTable[tableid][pkrPos] = 0;
  231. }
  232. // Find where to start & distubute blinds.
  233. new bool:roomDealer = false, bool:roomBigBlind = false, bool:roomSmallBlind = false;
  234. // Find the Dealer.
  235. new tmpPos = PokerTable[tableid][pkrPos];
  236. if(roomDealer == false) {
  237. if(tmpPos == 6) {
  238. tmpPos = 0;
  239. }
  240. new playerid = PokerFindPlayerOrder(tableid, tmpPos);
  241. if(playerid != -1) {
  242. SetPVarInt(playerid, "pkrRoomDealer", 1);
  243. SetPVarString(playerid, "pkrStatusString", "Dealer");
  244. roomDealer = true;
  245. } else {
  246. tmpPos++;
  247. }
  248. }
  249. // Find the player after the Dealer.
  250. tmpPos = PokerTable[tableid][pkrPos];
  251. if(roomBigBlind == false) {
  252. if(tmpPos == 6) {
  253. tmpPos = 0;
  254. }
  255. new playerid = PokerFindPlayerOrder(tableid, tmpPos);
  256. if(playerid != -1) {
  257. if(GetPVarInt(playerid, "pkrRoomDealer") != 1 && GetPVarInt(playerid, "pkrRoomBigBlind") != 1 && GetPVarInt(playerid, "pkrRoomSmallBlind") != 1) {
  258. SetPVarInt(playerid, "pkrRoomBigBlind", 1);
  259. new tmpString[128];
  260. format(tmpString, sizeof(tmpString), "~r~BB -$%d", PokerTable[tableid][pkrBlind]);
  261. SetPVarString(playerid, "pkrStatusString", tmpString);
  262. roomBigBlind = true;
  263. if(GetPVarInt(playerid, "pkrChips") < PokerTable[tableid][pkrBlind]) {
  264. PokerTable[tableid][pkrPot] += GetPVarInt(playerid, "pkrChips");
  265. SetPVarInt(playerid, "pkrChips", 0);
  266. } else {
  267. PokerTable[tableid][pkrPot] += PokerTable[tableid][pkrBlind];
  268. SetPVarInt(playerid, "pkrChips", GetPVarInt(playerid, "pkrChips")-PokerTable[tableid][pkrBlind]);
  269. }
  270. SetPVarInt(playerid, "pkrCurrentBet", PokerTable[tableid][pkrBlind]);
  271. PokerTable[tableid][pkrActiveBet] = PokerTable[tableid][pkrBlind];
  272. } else {
  273. tmpPos++;
  274. }
  275. } else {
  276. tmpPos++;
  277. }
  278. }
  279. // Small Blinds are active only if there are more than 2 players.
  280. if(PokerTable[tableid][pkrActivePlayers] > 2) {
  281. // Find the player after the Big Blind.
  282. tmpPos = PokerTable[tableid][pkrPos];
  283. if(roomSmallBlind == false) {
  284. if(tmpPos == 6) {
  285. tmpPos = 0;
  286. }
  287. new playerid = PokerFindPlayerOrder(tableid, tmpPos);
  288. if(playerid != -1) {
  289. if(GetPVarInt(playerid, "pkrRoomDealer") != 1 && GetPVarInt(playerid, "pkrRoomBigBlind") != 1 && GetPVarInt(playerid, "pkrRoomSmallBlind") != 1) {
  290. SetPVarInt(playerid, "pkrRoomSmallBlind", 1);
  291. new tmpString[128];
  292. format(tmpString, sizeof(tmpString), "~r~SB -$%d", PokerTable[tableid][pkrBlind]/2);
  293. SetPVarString(playerid, "pkrStatusString", tmpString);
  294. roomSmallBlind = true;
  295. if(GetPVarInt(playerid, "pkrChips") < (PokerTable[tableid][pkrBlind]/2)) {
  296. PokerTable[tableid][pkrPot] += GetPVarInt(playerid, "pkrChips");
  297. SetPVarInt(playerid, "pkrChips", 0);
  298. } else {
  299. PokerTable[tableid][pkrPot] += (PokerTable[tableid][pkrBlind]/2);
  300. SetPVarInt(playerid, "pkrChips", GetPVarInt(playerid, "pkrChips")-(PokerTable[tableid][pkrBlind]/2));
  301. }
  302. SetPVarInt(playerid, "pkrCurrentBet", PokerTable[tableid][pkrBlind]/2);
  303. PokerTable[tableid][pkrActiveBet] = PokerTable[tableid][pkrBlind]/2;
  304. } else {
  305. tmpPos++;
  306. }
  307. } else {
  308. tmpPos++;
  309. }
  310. }
  311. }
  312. PokerTable[tableid][pkrPos]++;
  313. }
  314. PokerRotateActivePlayer(tableid)
  315. {
  316. new nextactiveid = -1, lastapid = -1, lastapslot = -1;
  317. if(PokerTable[tableid][pkrActivePlayerID] != -1) {
  318. lastapid = PokerTable[tableid][pkrActivePlayerID];
  319. for(new i = 0; i < 6; i++) {
  320. if(PokerTable[tableid][pkrSlot][i] == lastapid) {
  321. lastapslot = i;
  322. }
  323. }
  324. DeletePVar(lastapid, "pkrActivePlayer");
  325. DeletePVar(lastapid, "pkrTime");
  326. PokerOptions(lastapid, 0);
  327. }
  328. // New Round Init Block
  329. if(PokerTable[tableid][pkrRotations] == 0 && lastapid == -1 && lastapslot == -1) {
  330. // Find & Assign ActivePlayer to Dealer
  331. for(new i = 0; i < 6; i++) {
  332. new playerid = PokerTable[tableid][pkrSlot][i];
  333. if(GetPVarInt(playerid, "pkrRoomDealer") == 1) {
  334. nextactiveid = playerid;
  335. PokerTable[tableid][pkrActivePlayerID] = playerid;
  336. PokerTable[tableid][pkrActivePlayerSlot] = i;
  337. PokerTable[tableid][pkrRotations]++;
  338. PokerTable[tableid][pkrSlotRotations] = i;
  339. }
  340. }
  341. }
  342. else if(PokerTable[tableid][pkrRotations] >= 6)
  343. {
  344. PokerTable[tableid][pkrRotations] = 0;
  345. PokerTable[tableid][pkrStage]++;
  346. if(PokerTable[tableid][pkrStage] > 3) {
  347. PokerTable[tableid][pkrActive] = 4;
  348. PokerTable[tableid][pkrDelay] = 20+1;
  349. return 1;
  350. }
  351. PokerTable[tableid][pkrSlotRotations]++;
  352. if(PokerTable[tableid][pkrSlotRotations] >= 6) {
  353. PokerTable[tableid][pkrSlotRotations] -= 6;
  354. }
  355. new playerid = PokerFindPlayerOrder(tableid, PokerTable[tableid][pkrSlotRotations]);
  356. if(playerid != -1) {
  357. nextactiveid = playerid;
  358. PokerTable[tableid][pkrActivePlayerID] = playerid;
  359. PokerTable[tableid][pkrActivePlayerSlot] = PokerTable[tableid][pkrSlotRotations];
  360. PokerTable[tableid][pkrRotations]++;
  361. } else {
  362. PokerTable[tableid][pkrRotations]++;
  363. PokerRotateActivePlayer(tableid);
  364. }
  365. }
  366. else
  367. {
  368. PokerTable[tableid][pkrSlotRotations]++;
  369. if(PokerTable[tableid][pkrSlotRotations] >= 6) {
  370. PokerTable[tableid][pkrSlotRotations] -= 6;
  371. }
  372. new playerid = PokerFindPlayerOrder(tableid, PokerTable[tableid][pkrSlotRotations]);
  373. if(playerid != -1) {
  374. nextactiveid = playerid;
  375. PokerTable[tableid][pkrActivePlayerID] = playerid;
  376. PokerTable[tableid][pkrActivePlayerSlot] = PokerTable[tableid][pkrSlotRotations];
  377. PokerTable[tableid][pkrRotations]++;
  378. } else {
  379. PokerTable[tableid][pkrRotations]++;
  380. PokerRotateActivePlayer(tableid);
  381. }
  382. }
  383. if(nextactiveid != -1) {
  384. if(GetPVarInt(nextactiveid, "pkrActiveHand")) {
  385. new currentBet = GetPVarInt(nextactiveid, "pkrCurrentBet");
  386. new activeBet = PokerTable[tableid][pkrActiveBet];
  387. new apSoundID[] = {5809, 5810};
  388. new randomApSoundID = random(sizeof(apSoundID));
  389. PlayerPlaySound(nextactiveid, apSoundID[randomApSoundID], 0.0, 0.0, 0.0);
  390. if(GetPVarInt(nextactiveid, "pkrChips") < 1) {
  391. PokerOptions(nextactiveid, 3);
  392. } else if(currentBet >= activeBet) {
  393. PokerOptions(nextactiveid, 1);
  394. } else if (currentBet < activeBet) {
  395. PokerOptions(nextactiveid, 2);
  396. } else {
  397. PokerOptions(nextactiveid, 0);
  398. }
  399. SetPVarInt(nextactiveid, "pkrTime", 60);
  400. SetPVarInt(nextactiveid, "pkrActivePlayer", 1);
  401. }
  402. }
  403. return 1;
  404. }
  405. InitPokerTables()
  406. {
  407. for(new i = 0; i < MAX_POKERTABLES; i++) {
  408. PokerTable[i][pkrActive] = 0;
  409. PokerTable[i][pkrPlaced] = 0;
  410. PokerTable[i][pkrObjectID] = 0;
  411. for(new c = 0; c < MAX_POKERTABLEMISCOBJS; c++) {
  412. PokerTable[i][pkrMiscObjectID][c] = 0;
  413. }
  414. for(new s = 0; s < 6; s++) {
  415. PokerTable[i][pkrSlot][s] = -1;
  416. }
  417. PokerTable[i][pkrX] = 0.0;
  418. PokerTable[i][pkrY] = 0.0;
  419. PokerTable[i][pkrZ] = 0.0;
  420. PokerTable[i][pkrRX] = 0.0;
  421. PokerTable[i][pkrRY] = 0.0;
  422. PokerTable[i][pkrRZ] = 0.0;
  423. PokerTable[i][pkrVW] = 0;
  424. PokerTable[i][pkrInt] = 0;
  425. PokerTable[i][pkrPlayers] = 0;
  426. PokerTable[i][pkrLimit] = 6;
  427. PokerTable[i][pkrBuyInMax] = 1000;
  428. PokerTable[i][pkrBuyInMin] = 500;
  429. PokerTable[i][pkrBlind] = 100;
  430. PokerTable[i][pkrPos] = 0;
  431. PokerTable[i][pkrRound] = 0;
  432. PokerTable[i][pkrStage] = 0;
  433. PokerTable[i][pkrActiveBet] = 0;
  434. PokerTable[i][pkrSetDelay] = 15;
  435. PokerTable[i][pkrActivePlayerID] = -1;
  436. PokerTable[i][pkrActivePlayerSlot] = -1;
  437. PokerTable[i][pkrRotations] = 0;
  438. PokerTable[i][pkrSlotRotations] = 0;
  439. PokerTable[i][pkrWinnerID] = -1;
  440. PokerTable[i][pkrWinners] = 0;
  441. }
  442. }
  443. ResetPokerRound(tableid)
  444. {
  445. PokerTable[tableid][pkrRound] = 0;
  446. PokerTable[tableid][pkrStage] = 0;
  447. PokerTable[tableid][pkrActiveBet] = 0;
  448. PokerTable[tableid][pkrActive] = 2;
  449. PokerTable[tableid][pkrDelay] = PokerTable[tableid][pkrSetDelay];
  450. PokerTable[tableid][pkrPot] = 0;
  451. PokerTable[tableid][pkrRotations] = 0;
  452. PokerTable[tableid][pkrSlotRotations] = 0;
  453. PokerTable[tableid][pkrWinnerID] = -1;
  454. PokerTable[tableid][pkrWinners] = 0;
  455. // Reset Player Variables
  456. for(new i = 0; i < 6; i++) {
  457. new playerid = PokerTable[tableid][pkrSlot][i];
  458. if(playerid != -1) {
  459. DeletePVar(playerid, "pkrWinner");
  460. DeletePVar(playerid, "pkrRoomBigBlind");
  461. DeletePVar(playerid, "pkrRoomSmallBlind");
  462. DeletePVar(playerid, "pkrRoomDealer");
  463. DeletePVar(playerid, "pkrCard1");
  464. DeletePVar(playerid, "pkrCard2");
  465. DeletePVar(playerid, "pkrActivePlayer");
  466. DeletePVar(playerid, "pkrTime");
  467. if(GetPVarInt(playerid, "pkrActiveHand")) {
  468. PokerTable[tableid][pkrActiveHands]--;
  469. // Animation
  470. ApplyAnimation(playerid, "CASINO", "cards_out", 4.1, 0, 1, 1, 1, 1, 1);
  471. }
  472. DeletePVar(playerid, "pkrActiveHand");
  473. DeletePVar(playerid, "pkrCurrentBet");
  474. DeletePVar(playerid, "pkrResultString");
  475. DeletePVar(playerid, "pkrHide");
  476. }
  477. }
  478. return 1;
  479. }
  480. ResetPokerTable(tableid)
  481. {
  482. new szString[32];
  483. format(szString, sizeof(szString), "");
  484. strmid(PokerTable[tableid][pkrPass], szString, 0, strlen(szString), 64);
  485. PokerTable[tableid][pkrActive] = 0;
  486. PokerTable[tableid][pkrLimit] = 6;
  487. PokerTable[tableid][pkrBuyInMax] = 1000;
  488. PokerTable[tableid][pkrBuyInMin] = 500;
  489. PokerTable[tableid][pkrBlind] = 100;
  490. PokerTable[tableid][pkrPos] = 0;
  491. PokerTable[tableid][pkrRound] = 0;
  492. PokerTable[tableid][pkrStage] = 0;
  493. PokerTable[tableid][pkrActiveBet] = 0;
  494. PokerTable[tableid][pkrDelay] = 0;
  495. PokerTable[tableid][pkrPot] = 0;
  496. PokerTable[tableid][pkrSetDelay] = 15;
  497. PokerTable[tableid][pkrRotations] = 0;
  498. PokerTable[tableid][pkrSlotRotations] = 0;
  499. PokerTable[tableid][pkrWinnerID] = -1;
  500. PokerTable[tableid][pkrWinners] = 0;
  501. }
  502. ShowPokerGUI(playerid, guitype)
  503. {
  504. switch(guitype)
  505. {
  506. case GUI_POKER_TABLE:
  507. {
  508. SetPVarInt(playerid, "pkrTableGUI", 1);
  509. for(new i = 0; i < MAX_PLAYERPOKERUI; i++) {
  510. PlayerTextDrawShow(playerid, PlayerPokerUI[playerid][i]);
  511. }
  512. }
  513. }
  514. }
  515. DestroyPokerGUI(playerid)
  516. {
  517. for(new i = 0; i < MAX_PLAYERPOKERUI; i++) {
  518. PlayerTextDrawDestroy(playerid, PlayerPokerUI[playerid][i]);
  519. }
  520. }
  521. PlacePokerTable(tableid, skipmisc, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, virtualworld, interior)
  522. {
  523. PokerTable[tableid][pkrPlaced] = 1;
  524. PokerTable[tableid][pkrX] = x;
  525. PokerTable[tableid][pkrY] = y;
  526. PokerTable[tableid][pkrZ] = z;
  527. PokerTable[tableid][pkrRX] = rx;
  528. PokerTable[tableid][pkrRY] = ry;
  529. PokerTable[tableid][pkrRZ] = rz;
  530. PokerTable[tableid][pkrVW] = virtualworld;
  531. PokerTable[tableid][pkrInt] = interior;
  532. // Create Table
  533. PokerTable[tableid][pkrObjectID] = CreateDynamicObject(OBJ_POKER_TABLE, x, y, z, rx, ry, rz, virtualworld, interior, -1, DRAWDISTANCE_POKER_TABLE);
  534. if(skipmisc != 0) {
  535. }
  536. // Create 3D Text Label
  537. new szString[64];
  538. format(szString, sizeof(szString), "Poker Table %d", tableid);
  539. PokerTable[tableid][pkrText3DID] = Create3DTextLabel(szString, COLOR_YELLOW, x, y, z+1.3, DRAWDISTANCE_POKER_MISC, virtualworld, 0);
  540. return tableid;
  541. }
  542. DestroyPokerTable(tableid)
  543. {
  544. if(PokerTable[tableid][pkrPlaced] == 1) {
  545. foreach(new i : Player)
  546. {
  547. if(GetPVarInt(i, "pkrTableID")-1 == tableid)
  548. {
  549. LeavePokerTable(i);
  550. SendClientMessageEx(i, COLOR_YELLOW, "The poker table owner has destroyed the table.");
  551. }
  552. }
  553. // Delete Table
  554. if(IsValidDynamicObject(PokerTable[tableid][pkrObjectID])) DestroyDynamicObject(PokerTable[tableid][pkrObjectID]);
  555. // Delete 3D Text Label
  556. Delete3DTextLabel(PokerTable[tableid][pkrText3DID]);
  557. // Delete Misc Obj
  558. for(new c = 0; c < MAX_POKERTABLEMISCOBJS; c++) {
  559. if(IsValidObject(PokerTable[tableid][pkrMiscObjectID][c])) DestroyObject(PokerTable[tableid][pkrMiscObjectID][c]);
  560. }
  561. }
  562. PokerTable[tableid][pkrX] = 0.0;
  563. PokerTable[tableid][pkrY] = 0.0;
  564. PokerTable[tableid][pkrZ] = 0.0;
  565. PokerTable[tableid][pkrRX] = 0.0;
  566. PokerTable[tableid][pkrRY] = 0.0;
  567. PokerTable[tableid][pkrRZ] = 0.0;
  568. PokerTable[tableid][pkrVW] = 0;
  569. PokerTable[tableid][pkrInt] = 0;
  570. PokerTable[tableid][pkrPlayers] = 0;
  571. PokerTable[tableid][pkrLimit] = 6;
  572. PokerTable[tableid][pkrPlaced] = 0;
  573. return tableid;
  574. }
  575. // Note: 0, 1 should be the hand, the rest are community cards.
  576. AnaylzePokerHand(playerid, Hand[])
  577. {
  578. new pokerArray[7];
  579. for(new i = 0; i < sizeof(pokerArray); i++) {
  580. pokerArray[i] = Hand[i];
  581. }
  582. new suitArray[4][13];
  583. new tmp = 0;
  584. new pairs = 0;
  585. new bool:isRoyalFlush = false;
  586. new bool:isFlush = false;
  587. new bool:isStraight = false;
  588. new bool:isFour = false;
  589. new bool:isThree = false;
  590. new bool:isTwoPair = false;
  591. new bool:isPair = false;
  592. // Convert Hand[] (AKA pokerArray) to suitArray[]
  593. for(new i = 0; i < sizeof(pokerArray); i++) {
  594. if(pokerArray[i] < 13) { // Clubs (0 - 12)
  595. suitArray[0][pokerArray[i]] = 1;
  596. }
  597. if(12 < pokerArray[i] < 26) { // Diamonds (13 - 25)
  598. suitArray[1][pokerArray[i]-13] = 1;
  599. }
  600. if(25 < pokerArray[i] < 39) { // Hearts (26 - 38)
  601. suitArray[2][pokerArray[i]-26] = 1;
  602. }
  603. if(38 < pokerArray[i] < 52) { // Spades (39 - 51)
  604. suitArray[3][pokerArray[i]-39] = 1;
  605. }
  606. }
  607. // Royal Check
  608. for(new i = 0; i < 4; i++) {
  609. if(suitArray[i][8] == 1) { // Must be 8 (?) -> 10, Jack, Queen, King, Ace.
  610. if(suitArray[i][9] == 1) {
  611. if(suitArray[i][10] == 1) {
  612. if(suitArray[i][11] == 1) {
  613. if(suitArray[i][12] == 1) {
  614. isRoyalFlush = true;
  615. break;
  616. }
  617. }
  618. }
  619. }
  620. }
  621. }
  622. tmp = 0;
  623. // Flush Check
  624. for(new i = 0; i < 4; i++) {
  625. for(new j = 0; j < 13; j++) {
  626. if(suitArray[i][j] == 1) {
  627. tmp++;
  628. }
  629. }
  630. if(tmp > 4) {
  631. isFlush = true;
  632. break;
  633. } else {
  634. tmp = 0;
  635. }
  636. }
  637. tmp = 0;
  638. // Four of a Kind Check
  639. // Three of a Kind Check
  640. for(new i = 0; i < 4; i++) {
  641. for(new j = 0; j < 13; j++) {
  642. if(suitArray[i][j] == 1) {
  643. for(new c = 0; c < 4; c++) {
  644. if(suitArray[c][j] == 1) {
  645. tmp++;
  646. }
  647. }
  648. if(tmp == 4) {
  649. isFour = true;
  650. }
  651. else if(tmp == 3) { // if tmp >= 3, then tmp = 4 is also ruled as a Three of a Kind.
  652. isThree = true;
  653. } else {
  654. tmp = 0;
  655. }
  656. }
  657. }
  658. }
  659. tmp = 0;
  660. // Two Pair & Pair Check
  661. for(new j = 0; j < 13; j++) {
  662. tmp = 0;
  663. for(new i = 0; i < 4; i++) {
  664. if(suitArray[i][j] == 1) {
  665. tmp++;
  666. if(tmp >= 2) {
  667. isPair = true;
  668. pairs++;
  669. if(pairs >= 2) {
  670. isTwoPair = true;
  671. }
  672. }
  673. }
  674. }
  675. }
  676. tmp = 0;
  677. // Straight Check
  678. for(new j = 0; j < 13; j++) {
  679. for(new i = 0; i < 4; i++) {
  680. if(suitArray[i][j] == 1) {
  681. for(new s = 0; s < 5; s++) {
  682. for(new c = 0; c < 4; c++) {
  683. if(j+s == 13)
  684. {
  685. if(suitArray[c][0] == 1) {
  686. tmp++;
  687. break;
  688. }
  689. }
  690. else if (j+s >= 14)
  691. {
  692. break;
  693. }
  694. else
  695. {
  696. if(suitArray[c][j+s] == 1) {
  697. tmp++;
  698. break;
  699. }
  700. }
  701. }
  702. }
  703. }
  704. if(tmp >= 5) {
  705. isStraight = true;
  706. }
  707. tmp = 0;
  708. }
  709. }
  710. tmp = 0;
  711. // Convert Hand to Singles
  712. // Card 1
  713. if(pokerArray[0] > 12 && pokerArray[0] < 26) pokerArray[0] -= 13;
  714. if(pokerArray[0] > 25 && pokerArray[0] < 39) pokerArray[0] -= 26;
  715. if(pokerArray[0] > 38 && pokerArray[0] < 52) pokerArray[0] -= 39;
  716. if(pokerArray[0] == 0) pokerArray[0] = 13; // Convert Aces to worth 13.
  717. // Card 2
  718. if(pokerArray[1] > 12 && pokerArray[1] < 26) pokerArray[1] -= 13;
  719. if(pokerArray[1] > 25 && pokerArray[1] < 39) pokerArray[1] -= 26;
  720. if(pokerArray[1] > 38 && pokerArray[1] < 52) pokerArray[1] -= 39;
  721. if(pokerArray[1] == 0) pokerArray[1] = 13; // Convert Aces to worth 13.
  722. // 10) POKER_RESULT_ROYAL_FLUSH - A, K, Q, J, 10 (SAME SUIT) * ROYAL + FLUSH *
  723. if(isRoyalFlush) {
  724. SetPVarString(playerid, "pkrResultString", "Royal Flush");
  725. return 1000 + pokerArray[0] + pokerArray[1];
  726. }
  727. // 9) POKER_RESULT_STRAIGHT_FLUSH - Any five card squence. (SAME SUIT) * STRAIGHT + FLUSH *
  728. if(isStraight && isFlush) {
  729. SetPVarString(playerid, "pkrResultString", "Straight Flush");
  730. return 900 + pokerArray[0] + pokerArray[1];
  731. }
  732. // 8) POKER_RESULT_FOUR_KIND - All four cards of the same rank. * FOUR KIND *
  733. if(isFour) {
  734. SetPVarString(playerid, "pkrResultString", "Four of a Kind");
  735. return 800 + pokerArray[0] + pokerArray[1];
  736. }
  737. // 7) POKER_RESULT_FULL_HOUSE - Three of a kind combined with a pair. * THREE KIND + PAIR *
  738. if(isThree && isTwoPair) {
  739. SetPVarString(playerid, "pkrResultString", "Full House");
  740. return 700 + pokerArray[0] + pokerArray[1];
  741. }
  742. // 6) POKER_RESULT_FLUSH - Any five cards of the same suit, no sequence. * FLUSH *
  743. if(isFlush) {
  744. SetPVarString(playerid, "pkrResultString", "Flush");
  745. return 600 + pokerArray[0] + pokerArray[1];
  746. }
  747. // 5) POKER_RESULT_STRAIGHT - Five cards in sequence, but not in the same suit. * STRAIGHT *
  748. if(isStraight) {
  749. SetPVarString(playerid, "pkrResultString", "Straight");
  750. return 500 + pokerArray[0] + pokerArray[1];
  751. }
  752. // 4) POKER_RESULT_THREE_KIND - Three cards of the same rank. * THREE KIND *
  753. if(isThree) {
  754. SetPVarString(playerid, "pkrResultString", "Three of a Kind");
  755. return 400 + pokerArray[0] + pokerArray[1];
  756. }
  757. // 3) POKER_RESULT_TWO_PAIR - Two seperate pair. * TWO PAIR *
  758. if(isTwoPair) {
  759. SetPVarString(playerid, "pkrResultString", "Two Pair");
  760. return 300 + pokerArray[0] + pokerArray[1];
  761. }
  762. // 2) POKER_RESULT_PAIR - Two cards of the same rank. * PAIR *
  763. if(isPair) {
  764. SetPVarString(playerid, "pkrResultString", "Pair");
  765. return 200 + pokerArray[0] + pokerArray[1];
  766. }
  767. // 1) POKER_RESULT_HIGH_CARD - Highest card.
  768. SetPVarString(playerid, "pkrResultString", "High Card");
  769. return pokerArray[0] + pokerArray[1];
  770. }
  771. forward PokerExit(playerid);
  772. public PokerExit(playerid)
  773. {
  774. SetCameraBehindPlayer(playerid);
  775. TogglePlayerControllable(playerid, 1);
  776. ClearAnimationsEx(playerid);
  777. CancelSelectTextDraw(playerid);
  778. }
  779. forward PokerPulse(tableid);
  780. public PokerPulse(tableid)
  781. {
  782. // Idle Animation Loop & Re-seater
  783. for(new i = 0; i < 6; i++) {
  784. new playerid = PokerTable[tableid][pkrSlot][i];
  785. if(playerid != -1) {
  786. // Disable Weapons
  787. SetPlayerArmedWeapon(playerid,0);
  788. new idleRandom = random(100);
  789. if(idleRandom >= 90) {
  790. SetPlayerPosObjectOffset(PokerTable[tableid][pkrObjectID], playerid, PokerTableMiscObjOffsets[i][0], PokerTableMiscObjOffsets[i][1], PokerTableMiscObjOffsets[i][2]);
  791. SetPlayerFacingAngle(playerid, PokerTableMiscObjOffsets[i][5]+90.0);
  792. SetPlayerInterior(playerid, PokerTable[tableid][pkrInt]);
  793. SetPlayerVirtualWorld(playerid, PokerTable[tableid][pkrVW]);
  794. // Animation
  795. if(GetPVarInt(playerid, "pkrActiveHand")) {
  796. ApplyAnimation(playerid, "CASINO", "cards_loop", 4.1, 0, 1, 1, 1, 1, 1);
  797. }
  798. }
  799. }
  800. }
  801. // 3D Text Label
  802. Update3DTextLabelText(PokerTable[tableid][pkrText3DID], COLOR_YELLOW, " ");
  803. if(PokerTable[tableid][pkrActivePlayers] >= 2 && PokerTable[tableid][pkrActive] == 2) {
  804. // Count the number of active players with more than $0, activate the round if more than 1 gets counted.
  805. new tmpCount = 0;
  806. for(new i = 0; i < 6; i++) {
  807. new playerid = PokerTable[tableid][pkrSlot][i];
  808. if(playerid != -1) {
  809. if(GetPVarInt(playerid, "pkrChips") > 0) {
  810. tmpCount++;
  811. }
  812. }
  813. }
  814. if(tmpCount > 1) {
  815. PokerTable[tableid][pkrActive] = 3;
  816. PokerTable[tableid][pkrDelay] = PokerTable[tableid][pkrSetDelay];
  817. }
  818. }
  819. if(PokerTable[tableid][pkrPlayers] < 2 && PokerTable[tableid][pkrActive] == 3) {
  820. // Pseudo Code (Move Pot towards last player's chip count)
  821. for(new i = 0; i < 6; i++) {
  822. new playerid = PokerTable[tableid][pkrSlot][i];
  823. if(playerid != -1) {
  824. SetPVarInt(playerid, "pkrChips", GetPVarInt(playerid, "pkrChips")+PokerTable[tableid][pkrPot]);
  825. LeavePokerTable(playerid);
  826. ResetPokerTable(tableid);
  827. JoinPokerTable(playerid, tableid);
  828. }
  829. }
  830. }
  831. // Winner Loop
  832. if(PokerTable[tableid][pkrActive] == 4)
  833. {
  834. if(PokerTable[tableid][pkrDelay] == 20) {
  835. new endBetsSoundID[] = {5826, 5827};
  836. new randomEndBetsSoundID = random(sizeof(endBetsSoundID));
  837. GlobalPlaySound(endBetsSoundID[randomEndBetsSoundID], PokerTable[tableid][pkrX], PokerTable[tableid][pkrY], PokerTable[tableid][pkrZ]);
  838. for(new i = 0; i < 6; i++) {
  839. new playerid = PokerTable[tableid][pkrSlot][i];
  840. if(playerid != -1) {
  841. PokerOptions(playerid, 0);
  842. }
  843. }
  844. }
  845. if(PokerTable[tableid][pkrDelay] > 0) {
  846. PokerTable[tableid][pkrDelay]--;
  847. if(PokerTable[tableid][pkrDelay] <= 5 && PokerTable[tableid][pkrDelay] > 0) {
  848. for(new i = 0; i < 6; i++) {
  849. new playerid = PokerTable[tableid][pkrSlot][i];
  850. if(playerid != -1) PlayerPlaySound(playerid, 1139, 0.0, 0.0, 0.0);
  851. }
  852. }
  853. }
  854. if(PokerTable[tableid][pkrDelay] == 0) {
  855. return ResetPokerRound(tableid);
  856. }
  857. if(PokerTable[tableid][pkrDelay] == 19) {
  858. // Anaylze Cards
  859. new resultArray[6];
  860. for(new i = 0; i < 6; i++) {
  861. new playerid = PokerTable[tableid][pkrSlot][i];
  862. new cards[7];
  863. if(playerid != -1) {
  864. if(GetPVarInt(playerid, "pkrActiveHand")) {
  865. cards[0] = GetPVarInt(playerid, "pkrCard1");
  866. cards[1] = GetPVarInt(playerid, "pkrCard2");
  867. new tmp = 0;
  868. for(new c = 2; c < 7; c++) {
  869. cards[c] = PokerTable[tableid][pkrCCards][tmp];
  870. tmp++;
  871. }
  872. SetPVarInt(playerid, "pkrResult", AnaylzePokerHand(playerid, cards));
  873. }
  874. }
  875. }
  876. // Sorting Results (Highest to Lowest)
  877. for(new i = 0; i < 6; i++) {
  878. new playerid = PokerTable[tableid][pkrSlot][i];
  879. if(playerid != -1) {
  880. if(GetPVarInt(playerid, "pkrActiveHand")) {
  881. resultArray[i] = GetPVarInt(playerid, "pkrResult");
  882. }
  883. }
  884. }
  885. BubbleSort(resultArray, sizeof(resultArray));
  886. // Determine Winner(s)
  887. for(new i = 0; i < 6; i++) {
  888. if(resultArray[5] == resultArray[i])
  889. PokerTable[tableid][pkrWinners]++;
  890. }
  891. // Notify Table of Winner & Give Rewards
  892. for(new i = 0; i < 6; i++) {
  893. new playerid = PokerTable[tableid][pkrSlot][i];
  894. if(playerid != -1) {
  895. if(PokerTable[tableid][pkrWinners] > 1) {
  896. // Split
  897. if(resultArray[5] == GetPVarInt(playerid, "pkrResult")) {
  898. new splitpot = PokerTable[tableid][pkrPot]/PokerTable[tableid][pkrWinners];
  899. SetPVarInt(playerid, "pkrWinner", 1);
  900. SetPVarInt(playerid, "pkrChips", GetPVarInt(playerid, "pkrChips")+splitpot);
  901. PlayerPlaySound(playerid, 5821, 0.0, 0.0, 0.0);
  902. } else {
  903. PlayerPlaySound(playerid, 31202, 0.0, 0.0, 0.0);
  904. }
  905. } else {
  906. // Single Winner
  907. if(resultArray[5] == GetPVarInt(playerid, "pkrResult")) {
  908. SetPVarInt(playerid, "pkrWinner", 1);
  909. SetPVarInt(playerid, "pkrChips", GetPVarInt(playerid, "pkrChips")+PokerTable[tableid][pkrPot]);
  910. PokerTable[tableid][pkrWinnerID] = playerid;
  911. new winnerSoundID[] = {5847, 5848, 5849, 5854, 5855, 5856};
  912. new randomWinnerSoundID = random(sizeof(winnerSoundID));
  913. PlayerPlaySound(playerid, winnerSoundID[randomWinnerSoundID], 0.0, 0.0, 0.0);
  914. } else {
  915. PlayerPlaySound(playerid, 31202, 0.0, 0.0, 0.0);
  916. }
  917. }
  918. }
  919. }
  920. }
  921. }
  922. // Game Loop
  923. if(PokerTable[tableid][pkrActive] == 3)
  924. {
  925. if(PokerTable[tableid][pkrActiveHands] == 1 && PokerTable[tableid][pkrRound] == 1) {
  926. PokerTable[tableid][pkrStage] = 0;
  927. PokerTable[tableid][pkrActive] = 4;
  928. PokerTable[tableid][pkrDelay] = 20+1;
  929. for(new i = 0; i < 6; i++) {
  930. new playerid = PokerTable[tableid][pkrSlot][i];
  931. if(playerid != -1) {
  932. if(GetPVarInt(playerid, "pkrActiveHand")) {
  933. SetPVarInt(playerid, "pkrHide", 1);
  934. }
  935. }
  936. }
  937. }
  938. // Delay Time Controller
  939. if(PokerTable[tableid][pkrDelay] > 0) {
  940. PokerTable[tableid][pkrDelay]--;
  941. if(PokerTable[tableid][pkrDelay] <= 5 && PokerTable[tableid][pkrDelay] > 0) {
  942. for(new i = 0; i < 6; i++) {
  943. new playerid = PokerTable[tableid][pkrSlot][i];
  944. if(playerid != -1) PlayerPlaySound(playerid, 1139, 0.0, 0.0, 0.0);
  945. }
  946. }
  947. }
  948. // Assign Blinds & Active Player
  949. if(PokerTable[tableid][pkrRound] == 0 && PokerTable[tableid][pkrDelay] == 5)
  950. {
  951. for(new i = 0; i < 6; i++) {
  952. new playerid = PokerTable[tableid][pkrSlot][i];
  953. if(playerid != -1) {
  954. SetPVarInt(playerid, "pkrStatus", 1);
  955. }
  956. }
  957. PokerAssignBlinds(tableid);
  958. }
  959. // If no round active, start it.
  960. if(PokerTable[tableid][pkrRound] == 0 && PokerTable[tableid][pkrDelay] == 0)
  961. {
  962. PokerTable[tableid][pkrRound] = 1;
  963. for(new i = 0; i < 6; i++) {
  964. new playerid = PokerTable[tableid][pkrSlot][i];
  965. if(playerid != -1) {
  966. SetPVarString(playerid, "pkrStatusString", " ");
  967. }
  968. }
  969. // Shuffle Deck & Deal Cards & Allocate Community Cards
  970. PokerShuffleDeck(tableid);
  971. PokerDealHands(tableid);
  972. PokerRotateActivePlayer(tableid);
  973. }
  974. // Round Logic
  975. // Time Controller
  976. for(new i = 0; i < 6; i++) {
  977. new playerid = PokerTable[tableid][pkrSlot][i];
  978. if(playerid != -1) {
  979. if(GetPVarInt(playerid, "pkrActivePlayer")) {
  980. SetPVarInt(playerid, "pkrTime", GetPVarInt(playerid, "pkrTime")-1);
  981. if(GetPVarInt(playerid, "pkrTime") == 0) {
  982. new name[24];
  983. GetPlayerName(playerid, name, sizeof(name));
  984. if(GetPVarInt(playerid, "pkrActionChoice")) {
  985. DeletePVar(playerid, "pkrActionChoice");
  986. ShowPlayerDialogEx(playerid, -1, DIALOG_STYLE_LIST, "Close", "Close", "Close", "Close");
  987. }
  988. PokerFoldHand(playerid);
  989. PokerRotateActivePlayer(tableid);
  990. }
  991. }
  992. }
  993. }
  994. }
  995. // Update GUI
  996. for(new i = 0; i < 6; i++) {
  997. new playerid = PokerTable[tableid][pkrSlot][i];
  998. new tmp, tmpString[128];
  999. // Set Textdraw Offset
  1000. switch(i)
  1001. {
  1002. case 0: { tmp = 0; }
  1003. case 1: { tmp = 5; }
  1004. case 2: { tmp = 10; }
  1005. case 3: { tmp = 15; }
  1006. case 4: { tmp = 20; }
  1007. case 5: { tmp = 25; }
  1008. }
  1009. if(playerid != -1) {
  1010. // Debug
  1011. /* new string[512];
  1012. format(string, sizeof(string), "Debug:~n~pkrActive: %d~n~pkrPlayers: %d~n~pkrActivePlayers: %d~n~pkrActiveHands: %d~n~pkrPos: %d~n~pkrDelay: %d~n~pkrRound: %d~n~pkrStage: %d~n~pkrActiveBet: %d~n~pkrRotations: %d",
  1013. PokerTable[tableid][pkrActive],
  1014. PokerTable[tableid][pkrPlayers],
  1015. PokerTable[tableid][pkrActivePlayers],
  1016. PokerTable[tableid][pkrActiveHands],
  1017. PokerTable[tableid][pkrPos],
  1018. PokerTable[tableid][pkrDelay],
  1019. PokerTable[tableid][pkrRound],
  1020. PokerTable[tableid][pkrStage],
  1021. PokerTable[tableid][pkrActiveBet],
  1022. PokerTable[tableid][pkrRotations]
  1023. );
  1024. format(string, sizeof(string), "%s~n~----------~n~", string);
  1025. new sstring[128];
  1026. GetPVarString(playerid, "pkrStatusString", sstring, 128);
  1027. format(string, sizeof(string), "%spkrTableID: %d~n~pkrCurrentBet: %d~n~pkrStatus: %d~n~pkrRoomLeader: %d~n~pkrRoomBigBlind: %d~n~pkrRoomSmallBlind: %d~n~pkrRoomDealer: %d~n~pkrActivePlayer: %d~n~pkrActiveHand: %d~n~pkrStatusString: %s",
  1028. string,
  1029. GetPVarInt(playerid, "pkrTableID")-1,
  1030. GetPVarInt(playerid, "pkrCurrentBet"),
  1031. GetPVarInt(playerid, "pkrStatus"),
  1032. GetPVarInt(playerid, "pkrRoomLeader"),
  1033. GetPVarInt(playerid, "pkrRoomBigBlind"),
  1034. GetPVarInt(playerid, "pkrRoomSmallBlind"),
  1035. GetPVarInt(playerid, "pkrRoomDealer"),
  1036. GetPVarInt(playerid, "pkrActivePlayer"),
  1037. GetPVarInt(playerid, "pkrActiveHand"),
  1038. sstring
  1039. );
  1040. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][45], string); */
  1041. // Name
  1042. new name[MAX_PLAYER_NAME+1];
  1043. GetPlayerName(playerid, name, sizeof(name));
  1044. for(new td = 0; td < 6; td++) {
  1045. new pid = PokerTable[tableid][pkrSlot][td];
  1046. if(pid != -1) PlayerTextDrawSetString(pid, PlayerPokerUI[pid][0+tmp], name);
  1047. }
  1048. // Chips
  1049. if(GetPVarInt(playerid, "pkrChips") > 0) {
  1050. format(tmpString, sizeof(tmpString), "$%d", GetPVarInt(playerid, "pkrChips"));
  1051. } else {
  1052. format(tmpString, sizeof(tmpString), "~r~$%d", GetPVarInt(playerid, "pkrChips"));
  1053. }
  1054. for(new td = 0; td < 6; td++) {
  1055. new pid = PokerTable[tableid][pkrSlot][td];
  1056. if(pid != -1) PlayerTextDrawSetString(pid, PlayerPokerUI[pid][1+tmp], tmpString);
  1057. }
  1058. // Cards
  1059. for(new td = 0; td < 6; td++) {
  1060. new pid = PokerTable[tableid][pkrSlot][td];
  1061. if(pid != -1) {
  1062. if(GetPVarInt(playerid, "pkrActiveHand")) {
  1063. if(playerid != pid) {
  1064. if(PokerTable[tableid][pkrActive] == 4 && PokerTable[tableid][pkrDelay] <= 19 && GetPVarInt(playerid, "pkrHide") != 1) {
  1065. format(tmpString, sizeof(tmpString), "%s", DeckTextdrw[GetPVarInt(playerid, "pkrCard1")+1]);
  1066. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][2+tmp], tmpString);
  1067. format(tmpString, sizeof(tmpString), "%s", DeckTextdrw[GetPVarInt(playerid, "pkrCard2")+1]);
  1068. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][3+tmp], tmpString);
  1069. } else {
  1070. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][2+tmp], DeckTextdrw[0]);
  1071. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][3+tmp], DeckTextdrw[0]);
  1072. }
  1073. } else {
  1074. format(tmpString, sizeof(tmpString), "%s", DeckTextdrw[GetPVarInt(playerid, "pkrCard1")+1]);
  1075. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][2+tmp], tmpString);
  1076. format(tmpString, sizeof(tmpString), "%s", DeckTextdrw[GetPVarInt(playerid, "pkrCard2")+1]);
  1077. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][3+tmp], tmpString);
  1078. }
  1079. } else {
  1080. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][2+tmp], " ");
  1081. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][3+tmp], " ");
  1082. }
  1083. }
  1084. }
  1085. // Status
  1086. if(PokerTable[tableid][pkrActive] < 3) {
  1087. format(tmpString, sizeof(tmpString), " ");
  1088. } else if(GetPVarInt(playerid, "pkrActivePlayer") && PokerTable[tableid][pkrActive] == 3) {
  1089. format(tmpString, sizeof(tmpString), "0:%d", GetPVarInt(playerid, "pkrTime"));
  1090. } else {
  1091. if(PokerTable[tableid][pkrActive] == 3 && PokerTable[tableid][pkrDelay] > 5) {
  1092. SetPVarString(playerid, "pkrStatusString", " ");
  1093. }
  1094. if(PokerTable[tableid][pkrActive] == 4 && PokerTable[tableid][pkrDelay] == 19) {
  1095. if(PokerTable[tableid][pkrWinners] == 1) {
  1096. if(GetPVarInt(playerid, "pkrWinner")) {
  1097. format(tmpString, sizeof(tmpString), "+$%d", PokerTable[tableid][pkrPot]);
  1098. SetPVarString(playerid, "pkrStatusString", tmpString);
  1099. } else {
  1100. format(tmpString, sizeof(tmpString), "-$%d", GetPVarInt(playerid, "pkrCurrentBet"));
  1101. SetPVarString(playerid, "pkrStatusString", tmpString);
  1102. }
  1103. } else {
  1104. if(GetPVarInt(playerid, "pkrWinner")) {
  1105. new splitpot = PokerTable[tableid][pkrPot]/PokerTable[tableid][pkrWinners];
  1106. format(tmpString, sizeof(tmpString), "+$%d", splitpot);
  1107. SetPVarString(playerid, "pkrStatusString", tmpString);
  1108. } else {
  1109. format(tmpString, sizeof(tmpString), "-$%d", GetPVarInt(playerid, "pkrCurrentBet"));
  1110. SetPVarString(playerid, "pkrStatusString", tmpString);
  1111. }
  1112. }
  1113. }
  1114. if(PokerTable[tableid][pkrActive] == 4 && PokerTable[tableid][pkrDelay] == 19) {
  1115. if(GetPVarInt(playerid, "pkrActiveHand") && GetPVarInt(playerid, "pkrHide") != 1) {
  1116. new resultString[64];
  1117. GetPVarString(playerid, "pkrResultString", resultString, 64);
  1118. format(tmpString, sizeof(tmpString), "%s", resultString);
  1119. SetPVarString(playerid, "pkrStatusString", resultString);
  1120. }
  1121. }
  1122. if(PokerTable[tableid][pkrActive] == 4 && PokerTable[tableid][pkrDelay] == 10) {
  1123. if(PokerTable[tableid][pkrWinners] == 1) {
  1124. if(GetPVarInt(playerid, "pkrWinner")) {
  1125. format(tmpString, sizeof(tmpString), "+$%d", PokerTable[tableid][pkrPot]);
  1126. SetPVarString(playerid, "pkrStatusString", tmpString);
  1127. } else {
  1128. format(tmpString, sizeof(tmpString), "-$%d", GetPVarInt(playerid, "pkrCurrentBet"));
  1129. SetPVarString(playerid, "pkrStatusString", tmpString);
  1130. }
  1131. } else {
  1132. if(GetPVarInt(playerid, "pkrWinner")) {
  1133. new splitpot = PokerTable[tableid][pkrPot]/PokerTable[tableid][pkrWinners];
  1134. format(tmpString, sizeof(tmpString), "+$%d", splitpot);
  1135. SetPVarString(playerid, "pkrStatusString", tmpString);
  1136. } else {
  1137. format(tmpString, sizeof(tmpString), "-$%d", GetPVarInt(playerid, "pkrCurrentBet"));
  1138. SetPVarString(playerid, "pkrStatusString", tmpString);
  1139. }
  1140. }
  1141. }
  1142. GetPVarString(playerid, "pkrStatusString", tmpString, 128);
  1143. }
  1144. for(new td = 0; td < 6; td++) {
  1145. new pid = PokerTable[tableid][pkrSlot][td];
  1146. if(pid != -1) PlayerTextDrawSetString(pid, PlayerPokerUI[pid][4+tmp], tmpString);
  1147. }
  1148. // Pot
  1149. if(PokerTable[tableid][pkrDelay] > 0 && PokerTable[tableid][pkrActive] == 3) {
  1150. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][37], "Texas Holdem Poker");
  1151. } else if(PokerTable[tableid][pkrActive] == 2) {
  1152. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][37], "Texas Holdem Poker");
  1153. } else if(PokerTable[tableid][pkrActive] == 3) {
  1154. format(tmpString, sizeof(tmpString), "Pot: $%d", PokerTable[tableid][pkrPot]);
  1155. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][37], tmpString);
  1156. } else if(PokerTable[tableid][pkrActive] == 4 && PokerTable[tableid][pkrDelay] < 19) {
  1157. if(PokerTable[tableid][pkrWinnerID] != -1) {
  1158. new winnerName[24];
  1159. GetPlayerName(PokerTable[tableid][pkrWinnerID], winnerName, sizeof(winnerName));
  1160. format(tmpString, sizeof(tmpString), "%s Won $%d", winnerName, PokerTable[tableid][pkrPot]);
  1161. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][37], tmpString);
  1162. } else if(PokerTable[tableid][pkrWinners] > 1) {
  1163. new splitpot = PokerTable[tableid][pkrPot]/PokerTable[tableid][pkrWinners];
  1164. format(tmpString, sizeof(tmpString), "%d Winners Won $%d", PokerTable[tableid][pkrWinners], splitpot);
  1165. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][37], tmpString);
  1166. }
  1167. } else {
  1168. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][37], "Texas Holdem Poker");
  1169. }
  1170. // Bet
  1171. if(PokerTable[tableid][pkrDelay] > 0 && PokerTable[tableid][pkrActive] == 3) {
  1172. format(tmpString, sizeof(tmpString), "Round Begins in ~r~%d~w~...", PokerTable[tableid][pkrDelay]);
  1173. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][46], tmpString);
  1174. } else if(PokerTable[tableid][pkrActive] == 2) {
  1175. format(tmpString, sizeof(tmpString), "Waiting for players...", PokerTable[tableid][pkrPot]);
  1176. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][46], tmpString);
  1177. } else if(PokerTable[tableid][pkrActive] == 3) {
  1178. format(tmpString, sizeof(tmpString), "Bet: $%d", PokerTable[tableid][pkrActiveBet]);
  1179. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][46], tmpString);
  1180. } else if(PokerTable[tableid][pkrActive] == 4) {
  1181. format(tmpString, sizeof(tmpString), "Round Ends in ~r~%d~w~...", PokerTable[tableid][pkrDelay]);
  1182. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][46], tmpString);
  1183. } else {
  1184. if(playerid != -1) PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][46], "Texas Holdem Poker");
  1185. }
  1186. // Community Cards
  1187. switch(PokerTable[tableid][pkrStage]) {
  1188. case 0: // Opening
  1189. {
  1190. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][31], "LD_CARD:cdback");
  1191. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][32], "LD_CARD:cdback");
  1192. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][33], "LD_CARD:cdback");
  1193. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][34], "LD_CARD:cdback");
  1194. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][35], "LD_CARD:cdback");
  1195. }
  1196. case 1: // Flop
  1197. {
  1198. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][31], DeckTextdrw[PokerTable[tableid][pkrCCards][0]+1]);
  1199. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][32], DeckTextdrw[PokerTable[tableid][pkrCCards][1]+1]);
  1200. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][33], DeckTextdrw[PokerTable[tableid][pkrCCards][2]+1]);
  1201. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][34], "LD_CARD:cdback");
  1202. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][35], "LD_CARD:cdback");
  1203. }
  1204. case 2: // Turn
  1205. {
  1206. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][31], DeckTextdrw[PokerTable[tableid][pkrCCards][0]+1]);
  1207. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][32], DeckTextdrw[PokerTable[tableid][pkrCCards][1]+1]);
  1208. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][33], DeckTextdrw[PokerTable[tableid][pkrCCards][2]+1]);
  1209. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][34], DeckTextdrw[PokerTable[tableid][pkrCCards][3]+1]);
  1210. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][35], "LD_CARD:cdback");
  1211. }
  1212. case 3: // River
  1213. {
  1214. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][31], DeckTextdrw[PokerTable[tableid][pkrCCards][0]+1]);
  1215. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][32], DeckTextdrw[PokerTable[tableid][pkrCCards][1]+1]);
  1216. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][33], DeckTextdrw[PokerTable[tableid][pkrCCards][2]+1]);
  1217. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][34], DeckTextdrw[PokerTable[tableid][pkrCCards][3]+1]);
  1218. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][35], DeckTextdrw[PokerTable[tableid][pkrCCards][4]+1]);
  1219. }
  1220. case 4: // Win
  1221. {
  1222. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][31], DeckTextdrw[PokerTable[tableid][pkrCCards][0]+1]);
  1223. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][32], DeckTextdrw[PokerTable[tableid][pkrCCards][1]+1]);
  1224. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][33], DeckTextdrw[PokerTable[tableid][pkrCCards][2]+1]);
  1225. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][34], DeckTextdrw[PokerTable[tableid][pkrCCards][3]+1]);
  1226. PlayerTextDrawSetString(playerid, PlayerPokerUI[playerid][35], DeckTextdrw[PokerTable[tableid][pkrCCards][4]+1]);
  1227. }
  1228. }
  1229. } else {
  1230. for(new td = 0; td < 6; td++) {
  1231. new pid = PokerTable[tableid][pkrSlot][td];
  1232. if(pid != -1) {
  1233. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][0+tmp], " ");
  1234. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][1+tmp], " ");
  1235. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][2+tmp], " ");
  1236. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][3+tmp], " ");
  1237. PlayerTextDrawSetString(pid, PlayerPokerUI[pid][4+tmp], " ");
  1238. }
  1239. }
  1240. }
  1241. }
  1242. return 1;
  1243. }
  1244. ShowCasinoGamesMenu(playerid, dialogid)
  1245. {
  1246. switch(dialogid)
  1247. {
  1248. case DIALOG_CGAMESCALLPOKER: {
  1249. if(GetPVarInt(playerid, "pkrChips") > 0) {
  1250. SetPVarInt(playerid, "pkrActionChoice", 1);
  1251. new tableid = GetPVarInt(playerid, "pkrTableID")-1;
  1252. new actualBet = PokerTable[tableid][pkrActiveBet]-GetPVarInt(playerid, "pkrCurrentBet");
  1253. if(actualBet > GetPVarInt(playerid, "pkrChips")) {
  1254. format(szMiscArray, sizeof(szMiscArray), "{FFFFFF}Are you sure you want to call $%s (All-In)?:", number_format(actualBet));
  1255. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESCALLPOKER, DIALOG_STYLE_MSGBOX, "{FFFFFF}Texas Holdem Poker - (Call)", szMiscArray, "All-In", "Cancel");
  1256. }
  1257. format(szMiscArray, sizeof(szMiscArray), "{FFFFFF}Are you sure you want to call $%s?:", number_format(actualBet));
  1258. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESCALLPOKER, DIALOG_STYLE_MSGBOX, "{FFFFFF}Texas Holdem Poker - (Call)", szMiscArray, "Call", "Cancel");
  1259. } else {
  1260. SendClientMessage(playerid, COLOR_WHITE, "DEALER: You do not have enough funds to call.");
  1261. new noFundsSoundID[] = {5823, 5824, 5825};
  1262. new randomNoFundsSoundID = random(sizeof(noFundsSoundID));
  1263. PlayerPlaySound(playerid, noFundsSoundID[randomNoFundsSoundID], 0.0, 0.0, 0.0);
  1264. }
  1265. }
  1266. case DIALOG_CGAMESRAISEPOKER: {
  1267. new tableid = GetPVarInt(playerid, "pkrTableID")-1;
  1268. SetPVarInt(playerid, "pkrActionChoice", 1);
  1269. if(GetPVarInt(playerid, "pkrCurrentBet")+GetPVarInt(playerid, "pkrChips") > PokerTable[tableid][pkrActiveBet]+PokerTable[tableid][pkrBlind]/2) {
  1270. SetPVarInt(playerid, "pkrActionChoice", 1);
  1271. format(szMiscArray, sizeof(szMiscArray), "{FFFFFF}How much do you want to Raise? ($%d-$%d):", PokerTable[tableid][pkrActiveBet]+PokerTable[tableid][pkrBlind]/2, GetPVarInt(playerid, "pkrCurrentBet")+GetPVarInt(playerid, "pkrChips"));
  1272. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESRAISEPOKER, DIALOG_STYLE_INPUT, "{FFFFFF}Texas Holdem Poker - (Raise)", szMiscArray, "Raise", "Cancel");
  1273. } else if(GetPVarInt(playerid, "pkrCurrentBet")+GetPVarInt(playerid, "pkrChips") == PokerTable[tableid][pkrActiveBet]+PokerTable[tableid][pkrBlind]/2) {
  1274. SetPVarInt(playerid, "pkrActionChoice", 1);
  1275. format(szMiscArray, sizeof(szMiscArray), "{FFFFFF}How much do you want to Raise? (All-In):", PokerTable[tableid][pkrActiveBet]+PokerTable[tableid][pkrBlind]/2, GetPVarInt(playerid, "pkrCurrentBet")+GetPVarInt(playerid, "pkrChips"));
  1276. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESRAISEPOKER, DIALOG_STYLE_INPUT, "{FFFFFF}Texas Holdem Poker - (Raise)", szMiscArray, "All-In", "Cancel");
  1277. } else {
  1278. SendClientMessage(playerid, COLOR_WHITE, "DEALER: You do not have enough funds to raise.");
  1279. new noFundsSoundID[] = {5823, 5824, 5825};
  1280. new randomNoFundsSoundID = random(sizeof(noFundsSoundID));
  1281. PlayerPlaySound(playerid, noFundsSoundID[randomNoFundsSoundID], 0.0, 0.0, 0.0);
  1282. }
  1283. }
  1284. case DIALOG_CGAMESBUYINPOKER: {
  1285. format(szMiscArray, sizeof(szMiscArray), "{FFFFFF}Please input a buy-in amount for the table:\n\nCurrent Casino Chips: {00FF00}$%d{FFFFFF}\nCurrent Poker Chips: {00FF00}$%d{FFFFFF}\nBuy-In Maximum/Minimum: {00FF00}$%d{FFFFFF}/{00FF00}$%d{FFFFFF}", GetPlayerCash(playerid), GetPVarInt(playerid, "pkrChips"), PokerTable[GetPVarInt(playerid, "pkrTableID")-1][pkrBuyInMax], PokerTable[GetPVarInt(playerid, "pkrTableID")-1][pkrBuyInMin]);
  1286. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESBUYINPOKER, DIALOG_STYLE_INPUT, "{FFFFFF}Casino Games - (BuyIn Menu)", szMiscArray, "Buy In", "Leave");
  1287. }
  1288. case DIALOG_CGAMESADMINMENU: {
  1289. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESADMINMENU, DIALOG_STYLE_LIST, "{FFFFFF}Casino Games - (Admin Menu)", "{FFFFFF}Setup Poker Minigame...\nLine2\nCredits", "Select", "Close");
  1290. }
  1291. case DIALOG_CGAMESSELECTPOKER: {
  1292. szMiscArray[0] = 0;
  1293. new szPlaced[64];
  1294. for(new i = 0; i < MAX_POKERTABLES; i++) {
  1295. if(PokerTable[i][pkrPlaced] == 1) { format(szPlaced, sizeof(szPlaced), "{00FF00}Active{FFFFFF}"); }
  1296. if(PokerTable[i][pkrPlaced] == 0) { format(szPlaced, sizeof(szPlaced), "{FF0000}Deactived{FFFFFF}"); }
  1297. format(szMiscArray, sizeof(szMiscArray), "%sPoker Table %d (%s)\n", szMiscArray, i, szPlaced, PokerTable[i][pkrPlayers]);
  1298. }
  1299. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSELECTPOKER, DIALOG_STYLE_LIST, "Casino Games - (Select Poker Table)", szMiscArray, "Select", "Back");
  1300. }
  1301. case DIALOG_CGAMESSETUPPOKER: {
  1302. new tableid = GetPVarInt(playerid, "tmpEditPokerTableID")-1;
  1303. if(PokerTable[tableid][pkrPlaced] == 0) {
  1304. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSETUPPOKER, DIALOG_STYLE_LIST, "{FFFFFF}Casino Games - (Setup Poker Minigame)", "{FFFFFF}Place Table...", "Select", "Back");
  1305. } else {
  1306. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSETUPPOKER, DIALOG_STYLE_LIST, "{FFFFFF}Casino Games - (Setup Poker Minigame)", "{FFFFFF}Edit Table...\nDelete Table...", "Select", "Back");
  1307. }
  1308. }
  1309. case DIALOG_CGAMESCREDITS: {
  1310. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESCREDITS, DIALOG_STYLE_MSGBOX, "{FFFFFF}Casino Games - (Credits)", "{FFFFFF}Developed By: Dan 'GhoulSlayeR' Reed", "Back", "");
  1311. }
  1312. case DIALOG_CGAMESSETUPPGAME: {
  1313. new tableid = GetPVarInt(playerid, "pkrTableID")-1;
  1314. if(GetPVarType(playerid, "pkrTableID")) {
  1315. new szString[512];
  1316. if(PokerTable[tableid][pkrPass][0] == EOS) {
  1317. format(szString, sizeof(szString), "{FFFFFF}Buy-In Max\t({00FF00}$%d{FFFFFF})\nBuy-In Min\t({00FF00}$%d{FFFFFF})\nBlind\t\t({00FF00}$%d{FFFFFF} / {00FF00}$%d{FFFFFF})\nLimit\t\t(%d)\nPassword\t(%s)\nRound Delay\t(%d)\nStart Game",
  1318. PokerTable[tableid][pkrBuyInMax],
  1319. PokerTable[tableid][pkrBuyInMin],
  1320. PokerTable[tableid][pkrBlind],
  1321. PokerTable[tableid][pkrBlind]/2,
  1322. PokerTable[tableid][pkrLimit],
  1323. "None",
  1324. PokerTable[tableid][pkrSetDelay]
  1325. );
  1326. } else {
  1327. format(szString, sizeof(szString), "{FFFFFF}Buy-In Max\t({00FF00}$%d{FFFFFF})\nBuy-In Min\t({00FF00}$%d{FFFFFF})\nBlind\t\t({00FF00}$%d{FFFFFF} / {00FF00}$%d{FFFFFF})\nLimit\t\t(%d)\nPassword\t(%s)\nRound Delay\t(%d)\nStart Game",
  1328. PokerTable[tableid][pkrBuyInMax],
  1329. PokerTable[tableid][pkrBuyInMin],
  1330. PokerTable[tableid][pkrBlind],
  1331. PokerTable[tableid][pkrBlind]/2,
  1332. PokerTable[tableid][pkrLimit],
  1333. PokerTable[tableid][pkrPass],
  1334. PokerTable[tableid][pkrSetDelay]
  1335. );
  1336. }
  1337. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSETUPPGAME, DIALOG_STYLE_LIST, "{FFFFFF}Casino Games - (Setup Poker Room)", szString, "Select", "Quit");
  1338. }
  1339. }
  1340. case DIALOG_CGAMESSETUPPGAME2:
  1341. {
  1342. if(GetPVarType(playerid, "pkrTableID")) {
  1343. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSETUPPGAME2, DIALOG_STYLE_INPUT, "{FFFFFF}Casino Games - (Buy-In Max)", "{FFFFFF}Please input a Buy-In Max:", "Change", "Back");
  1344. }
  1345. }
  1346. case DIALOG_CGAMESSETUPPGAME3:
  1347. {
  1348. if(GetPVarType(playerid, "pkrTableID")) {
  1349. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSETUPPGAME3, DIALOG_STYLE_INPUT, "{FFFFFF}Casino Games - (Buy-In Min)", "{FFFFFF}Please input a Buy-In Min:", "Change", "Back");
  1350. }
  1351. }
  1352. case DIALOG_CGAMESSETUPPGAME4:
  1353. {
  1354. if(GetPVarType(playerid, "pkrTableID")) {
  1355. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSETUPPGAME4, DIALOG_STYLE_INPUT, "{FFFFFF}Casino Games - (Blinds)", "{FFFFFF}Please input Blinds:\n\nNote: Small blinds are automatically half of a big blind.", "Change", "Back");
  1356. }
  1357. }
  1358. case DIALOG_CGAMESSETUPPGAME5:
  1359. {
  1360. if(GetPVarType(playerid, "pkrTableID")) {
  1361. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSETUPPGAME5, DIALOG_STYLE_INPUT, "{FFFFFF}Casino Games - (Limit)", "{FFFFFF}Please input a Player Limit (2-6):", "Change", "Back");
  1362. }
  1363. }
  1364. case DIALOG_CGAMESSETUPPGAME6:
  1365. {
  1366. if(GetPVarType(playerid, "pkrTableID")) {
  1367. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSETUPPGAME6, DIALOG_STYLE_INPUT, "{FFFFFF}Casino Games - (Password)", "{FFFFFF}Please input a Password:\n\nNote: Leave blank to have a public room", "Change", "Back");
  1368. }
  1369. }
  1370. case DIALOG_CGAMESSETUPPGAME7:
  1371. {
  1372. if(GetPVarType(playerid, "pkrTableID")) {
  1373. return ShowPlayerDialogEx(playerid, DIALOG_CGAMESSETUPPGAME7, DIALOG_STYLE_INPUT, "{FFFFFF}Casino Games - (Round Delay)", "{FFFFFF}Please input a Round Delay (15-120sec):", "Change", "Back");
  1374. }
  1375. }
  1376. }
  1377. return 1;
  1378. }
  1379. JoinPokerTable(playerid, tableid) {
  1380. // Check if there is room for the player
  1381. if(PokerTable[tableid][pkrPlayers] < PokerTable[tableid][pkrLimit]) {
  1382. // Check if table is not joinable.
  1383. if(PokerTable[tableid][pkrActive] == 1) {
  1384. SendClientMessage(playerid, COLOR_WHITE, "Someone is setting up this table, try again later.");
  1385. return 1;
  1386. }
  1387. // Find an open seat
  1388. for(new s; s < 6; s++) {
  1389. if(PokerTable[tableid][pkrSlot][s] == -1) {
  1390. SetPVarInt(playerid, "pkrTableID", tableid+1);
  1391. SetPVarInt(playerid, "pkrSlot", s);
  1392. // Occuply Slot
  1393. PokerTable[tableid][pkrPlayers] += 1;
  1394. PokerTable[tableid][pkrSlot][s] = playerid;
  1395. // Check & Start Game Loop if Not Active
  1396. if(PokerTable[tableid][pkrPlayers] == 1) {
  1397. // Player is Room Creator
  1398. SetPVarInt(playerid, "pkrRoomLeader", 1);
  1399. ShowCasinoGamesMenu(playerid, DIALOG_CGAMESSETUPPGAME);
  1400. PokerTable[tableid][pkrActive] = 1; // Warmup Phase
  1401. PokerTable[tableid][pkrPulseTimer] = SetTimerEx("PokerPulse", 1000, true, "i", tableid);
  1402. //PokerPulse(tableid);
  1403. } else { // Execute code for Non-Room Creators
  1404. ShowCasinoGamesMenu(playerid, DIALOG_CGAMESBUYINPOKER);
  1405. SelectTextDraw(playerid, COLOR_YELLOW);
  1406. }
  1407. CameraRadiusSetPos(playerid, PokerTable[tableid][pkrX], PokerTable[tableid][pkrY], PokerTable[tableid][pkrZ], 90.0, 4.7, 0.1);
  1408. new Float:tmpPos[3];
  1409. GetPlayerPos(playerid, tmpPos[0], tmpPos[1], tmpPos[2]);
  1410. SetPlayerInterior(playerid, PokerTable[tableid][pkrInt]);
  1411. SetPlayerVirtualWorld(playerid, PokerTable[tableid][pkrVW]);
  1412. SetPVarFloat(playerid, "pkrTableJoinX", tmpPos[0]);
  1413. SetPVarFloat(playerid, "pkrTableJoinY", tmpPos[1]);
  1414. SetPVarFloat(playerid, "pkrTableJoinZ", tmpPos[2]);
  1415. new string[128];
  1416. format(string, sizeof(string), "%s(%d) (IP:%s) has joined poker table (%d)", GetPlayerNameEx(playerid), GetPlayerSQLId(playerid), GetPlayerIpEx(playerid), tableid);
  1417. Log("logs/poker.log", string);
  1418. ApplyAnimation(playerid, "CASINO", "cards_out", 4.1, 0, 1, 1, 1, 1, 1);
  1419. TogglePlayerControllable(playerid, 0);
  1420. SetPlayerPosObjectOffset(PokerTable[tableid][pkrObjectID], playerid, PokerTableMiscObjOffsets[s][0], PokerTableMiscObjOffsets[s][1], PokerTableMiscObjOffsets[s][2]);
  1421. SetPlayerFacingAngle(playerid, PokerTableMiscObjOffsets[s][5]+90.0);
  1422. ApplyAnimation(playerid, "CASINO", "cards_out", 4.1, 0, 1, 1, 1, 1, 1);
  1423. // Create GUI
  1424. CreatePokerGUI(playerid);
  1425. ShowPokerGUI(playerid, GUI_POKER_TABLE);
  1426. // Hide Action Bar
  1427. PokerOptions(playerid, 0);
  1428. return 1;
  1429. }
  1430. }
  1431. }
  1432. return 1;
  1433. }
  1434. LeavePokerTable(playerid) {
  1435. new tableid = GetPVarInt(playerid, "pkrTableID")-1;
  1436. // SFX
  1437. new leaveSoundID[2] = {5852, 5853};
  1438. new randomLeaveSoundID = random(sizeof(leaveSoundID));
  1439. PlayerPlaySound(playerid, leaveSoundID[randomLeaveSoundID], 0.0, 0.0, 0.0);
  1440. // Convert prkChips to cgChips
  1441. //SetPVarInt(playerid, "cgChips", GetPVarInt(playerid, "cgChips")+GetPVarInt(playerid, "pkrChips"));
  1442. GivePlayerCashEx(playerid, TYPE_ONHAND, GetPVarInt(playerid, "pkrChips"));
  1443. PokerTable[tableid][pkrPot] -= GetPVarInt(playerid, "pkrChips");
  1444. new string[128];
  1445. format(string, sizeof(string), "%s(%d) (IP:%s) has left the table with $%s (%d)", GetPlayerNameEx(playerid), GetPlayerSQLId(playerid), GetPlayerIpEx(playerid), number_format(GetPVarInt(playerid, "pkrChips")), tableid);
  1446. Log("logs/poker.log", string);
  1447. // De-occuply Slot
  1448. PokerTable[tableid][pkrPlayers] -= 1;
  1449. if(GetPVarInt(playerid, "pkrStatus")) PokerTable[tableid][pkrActivePlayers] -= 1;
  1450. PokerTable[tableid][pkrSlot][GetPVarInt(playerid, "pkrSlot")] = -1;
  1451. // Check & Stop the Game Loop if No Players at the Table
  1452. if(PokerTable[tableid][pkrPlayers] == 0) {
  1453. KillTimer(PokerTable[tableid][pkrPulseTimer]);
  1454. new tmpString[64];
  1455. format(tmpString, sizeof(tmpString), "Poker Table %d", tableid);
  1456. Update3DTextLabelText(PokerTable[tableid][pkrText3DID], COLOR_YELLOW, tmpString);
  1457. ResetPokerTable(tableid);
  1458. }
  1459. if(PokerTable[tableid][pkrRound] == 0 && PokerTable[tableid][pkrDelay] < 5) {
  1460. ResetPokerRound(tableid);
  1461. }
  1462. SetPlayerInterior(playerid, PokerTable[tableid][pkrInt]);
  1463. SetPlayerVirtualWorld(playerid, PokerTable[tableid][pkrVW]);
  1464. SetPlayerPos(playerid, GetPVarFloat(playerid, "pkrTableJoinX"), GetPVarFloat(playerid, "pkrTableJoinY"), GetPVarFloat(playerid, "pkrTableJoinZ")+0.1);
  1465. SetCameraBehindPlayer(playerid);
  1466. TogglePlayerControllable(playerid, 1);
  1467. ApplyAnimation(playerid, "CARRY", "crry_prtial", 2.0, 0, 0, 0, 0, 0);
  1468. CancelSelectTextDraw(playerid);
  1469. ShowPlayerDialogEx(playerid, -1, DIALOG_STYLE_LIST, "Close", "Close", "Close", "Close");
  1470. if(GetPVarInt(playerid, "pkrActiveHand")) {
  1471. PokerTable[tableid][pkrActiveHands]--;
  1472. }
  1473. // Destroy Poker Memory
  1474. DeletePVar(playerid, "pkrWinner");
  1475. DeletePVar(playerid, "pkrCurrentBet");
  1476. DeletePVar(playerid, "pkrChips");
  1477. DeletePVar(playerid, "pkrTableJoinX");
  1478. DeletePVar(playerid, "pkrTableJoinY");
  1479. DeletePVar(playerid, "pkrTableJoinZ");
  1480. DeletePVar(playerid, "pkrTableID");
  1481. DeletePVar(playerid, "pkrSlot");
  1482. DeletePVar(playerid, "pkrStatus");
  1483. DeletePVar(playerid, "pkrRoomLeader");
  1484. DeletePVar(playerid, "pkrRoomBigBlind");
  1485. DeletePVar(playerid, "pkrRoomSmallBlind");
  1486. DeletePVar(playerid, "pkrRoomDealer");
  1487. DeletePVar(playerid, "pkrCard1");
  1488. DeletePVar(playerid, "pkrCard2");
  1489. DeletePVar(playerid, "pkrActivePlayer");
  1490. DeletePVar(playerid, "pkrActiveHand");
  1491. DeletePVar(playerid, "pkrHide");
  1492. // Destroy GUI
  1493. DestroyPokerGUI(playerid);
  1494. // Delay Exit Call
  1495. SetTimerEx("PokerExit", 250, false, "d", playerid);
  1496. return 1;
  1497. }
  1498. CMD:jointable(playerid, params[])
  1499. {
  1500. if(PlayerInfo[playerid][pConnectHours] < 5) {
  1501. SendClientMessageEx(playerid, COLOR_GREY, "You need 5 playing hours to join a poker table.");
  1502. return 1;
  1503. }
  1504. if(GetPVarType(playerid, "pkrTableID") == 0) {
  1505. for(new t = 0; t < MAX_POKERTABLES; t++) {
  1506. if(IsPlayerInRangeOfPoint(playerid, 5.0, PokerTable[t][pkrX], PokerTable[t][pkrY], PokerTable[t][pkrZ])) {
  1507. if(PokerTable[t][pkrPass][0] != EOS) {
  1508. if(!strcmp(params, PokerTable[t][pkrPass], false, 32)) {
  1509. JoinPokerTable(playerid, t);
  1510. } else {
  1511. return SendClientMessage(playerid, COLOR_WHITE, "Usage: /jointable (password)");
  1512. }
  1513. } else {
  1514. JoinPokerTable(playerid, t);
  1515. }
  1516. return 1;
  1517. }
  1518. }
  1519. } else {
  1520. SendClientMessage(playerid, COLOR_WHITE, "You are already at a Poker Table! You must /leavetable before you join another one!");
  1521. }
  1522. return 1;
  1523. }
  1524. CMD:leavetable(playerid, params[])
  1525. {
  1526. if(GetPVarType(playerid, "pkrTableID")) {
  1527. LeavePokerTable(playerid);
  1528. }
  1529. return 1;
  1530. }
  1531. CMD:placetable(playerid, params[])
  1532. {
  1533. if(PlayerInfo[playerid][pTable] == 1 || PlayerInfo[playerid][pAdmin] >= 4 || PlayerInfo[playerid][pASM] >= 1) {
  1534. if(GetPVarType(playerid, "IsInArena")) return SendClientMessageEx(playerid, COLOR_GREY, "You can't do this while being in an arena!");
  1535. if(GetPVarInt(playerid, "WatchingTV")) return SendClientMessageEx(playerid, COLOR_GREY, "You can not do this while watching TV!");
  1536. if(GetPVarInt(playerid, "Injured") == 1 || PlayerInfo[playerid][pHospital] > 0 || IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playerid, COLOR_GREY, "You can't do this right now.");
  1537. if(PlayerInfo[playerid][pVW] == 0 || PlayerInfo[playerid][pInt] == 0) return SendClientMessageEx(playerid, COLOR_GREY, "You can only place poker tables inside interiors.");
  1538. if(GetPVarType(playerid, "pTable")) return SendClientMessageEx(playerid, COLOR_GREY, "You already have a poker table out, use /destroytable.");
  1539. foreach(new i: Player)
  1540. {
  1541. if(GetPVarType(i, "pTable"))
  1542. {
  1543. if(IsPlayerInRangeOfPoint(playerid, 7.0, PokerTable[GetPVarInt(i, "pTable")][pkrX], PokerTable[GetPVarInt(i, "pTable")][pkrY], PokerTable[GetPVarInt(i, "pTable")][pkrZ]))
  1544. {
  1545. SendClientMessage(playerid, COLOR_GREY, "You are in range of another poker table, you can't place one here!");
  1546. return 1;
  1547. }
  1548. }
  1549. }
  1550. format(szMiscArray, sizeof(szMiscArray), "%s has placed a poker table!", GetPlayerNameEx(playerid));
  1551. ProxDetector(30.0, playerid, szMiscArray, COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW);
  1552. new Float:fPos[4];
  1553. GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  1554. GetPlayerFacingAngle(playerid, fPos[3]);
  1555. ApplyAnimation(playerid,"BOMBER","BOM_Plant_Crouch_In", 4.0, 0, 0, 0, 0, 0, 1);
  1556. fPos[0] += (2 * floatsin(-fPos[3], degrees));
  1557. fPos[1] += (2 * floatcos(-fPos[3], degrees));
  1558. fPos[2] -= 0.5;
  1559. for(new i = 0; i < MAX_POKERTABLES; i++) {
  1560. if(PokerTable[i][pkrPlaced] == 0) {
  1561. PlacePokerTable(i, 1, fPos[0], fPos[1], fPos[2], 0, 0, 0, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
  1562. SetPVarInt(playerid, "pTable", i);
  1563. break;
  1564. }
  1565. }
  1566. }
  1567. else {
  1568. SendClientMessageEx(playerid, COLOR_GRAD1, "You cannot place a poker table.");
  1569. }
  1570. return 1;
  1571. }
  1572. CMD:destroytable(playerid, params[])
  1573. {
  1574. if(GetPVarType(playerid, "pTable"))
  1575. {
  1576. if(PokerTable[GetPVarType(playerid, "pTable")][pkrPlayers] != 0)
  1577. return SendClientMessageEx(playerid, COLOR_GREY, "You can't destroy your table while a game is in progress.");
  1578. DestroyPokerTable(GetPVarInt(playerid, "pTable"));
  1579. DeletePVar(playerid, "pTable");
  1580. SendClientMessage(playerid, COLOR_GREY, "You've destroyed your poker table!");
  1581. }
  1582. return 1;
  1583. }
  1584. CMD:shoptable(playerid, params[])
  1585. {
  1586. if (PlayerInfo[playerid][pShopTech] < 1)
  1587. {
  1588. SendClientMessageEx(playerid, COLOR_GREY, " You are not allowed to use this command.");
  1589. return 1;
  1590. }
  1591. new giveplayerid, invoice;
  1592. if(sscanf(params, "ui", giveplayerid, invoice)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /shoptable [player] [invoice #]");
  1593. new string[128];
  1594. if(PlayerInfo[giveplayerid][pTable] == 1)
  1595. {
  1596. PlayerInfo[giveplayerid][pTable] = 0;
  1597. format(string, sizeof(string), "Your poker table has been taken by Shop Tech %s. ", GetPlayerNameEx(playerid));
  1598. SendClientMessageEx(giveplayerid, COLOR_LIGHTBLUE, string);
  1599. format(string, sizeof(string), "[SHOPPOKERTABLE] %s has taken %s(%d) poker table - Invoice %d", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), GetPlayerSQLId(giveplayerid), invoice);
  1600. SendClientMessageEx(playerid, COLOR_GRAD1, string);
  1601. Log("logs/shoplog.log", string);
  1602. }
  1603. else
  1604. {
  1605. PlayerInfo[giveplayerid][pTable] = 1;
  1606. format(string, sizeof(string), "You have been given a poker table from Shop Tech %s. ", GetPlayerNameEx(playerid));
  1607. SendClientMessageEx(giveplayerid, COLOR_LIGHTBLUE, string);
  1608. format(string, sizeof(string), "[SHOPPOKERTABLE] %s has given %s(%d) a poker table - Invoice %d", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), GetPlayerSQLId(giveplayerid), invoice);
  1609. SendClientMessageEx(playerid, COLOR_GRAD1, string);
  1610. Log("logs/shoplog.log", string);
  1611. }
  1612. return 1;
  1613. }