Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.28 KB | None | 0 0
  1. #include <a_samp>
  2. #define LOOP(%1,%2) for(new %1; %1<%2;%1++)
  3.  
  4. forward DeleteGame(gameid);
  5. forward CreateGame();
  6. forward UpdateGame(gameid);
  7. forward CloseWindow(playerid);
  8.  
  9. PlayerNearPlayer(player1,player2,Float:distance)
  10. {
  11. new Float:tmp[2][3];
  12. GetPlayerPos(player1,tmp[0][0],tmp[0][1],tmp[0][2]);
  13. GetPlayerPos(player2,tmp[1][0],tmp[1][1],tmp[1][2]);
  14. return ((((tmp[1][0]-tmp[0][0])*(tmp[1][0]-tmp[0][0]))+((tmp[1][1]-tmp[0][1])*(tmp[1][1]-tmp[0][1]))+((tmp[1][2]-tmp[0][2])*(tmp[1][2]-tmp[0][2])))<distance*distance);
  15. }
  16.  
  17. GiveCardName(card,name[],size = sizeof(name))
  18. {
  19. new face = (card/4)+1; // Ace = 1, Jack = 11, Queen = 12, King = 13
  20. new suit = card - ((card/4)*4); // Hearts = 0, Clubs = 1, Diamonds = 2, Spades = 3
  21. switch(face)
  22. {
  23. case 1: format(name,size,"Ace of ");
  24. case 11: format(name,size,"Jack of ");
  25. case 12: format(name,size,"Queen of ");
  26. case 13: format(name,size,"King of ");
  27. default: format(name,size,"%d of ",face);
  28. }
  29. switch(suit)
  30. {
  31. case 0: format(name,size,"%s~r~Hearts~w~",name);
  32. case 1: format(name,size,"%s~p~Clubs~w~",name);
  33. case 2: format(name,size,"%s~r~Diamonds~w~",name);
  34. case 3: format(name,size,"%s~p~Spades~w~",name);
  35. }
  36. }
  37.  
  38. new Game[100][5]; // Jumătate din MAX_PLAYERS - 4 fiind jucătorii maximi pe joc, 5 = Pariul plasat
  39. new GameStep[100]; //0 = jocul nu a fost creat, 1 = jocul a fost creat, 2 = căutarea jucătorilor, 3 = jocul început și cărțile date, 4 = rândul jucătorului 1, 5 = rândul jucătorului 2, 6 = rândul jucătorului 3,
  40. new PlayerGamePosition[MAX_PLAYERS]; // Oferă poziția jucătorului
  41. new PlayerGame[MAX_PLAYERS]; // Oferă gamei în care se află jucătorul
  42. new GameCards[100][52]; // Fiecare joc are un pachet de 52, valoarea fiecărei cărți fiind poziția jucătorului
  43. new Text:GameText[MAX_PLAYERS][5]; //MAX_PLAYERS ori 5 este egal cu 1000, MAX_TEXTDRAWS este egal cu 1024
  44. new PlayerHolding[MAX_PLAYERS];
  45. new PlayerInviting[MAX_PLAYERS];
  46. new PlayerCards[MAX_PLAYERS][5]; // Ordinea cărților primite
  47. new Text:null;
  48.  
  49. public DeleteGame(gameid)
  50. {
  51. LOOP(playerid,4)
  52. {
  53. if(Game[gameid][playerid]>-1)
  54. {
  55. PlayerGame[Game[gameid][playerid]]=-1;
  56. PlayerGamePosition[Game[gameid][playerid]]=-1;
  57. PlayerHolding[Game[gameid][playerid]]=0;
  58. PlayerInviting[Game[gameid][playerid]]=-1;
  59. ClearAnimations(playerid);
  60. LOOP(loop,5)PlayerCards[Game[gameid][playerid]][loop]=-1;
  61. }
  62. Game[gameid][playerid]=-1;
  63. }
  64. LOOP(card,52)GameCards[gameid][card]=-1;
  65. GameStep[gameid]=0;
  66. return 1;
  67. }
  68. public CloseWindow(playerid)
  69. {
  70. LOOP(text,5)
  71. {
  72. if(_:GameText[playerid][text]){TextDrawDestroy(GameText[playerid][text]);GameText[playerid][text]=Text:INVALID_TEXT_DRAW;}
  73. }
  74. return 1;
  75. }
  76.  
  77. public CreateGame()
  78. {
  79. //Cauta si deschide jocul.
  80. new gameid;
  81. LOOP(loop,100)if(!GameStep[loop]){gameid=loop;break;}
  82. GameStep[gameid]=1;
  83. return gameid;
  84. }
  85.  
  86. public UpdateGame(gameid)
  87. {
  88. new OVER;
  89. LOOP(player,4)
  90. {
  91. if(Game[gameid][player]>-1)
  92. {
  93. new playerid = Game[gameid][player];
  94. ApplyAnimation(playerid,"WUZI","Wuzi_stand_loop",4,1,0,0,1,0);
  95. ApplyAnimation(playerid,"WUZI","Wuzi_stand_loop",4,1,0,0,1,0);
  96. //For adding new players
  97. if((GameText[playerid][0]==Text:INVALID_TEXT_DRAW)||!_:GameText[playerid][0])
  98. {
  99. GameText[playerid][0] = TextDrawCreate(320,120,"~y~Jucator Slot 1~n~~w~");
  100. TextDrawUseBox(GameText[playerid][0],1);
  101. TextDrawBoxColor(GameText[playerid][0],0x00000077);
  102. TextDrawAlignment(GameText[playerid][0],2);
  103. TextDrawShowForPlayer(playerid,GameText[playerid][0]);
  104. }
  105. if((GameText[playerid][1]==Text:INVALID_TEXT_DRAW)||!_:GameText[playerid][1])
  106. {
  107. GameText[playerid][1] = TextDrawCreate(320,145,"~y~Jucator Slot 2~n~~w~");
  108. TextDrawUseBox(GameText[playerid][1],1);
  109. TextDrawBoxColor(GameText[playerid][1],0x00000077);
  110. TextDrawAlignment(GameText[playerid][1],2);
  111. TextDrawShowForPlayer(playerid,GameText[playerid][1]);
  112. }
  113. if((GameText[playerid][2]==Text:INVALID_TEXT_DRAW)||!_:GameText[playerid][2])
  114. {
  115. GameText[playerid][2] = TextDrawCreate(320,170,"~y~Jucator slot 3~n~~w~");
  116. TextDrawUseBox(GameText[playerid][2],1);
  117. TextDrawBoxColor(GameText[playerid][2],0x00000077);
  118. TextDrawAlignment(GameText[playerid][2],2);
  119. TextDrawShowForPlayer(playerid,GameText[playerid][2]);
  120. }
  121. if((GameText[playerid][3]==Text:INVALID_TEXT_DRAW)||!_:GameText[playerid][3])
  122. {
  123. GameText[playerid][3] = TextDrawCreate(320,194.5,"~y~Jucator Slot 4~n~~w~");
  124. TextDrawUseBox(GameText[playerid][3],1);
  125. TextDrawBoxColor(GameText[playerid][3],0x00000077);
  126. TextDrawAlignment(GameText[playerid][3],2);
  127. TextDrawShowForPlayer(playerid,GameText[playerid][3]);
  128. }
  129. if((GameText[playerid][4]==Text:INVALID_TEXT_DRAW)||!_:GameText[playerid][4])
  130. {
  131. GameText[playerid][4] = TextDrawCreate(320,219,"~y~Scoruri");
  132. TextDrawUseBox(GameText[playerid][4],1);
  133. TextDrawBoxColor(GameText[playerid][4],0x00000077);
  134. TextDrawAlignment(GameText[playerid][4],2);
  135. TextDrawShowForPlayer(playerid,GameText[playerid][4]);
  136. }
  137.  
  138. //Setari TD
  139. new string[5][256];
  140. new cardname[30];
  141. LOOP(loop,4)
  142. {
  143. if(Game[gameid][loop]>=0)
  144. {
  145. GetPlayerName(Game[gameid][loop],string[loop],sizeof(string[]));
  146. format(string[loop],sizeof(string[]),"~y~%s~n~~w~",string[loop]);
  147. //Aceassta verifica cardurile si le da nume.
  148. LOOP(cards,5)
  149. {
  150. if(PlayerCards[Game[gameid][loop]][cards]>-1)
  151. {
  152. GiveCardName(PlayerCards[Game[gameid][loop]][cards],cardname);
  153. if(Game[gameid][loop]==playerid)format(string[loop],sizeof(string[]),"%s: %s ",string[loop],cardname);
  154. else if(GameStep[gameid]>=8)format(string[loop],sizeof(string[]),"%s: %s ",string[loop],cardname);
  155. else if((GameCards[gameid][PlayerCards[Game[gameid][loop]][cards]]-(GameCards[gameid][PlayerCards[Game[gameid][loop]][cards]]/5)*5)==0)format(string[loop],sizeof(string[]),"%s: %s ",string[loop],cardname);
  156. else if(GameStep[gameid]<8)format(string[loop],sizeof(string[]),"%s: ~r~??~w~ ",string[loop]);
  157. else if(GameStep[gameid]>=8)format(string[loop],sizeof(string[]),"%s: %s ",string[loop],cardname);
  158. }
  159. }
  160. format(string[loop],sizeof(string[]),"%s :",string[loop]);
  161. }
  162. else
  163. {
  164. format(string[loop],sizeof(string[]),"~y~Jucator Slot %d~n~~w~",loop);
  165. }
  166.  
  167. TextDrawSetString(GameText[playerid][loop],string[loop]);
  168. }
  169. if(GameStep[gameid]==2)
  170. {
  171. format(string[4],sizeof(string[]),"Se aseapta jucatorii");
  172. if(Game[gameid][1]>-1)
  173. {
  174. if(Game[gameid][0]==playerid)
  175. {
  176. GetPlayerName(Game[gameid][0],string[4],sizeof(string[]));
  177. format(string[4],sizeof(string[]),"%s -- Apasa ~k~~PED_FIREWEAPON~ pentru a incepe.",string[4]);
  178. }else{
  179. GetPlayerName(Game[gameid][0],string[4],sizeof(string[]));
  180. format(string[4],sizeof(string[]),"Asteapta %s ca asa inceapa.",string[4]);
  181. }
  182. }
  183. TextDrawSetString(GameText[playerid][4],string[4]);
  184. }
  185. //Dați fiecărui jucător 2 cărți apoi setați la rândul dealerului pentru a lovi / rămâne
  186. if(GameStep[gameid]==3)
  187. {
  188. LOOP(loop,2)
  189. {
  190. if(Game[gameid][player]>-1)
  191. {
  192.  
  193. CardLabel:
  194. new tmp = random(52);
  195. if(GameCards[gameid][tmp]>=0)goto CardLabel;
  196. LOOP(cards,5)
  197. {
  198. if(PlayerCards[Game[gameid][player]][cards]==-1)
  199. {
  200. GameCards[gameid][tmp]=player*5+cards;
  201. PlayerCards[Game[gameid][player]][cards]=tmp;
  202. break;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. //Toată cartiile se rotesc, 4 = 0, 5 = 1, 6 = 2, 7 = 3
  209. if(GameStep[gameid]==4)
  210. {
  211. new winners[4];
  212. new won;
  213. string[4]="";
  214. LOOP(loop,4)
  215. {
  216. if(Game[gameid][loop]>-1)
  217. {
  218. new tmpstring2[64];
  219. if(PlayerCards[Game[gameid][loop]][2]==-1)
  220. {
  221. new tmp;
  222. if(PlayerCards[Game[gameid][loop]][0]/4==0)tmp+=11;
  223. if(PlayerCards[Game[gameid][loop]][1]/4==0)tmp+=11;
  224. if(PlayerCards[Game[gameid][loop]][1]/4>=9)tmp+=10;
  225. if(PlayerCards[Game[gameid][loop]][0]/4>=9)tmp+=10;
  226. if(tmp==21){tmpstring2="Black Jack";winners[loop]=1;won=1;} //Castiga instant
  227. }else if(PlayerCards[Game[gameid][loop]][4]>-1)
  228. {
  229. new tmp;
  230. LOOP(loop2,5)if(PlayerCards[Game[gameid][loop]][loop2]>-1)if((PlayerCards[Game[gameid][loop]][loop2]/4)+1>10)tmp+=10;else tmp+=((PlayerCards[Game[gameid][loop]][loop2]/4)+1);
  231. if(tmp<=21){tmpstring2="5 Card Jimmy";winners[loop]=2;won=1;} //Castiga cu 5 carti.
  232. }else
  233. {
  234. new tmp;
  235. new tmp2;
  236. LOOP(loop2,5)
  237. {
  238. if(PlayerCards[Game[gameid][loop]][loop2]>-1)
  239. {
  240. if((PlayerCards[Game[gameid][loop]][loop2]/4)+1>=10)
  241. {
  242. tmp+=10;
  243. tmp2+=10;
  244. }else if(PlayerCards[Game[gameid][loop]][loop2]/4==0)
  245. {
  246. if(tmp!=tmp2)tmp2+=1;
  247. else tmp2+=11;
  248. tmp+=1;
  249. }else {tmp+=(PlayerCards[Game[gameid][loop]][loop2]/4)+1; tmp2+=(PlayerCards[Game[gameid][loop]][loop2]/4)+1;}
  250. }
  251. }
  252. if((tmp==21)||(tmp2==21)) //Castiga normal
  253.  
  254. {
  255. tmpstring2="Black Jack";
  256. winners[loop]=1;
  257. won++;
  258. }
  259. }
  260. new tmpstring[24];
  261. GetPlayerName(Game[gameid][loop],tmpstring,sizeof(tmpstring));
  262. if(winners[loop])
  263. {
  264. format(string[4],sizeof(string[]),"%s~n~%s a castigat cu %s!",string[4],tmpstring,tmpstring2);
  265. }
  266. }
  267. }
  268. if(won)
  269. {
  270. format(string[4],sizeof(string[]),"Joc terminat!~n~%s",string[4]);
  271. TextDrawSetString(GameText[playerid][4],string[4]);
  272. if(winners[PlayerGamePosition[playerid]])
  273. {
  274. GetPlayerName(playerid,string[4],sizeof(string[]));
  275. new tmp;LOOP(loop,4)if(Game[gameid][loop]>-1)tmp++;
  276. format(string[4],sizeof(string[]),"%s wins $%d.",string[4],(Game[gameid][4]*tmp)/won);
  277. GivePlayerMoney(playerid,(Game[gameid][4]*tmp)/won);
  278. LOOP(loop2,4)if(Game[gameid][loop2]>-1)SendClientMessage(Game[gameid][loop2],0xFF0000FF,string[4]);
  279. }
  280. OVER=1;
  281. continue;
  282. }
  283. }
  284. if((GameStep[gameid]>=4)&&(GameStep[gameid]<=7))
  285. {
  286. new tmps;
  287. LOOP(loop,4)
  288. {
  289. if(Game[gameid][loop]>-1)
  290. {
  291. if(PlayerHolding[Game[gameid][loop]]){tmps++;}
  292. }else tmps++;
  293. }
  294. if(tmps==4)
  295. {
  296. new bestscore;
  297. new scoreholder;
  298. new currentscore;
  299. new playerscore[4];
  300. LOOP(loop,4)
  301. {
  302. if(Game[gameid][loop]>-1)
  303. {
  304. new tmp;
  305. new tmp2;
  306. LOOP(loop2,5)
  307. {
  308. if(PlayerCards[Game[gameid][loop]][loop2]>-1)
  309. {
  310. if((PlayerCards[Game[gameid][loop]][loop2]/4)+1>=10)
  311. {
  312. tmp+=10;
  313. tmp2+=10;
  314. }else if(PlayerCards[Game[gameid][loop]][loop2]/4==0)
  315. {
  316. if(tmp!=tmp2)tmp2+=1;
  317. else tmp2+=11;
  318. tmp+=1;
  319. }else {tmp+=(PlayerCards[Game[gameid][loop]][loop2]/4)+1; tmp2+=(PlayerCards[Game[gameid][loop]][loop2]/4)+1;}
  320. }
  321. }
  322. if(tmp2>21){currentscore=tmp;playerscore[loop]=tmp;}
  323. else {currentscore=tmp2;playerscore[loop]=tmp2;}
  324. if((currentscore>bestscore)&&(currentscore<22)){scoreholder=loop;bestscore=currentscore;}
  325. }
  326. }
  327. new tmp2;
  328. LOOP(loop,4)if(playerscore[loop]==bestscore)tmp2++;
  329. LOOP(loop,4)if(playerscore[loop]==bestscore)
  330. {
  331. new tmpstring[24];
  332. GetPlayerName(Game[gameid][scoreholder],tmpstring,sizeof(tmpstring));
  333. format(string[4],sizeof(string[]),"Joc terminat!~n~~n~%s has ~g~a castigat!~w~",tmpstring);
  334. }
  335. if(playerscore[PlayerGamePosition[playerid]]==bestscore)
  336. {
  337. GetPlayerName(playerid,string[4],sizeof(string[]));
  338. new tmp;LOOP(loop,4)if(Game[gameid][loop]>-1)tmp++;
  339. format(string[4],sizeof(string[]),"%s wins $%d.",string[4],(Game[gameid][4]*tmp)/tmp2);
  340. GivePlayerMoney(playerid,(Game[gameid][4]*tmp)/tmp2);
  341. LOOP(loop2,4)if(Game[gameid][loop2]>-1)SendClientMessage(Game[gameid][loop2],0xFF0000FF,string[4]);
  342. }
  343. TextDrawSetString(GameText[playerid][4],string[4]);
  344. OVER=1;
  345. continue;
  346. }
  347. if(GameStep[gameid]-4==PlayerGamePosition[playerid]) // Randul jucatorului.
  348. {
  349. if(PlayerHolding[playerid])
  350. {
  351. new tmp2;
  352. LOOP(loop2,4)if(Game[gameid][loop2]==-1)tmp2++;
  353. GameStep[gameid]++;
  354. if(GameStep[gameid]==7-tmp2+1)GameStep[gameid]=4;
  355. UpdateGame(gameid);
  356. return;
  357. }
  358. format(string[4],sizeof(string[]),"Randul tau, apasa ~k~~PED_JUMPING~ pentru a lovi si ~k~~PED_SPRINT~ pentru a sta.",string[4]);
  359. }else{
  360. GetPlayerName(Game[gameid][GameStep[gameid]-4],string[4],sizeof(string[]));
  361. format(string[4],sizeof(string[]),"%s's turn",string[4]);
  362. }
  363. }
  364. if((GameStep[gameid]>3)&&(GameStep[gameid]<8))
  365. {
  366. new Losers[4]; // -1 = nu există, 0 = ratat, 1 = nu
  367. LOOP(loop,4)
  368. {
  369. if(Game[gameid][loop]>-1)
  370. {
  371. new tmp;
  372. new tmp2;
  373. LOOP(loop2,5)
  374. {
  375. if(PlayerCards[Game[gameid][loop]][loop2]>-1)
  376. {
  377. if((PlayerCards[Game[gameid][loop]][loop2]/4)+1>=10)
  378. {
  379. tmp+=10;
  380. tmp2+=10;
  381. }else if(PlayerCards[Game[gameid][loop]][loop2]/4==0)
  382. {
  383. if(tmp!=tmp2)tmp2+=1;
  384. else tmp2+=11;
  385. tmp+=1;
  386. }else {tmp+=(PlayerCards[Game[gameid][loop]][loop2]/4)+1; tmp2+=(PlayerCards[Game[gameid][loop]][loop2]/4)+1;}
  387. }
  388. }
  389. if(tmp>21)
  390. {
  391. PlayerHolding[Game[gameid][loop]]=1;
  392. new tmpstring[24];
  393. Losers[loop]=0;
  394. GetPlayerName(Game[gameid][loop],tmpstring,sizeof(tmpstring));
  395. format(string[4],sizeof(string[]),"%s~n~%s has ~r~PRINS!~w~",string[4],tmpstring);
  396. }else Losers[loop]=1;
  397. }else Losers[loop]=-1;
  398. }
  399. new tmpp;
  400. new winner=-1;
  401. LOOP(loop,4)if(Losers[loop]==1){tmpp++;}
  402. if(tmpp==1)LOOP(loop,4)if(Losers[loop]==1)winner=loop;
  403. if(winner>-1)
  404. {
  405. new tmpstring[24];
  406. GetPlayerName(Game[gameid][winner],tmpstring,sizeof(tmpstring));
  407. format(string[4],sizeof(string[]),"%s~n~%s has ~g~WON!~w~",string[4],tmpstring);
  408. OVER=1;
  409. }
  410. if(OVER){strdel(string[4],0,strfind(string[4],"~n~",true));format(string[4],sizeof(string[]),"GetIPCountry(ip[], dest[], const len = sizeof(dest)ame Over!~n~%s",string[4]);}
  411. TextDrawSetString(GameText[playerid][4],string[4]);
  412. if(winner == PlayerGamePosition[playerid])
  413. {
  414. GetPlayerName(playerid,string[4],sizeof(string[]));
  415. new tmp;LOOP(loop,4)if(Game[gameid][loop]>-1)tmp++;
  416. format(string[4],sizeof(string[]),"%s wins $%d.",string[4],(Game[gameid][4]*tmp));
  417. GivePlayerMoney(playerid,(Game[gameid][4]*tmp));
  418. LOOP(loop2,4)if(Game[gameid][loop2]>-1)SendClientMessage(Game[gameid][loop2],0xFF0000FF,string[4]);
  419. }
  420. }
  421. }
  422. }
  423. if(OVER)GameStep[gameid]=8;
  424. if(GameStep[gameid]==3){GameStep[gameid]=4;UpdateGame(gameid);}
  425. if(GameStep[gameid]==8){GameStep[gameid]=9;UpdateGame(gameid);DeleteGame(gameid);}
  426. }
  427.  
  428. public OnFilterScriptInit()
  429. {
  430. LOOP(loop,100)
  431. {
  432. LOOP(loop2,4)Game[loop][loop2]=-1;
  433. LOOP(loop2,52)GameCards[loop][loop2]=-1;
  434. }
  435. LOOP(loop,MAX_PLAYERS)
  436. {
  437. PlayerGame[loop]=-1;
  438. PlayerGamePosition[loop]=-1;
  439. PlayerInviting[loop]=-1;
  440. LOOP(loop2,5)
  441. {
  442. if(_:GameText[loop][loop2])TextDrawDestroy(GameText[loop][loop2]);
  443. PlayerCards[loop][loop2]=-1;
  444. }
  445. }
  446. if(!_:null)null = TextDrawCreate(0,0," "); //Elimină un bug obișnuit, care va fi afișat sub fișierele OnFilterScriptInit și OnGameModeInit
  447. TextDrawShowForPlayer(0,null);
  448. return 1;
  449. }
  450.  
  451. public OnGameModeInit()
  452. {
  453. null = TextDrawCreate(0,0," "); //Elimină un bug obișnuit, care va fi afișat sub fișierele OnFilterScriptInit și OnGameModeInit
  454. TextDrawShowForPlayer(0,null);
  455. return 1;
  456. }
  457.  
  458. public OnFilterScriptExit()
  459. {
  460. return 1;
  461. }
  462.  
  463. public OnPlayerCommandText(playerid,cmdtext[])
  464. {
  465. if(!strcmp(cmdtext,"/StartBlackJack ",true,16))
  466. {
  467. if(PlayerGame[playerid]>-1)return SendClientMessage(playerid,0xff0000ff,"You are already in a game.");
  468. if(IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,0xFF0000FF,"You cannot be in a vehicle.");
  469. new BetAmount = strval(cmdtext[16]);
  470. if(!strlen(cmdtext[16]) || BetAmount<0)return SendClientMessage(playerid,0xFF0000FF,"USAGE: /StartBlackJack $amount$");
  471. if(GetPlayerMoney(playerid)<BetAmount)return SendClientMessage(playerid,0xFF0000FF,"You don't have that much cash.");
  472. GivePlayerMoney(playerid,-BetAmount);
  473. new gameid = CreateGame();
  474. Game[gameid][0]=playerid;
  475. Game[gameid][4]=BetAmount;
  476. GameStep[gameid]=2;
  477. PlayerGame[playerid]=gameid;
  478. PlayerGamePosition[playerid]=0;
  479. new tmpstring[60];
  480. format(tmpstring,sizeof(tmpstring),"You have started a Black Jack game with a bet of $%d",BetAmount);
  481. SendClientMessage(playerid,0xFF0000FF,tmpstring);
  482. UpdateGame(gameid);
  483. return 1;
  484. }/*
  485. if(!strcmp(cmdtext,"/addcrd ",true,8))
  486. {
  487. new face = strval(cmdtext[8])+1;
  488. new card = strval(cmdtext[strfind(cmdtext," ",true,8)+1]);
  489. new tmp = (face*4)+card;
  490. if(GameCards[PlayerGame[playerid]][tmp]>-1)return SendClientMessage(playerid,0xFF0000FF,"Card taken");
  491. new tmp2;
  492. LOOP(cards,5)
  493. {
  494. if(PlayerCards[playerid][cards]==-1)
  495. {
  496. GameCards[PlayerGame[playerid]][tmp]=playerid*5+cards;
  497. PlayerCards[playerid][cards]=tmp;
  498. break;
  499. }
  500. }
  501. new tmp23[50];
  502. GetPlayerName(playerid,tmp23,sizeof(tmp23));
  503. format(tmp23,sizeof(tmp23),"%s decides to hit.",tmp23);
  504. LOOP(loop2,4)if(Game[PlayerGame[playerid]][loop2]!=playerid)SendClientMessage(Game[PlayerGame[playerid]][loop2],0xFF0000FF,tmp23);
  505. GameStep[PlayerGame[playerid]]++;
  506. LOOP(loop2,4)if(Game[PlayerGame[playerid]][loop2]==-1)tmp2++;
  507. if(GameStep[PlayerGame[playerid]]==7-tmp2+1)GameStep[PlayerGame[playerid]]=4;
  508. UpdateGame(PlayerGame[playerid]);
  509. return 1;
  510. }*/
  511. if(!strcmp(cmdtext,"/invite ",true,8))
  512. {
  513. if(PlayerInviting[playerid]>-1)return SendClientMessage(playerid,0xFF0000FF,"You currently have an outstanding invite. type /CancelInvite to cancel it.");
  514. if(IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,0xFF0000FF,"You cannot be in a vehicle.");
  515. new person = strval(cmdtext[8]);
  516. if(IsPlayerConnected(person))
  517. {
  518. if(GetPlayerMoney(person)<Game[PlayerGame[playerid]][4])return SendClientMessage(playerid,0xFF0000FF,"That player doesn't have enough cash.");
  519. new string[200];
  520. LOOP(loop,MAX_PLAYERS)if(PlayerInviting[loop]==person){printf("%d",loop);return SendClientMessage(playerid,0xFF0000FF,"That player is busy with another invite.");}
  521. if((PlayerGame[person]==-1))//PlayerGame[person]==-1
  522. {
  523. PlayerInviting[playerid]=person;
  524. GetPlayerName(playerid,string,sizeof(string));
  525. format(string,sizeof(string),"%s has invited you to a game of Black Jack betting $%d. Type /AcceptInvite to accept.",string,Game[PlayerGame[playerid]][4]);
  526. SendClientMessage(person,0xFF0000FF,string);
  527. GetPlayerName(person,string,sizeof(string));
  528. format(string,sizeof(string),"You have invited %s to a game of Black Jack betting $%d.",string,Game[PlayerGame[playerid]][4]);
  529. SendClientMessage(playerid,0xFF0000FF,string);
  530. return 1;
  531. }else{
  532. return 1;
  533. }
  534. }
  535. }
  536. if(!strcmp(cmdtext,"/acceptinvite",true))
  537. {
  538. LOOP(player,MAX_PLAYERS)
  539. {
  540. if(PlayerInviting[player]==playerid)
  541. {
  542. if(PlayerNearPlayer(playerid,player,5))
  543. {
  544. LOOP(position,4)
  545. {
  546. if(Game[PlayerGame[player]][position]==-1)
  547. {
  548. PlayerGame[playerid] = PlayerGame[player];
  549. PlayerGamePosition[playerid]=position;
  550. Game[PlayerGame[player]][position]=playerid;
  551. GivePlayerMoney(playerid,-Game[PlayerGame[player]][4]);
  552. UpdateGame(PlayerGame[player]);
  553. return 1;
  554. }
  555. }
  556. PlayerInviting[playerid]=-1;
  557. }else SendClientMessage(playerid,0xFF0000FF,"You are not close enough to accept the invite.");
  558. }
  559. }
  560. }
  561. if(!strcmp(cmdtext,"/cancelinvite",true))
  562. {
  563. if(PlayerInviting[playerid]>-1)
  564. {
  565. new tmpstring[100];
  566. GetPlayerName(playerid,tmpstring,sizeof(tmpstring));
  567. format(tmpstring,sizeof(tmpstring),"%s has canceled the invite sent to you",tmpstring);
  568. SendClientMessage(PlayerInviting[playerid],0xFF0000FF,tmpstring);
  569. GetPlayerName(PlayerInviting[playerid],tmpstring,sizeof(tmpstring));
  570. format(tmpstring,sizeof(tmpstring),"You have canceled the invite to %s",tmpstring);
  571. SendClientMessage(playerid,0xFF0000FF,tmpstring);
  572. PlayerInviting[playerid]=-1;
  573. return 1;
  574. }else return SendClientMessage(playerid,0xFF0000FF,"You don't have any outstanding invites.");
  575. }
  576. if(!strcmp(cmdtext,"/declineinvite",true))
  577. {
  578. LOOP(player,MAX_PLAYERS)
  579. {
  580. if(PlayerInviting[player]==playerid)
  581. {
  582. PlayerInviting[playerid]=-1;
  583. new tmpstring[80];
  584. GetPlayerName(playerid,tmpstring,sizeof(tmpstring));
  585. format(tmpstring,sizeof(tmpstring),"%s has declined you invite",tmpstring);
  586. SendClientMessage(player,0xFF0000FF,tmpstring);
  587. GetPlayerName(player,tmpstring,sizeof(tmpstring));
  588. format(tmpstring,sizeof(tmpstring),"You have declined %s's invite",tmpstring);
  589. SendClientMessage(playerid,0xFF0000FF,tmpstring);
  590. return 1;
  591. }
  592. }return SendClientMessage(playerid,0xFF0000FF,"No one has invited you to a game, or they have canceled the invite.");
  593. }
  594. if(!strcmp(cmdtext,"/closegame",true))
  595. {
  596. if(PlayerGame[playerid]>-1)
  597. {
  598. if(GameStep[PlayerGame[playerid]]<3)
  599. {
  600. LOOP(loop,4)if((Game[PlayerGame[playerid]][loop]>-1))if(Game[PlayerGame[playerid]][loop]!=playerid)
  601. {
  602. new tmpstring[100];
  603. GetPlayerName(playerid,tmpstring,sizeof(tmpstring));
  604. format(tmpstring,sizeof(tmpstring),"%s has canceled the game, your money has been returned to you.",tmpstring);
  605. SendClientMessage(Game[PlayerGame[playerid]][loop],0xFF0000FF,tmpstring);
  606. GivePlayerMoney(Game[PlayerGame[playerid]][loop],Game[PlayerGame[playerid]][4]);
  607. }
  608. SendClientMessage(playerid,0xFF0000FF,"You have canceled the game and the money has been returns to the players.");
  609. GivePlayerMoney(playerid,Game[PlayerGame[playerid]][4]);
  610. }
  611. else
  612. {
  613. LOOP(loop,4)if((Game[PlayerGame[playerid]][loop]>-1))if(Game[PlayerGame[playerid]][loop]!=playerid)
  614. {
  615. new tmpstring[100];
  616. GetPlayerName(playerid,tmpstring,sizeof(tmpstring));
  617. new tmp;
  618. LOOP(loop2,4)if(Game[PlayerGame[playerid]][loop]>-1)tmp++;
  619. format(tmpstring,sizeof(tmpstring),"%s has quit, $%d has split between the remaining players.",tmpstring,Game[PlayerGame[playerid]][4]*tmp);
  620. GivePlayerMoney(Game[PlayerGame[playerid]][loop],Game[PlayerGame[playerid]][4]*tmp);
  621. SendClientMessage(Game[PlayerGame[playerid]][loop],0xFF0000FF,tmpstring);
  622. }
  623. SendClientMessage(playerid,0xFF0000FF,"You quit and lost the money.");
  624. }
  625. DeleteGame(PlayerGame[playerid]);
  626. }
  627. CloseWindow(playerid);
  628. return 1;
  629. }
  630. return 0;
  631. }
  632.  
  633. public OnPlayerDisconnect(playerid, reason)
  634. {
  635. if(PlayerGame[playerid]>-1)
  636. {
  637. if(PlayerGame[playerid]>-1)
  638. {
  639. LOOP(loop,4)if((Game[PlayerGame[playerid]][loop]>-1))if(Game[PlayerGame[playerid]][loop]!=playerid)
  640. {
  641. new tmpstring[100];
  642. GetPlayerName(playerid,tmpstring,sizeof(tmpstring));
  643. new tmp;
  644. LOOP(loop2,4)if(Game[PlayerGame[playerid]][loop]>-1)tmp++;
  645. format(tmpstring,sizeof(tmpstring),"%s a iesit, $%d s-au dat la playerii ramasi.",tmpstring,Game[PlayerGame[playerid]][4]*tmp);
  646. GivePlayerMoney(Game[PlayerGame[playerid]][loop],Game[PlayerGame[playerid]][4]*tmp);
  647. SendClientMessage(Game[PlayerGame[playerid]][loop],0xFF0000FF,tmpstring);
  648. }
  649. SendClientMessage(playerid,0xFF0000FF,"Ai iesit si ai pierdut banii");
  650. DeleteGame(PlayerGame[playerid]);
  651. }
  652. CloseWindow(playerid);
  653. }
  654. return 1;
  655. }
  656.  
  657. public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
  658. {
  659. if(PlayerGame[playerid]>-1)
  660. {
  661. if(GameStep[PlayerGame[playerid]]==2)
  662. {
  663. if(Game[PlayerGame[playerid]][1]>-1)
  664. {
  665. if(Game[PlayerGame[playerid]][0]==playerid)
  666. {
  667. if((newkeys==KEY_FIRE) && (oldkeys == 0))
  668. {
  669. GameStep[PlayerGame[playerid]]=3;
  670. UpdateGame(PlayerGame[playerid]);
  671. return 1;
  672. }
  673. }
  674. }
  675. }
  676. if(GameStep[PlayerGame[playerid]]==PlayerGamePosition[playerid]+4)
  677. {
  678. if((newkeys == KEY_SPRINT) && (oldkeys == 0))
  679. {
  680. PlayerHolding[playerid] = 1;
  681. new tmp2;
  682. LOOP(players,4)
  683. {
  684. if(Game[PlayerGame[playerid]][players]>-1)
  685. {
  686. new tmp[50];
  687. GetPlayerName(playerid,tmp,sizeof(tmp));
  688. format(tmp,sizeof(tmp),"%s decides to stay.",tmp);
  689. SendClientMessage(Game[PlayerGame[playerid]][players],0xFF0000FF,tmp);
  690. }else tmp2++;
  691.  
  692. }
  693. GameStep[PlayerGame[playerid]]++;
  694. if(GameStep[PlayerGame[playerid]]==7-tmp2+1)GameStep[PlayerGame[playerid]]=4;
  695. UpdateGame(PlayerGame[playerid]);
  696. return 1;
  697. }
  698. if((newkeys == KEY_JUMP) && (oldkeys == 0))
  699. {
  700. CardLabel2:
  701. new tmp = random(52);
  702. if(GameCards[PlayerGame[playerid]][tmp]>=0)goto CardLabel2;
  703. new tmp2;
  704. LOOP(cards,5)
  705. {
  706. if(PlayerCards[playerid][cards]==-1)
  707. {
  708. GameCards[PlayerGame[playerid]][tmp]=playerid*5+cards;
  709. PlayerCards[playerid][cards]=tmp;
  710. break;
  711. }
  712. }
  713. new tmp23[50];
  714. GetPlayerName(playerid,tmp23,sizeof(tmp23));
  715. format(tmp23,sizeof(tmp23),"%s decides to hit.",tmp23);
  716. LOOP(loop2,4)if(Game[PlayerGame[playerid]][loop2]!=playerid)SendClientMessage(Game[PlayerGame[playerid]][loop2],0xFF0000FF,tmp23);
  717. GameStep[PlayerGame[playerid]]++;
  718. LOOP(loop2,4)if(Game[PlayerGame[playerid]][loop2]==-1)tmp2++;
  719. if(GameStep[PlayerGame[playerid]]==7-tmp2+1)GameStep[PlayerGame[playerid]]=4;
  720. UpdateGame(PlayerGame[playerid]);
  721. return 1;
  722. }
  723. }
  724. }
  725. return 1;
  726. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement