Guest User

Untitled

a guest
Nov 18th, 2012
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.76 KB | None | 0 0
  1. // //
  2. // //
  3. // //
  4. // //
  5. // MarkzD //
  6. // //
  7. // //
  8. // //
  9. // //
  10. #include <a_samp>
  11. #include <mxINI>
  12. #include <zcmd>
  13.  
  14. #define red 0xFF0000AA
  15. #define COLOR_DRED 0xFF0000AA
  16.  
  17. new PAccount[MAX_PLAYERS];//Account saved or not
  18.  
  19. enum pInfo
  20. {
  21. pPass[64],//Player saved password
  22. pAdmin,//Admin or not
  23. pVip,//Vip or not
  24. pMoney,//PlayerMoneys
  25. pScore,//Score
  26. }
  27. new Player[MAX_PLAYERS][pInfo];
  28.  
  29. public OnGameModeInit()
  30. {
  31. SetGameModeText("M-Admin");
  32. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  33. return 1;
  34. }
  35.  
  36. main()
  37. {
  38. print("\n----------------------------------");
  39. print("M-Admin system 1.0");
  40. print("----------------------------------\n");
  41. }
  42.  
  43. public OnGameModeExit()
  44. {
  45. return 1;
  46. }
  47.  
  48. public OnPlayerRequestClass(playerid, classid)
  49. {
  50. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  51. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  52. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  53. if(PAccount[playerid] == 1)// If account saved
  54. {
  55. ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"{FF0000}Login","{FFFFFF}Hello!\nYour account registered in server\nPlease,type your password below:","Yep","Exit");// Ïîêàçûâàåì äèàëîã âõîäà â èãðó. Ñòèëü äèàëîãà âûñòàâëÿåì íà ââîä òåêñòà.
  56. }
  57. else// If account nor saved
  58. {
  59. ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"{00FF00}Register","{FFFFFF}Hello!\nYour account not registered!\nType password below:","Yep","Exit");// Ïîêàçûâàåì äèàëîã ðåãèñòðàöèè. Ñòèëü äèàëîãà âûñòàâëÿåì íà ââîä òåêñòà.
  60. }
  61. return 1;
  62. }
  63.  
  64. public OnPlayerConnect(playerid)
  65. {
  66. new playername[MAX_PLAYER_NAME];
  67. new string[128];
  68. GetPlayerName(playerid,playername,sizeof(playername));
  69. format(string,sizeof(string),"players/%s.ini", playername);
  70. if(fexist(string))
  71. {
  72. PAccount[playerid] = 1;
  73. }
  74. else
  75. {
  76. PAccount[playerid] = 0;
  77. }
  78. return 1;
  79. }
  80.  
  81. public OnPlayerDisconnect(playerid, reason)
  82. {
  83. return 1;
  84. }
  85.  
  86. public OnPlayerSpawn(playerid)
  87. {
  88. return 1;
  89. }
  90.  
  91. public OnPlayerDeath(playerid, killerid, reason)
  92. {
  93. return 1;
  94. }
  95.  
  96. public OnVehicleSpawn(vehicleid)
  97. {
  98. return 1;
  99. }
  100.  
  101. public OnVehicleDeath(vehicleid, killerid)
  102. {
  103. return 1;
  104. }
  105.  
  106. public OnPlayerText(playerid, text[])
  107. {
  108. return 1;
  109. }
  110. COMMAND:pmenu(playerid,params[])
  111. {
  112. ShowPlayerDialog(playerid,3,DIALOG_STYLE_LIST,"Player Menu","Account stats","Okay","Exit");
  113. return 1;
  114. }
  115.  
  116. CMD:ban(playerid,params[])
  117. {
  118. if(Player[playerid][pAdmin] >= 2)
  119. {
  120. new tmp[256], tmp2[256], Index;
  121. tmp = strtok(params,Index), tmp2 = strtok(params,Index);
  122. if(isnull(params)) return SendClientMessage(playerid, red, "Usage: /ban [playerid] [reason]"); //Check If Player Does Not Added "Reason and the ID"
  123. new player1, playername[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[128];
  124. player1 = strval(tmp); // << player1 = ID of The Player
  125. if(!IsPlayerConnected(player1)) return SendClientMessage(playerid,red,"Player not connected.."); //<< Check If Player Connected Or Not
  126. GetPlayerName(player1, playername, sizeof(playername)); //get Selected Player Name
  127. GetPlayerName(playerid, adminname, sizeof(adminname)); //get Admin Name Who Use This command
  128. if(isnull(tmp2))
  129. {
  130. format(string,sizeof(string),"M-Admin:Administartor %s has ban %s | Reason: %s",adminname,playername,params[2]); //adminname = the player Who Use This command || playername = the Player who Going To Be kicked || params[2] = The Reason Of The Kick
  131. SendClientMessageToAll(red,string); // Send Message To all Players.
  132. Ban(player1);
  133. }
  134. else
  135. {
  136. SendClientMessage(playerid,0xFF0000FF,"Error: You are not admin!");
  137. }
  138. }
  139. return 1;
  140. }
  141. CMD:kick(playerid,params[])
  142. {
  143. if(Player[playerid][pAdmin] >= 1)
  144. {
  145. new tmp[256], tmp2[256], Index;
  146. tmp = strtok(params,Index), tmp2 = strtok(params,Index);
  147. if(isnull(params)) return SendClientMessage(playerid, red, "Usage: /kick [playerid] [reason]"); //Check If Player Does Not Added "Reason and the ID"
  148. new player1, playername[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[128];
  149. player1 = strval(tmp); // << player1 = ID of The Player
  150. if(!IsPlayerConnected(player1)) return SendClientMessage(playerid,red,"Player not connected"); //<< Check If Player Connected Or Not
  151. GetPlayerName(player1, playername, sizeof(playername)); //get Selected Player Name
  152. GetPlayerName(playerid, adminname, sizeof(adminname)); //get Admin Name Who Use This command
  153. format(string,sizeof(string),"M-Admin:Administartor %s has kick %s | Reason: %s",adminname,playername,params[2]); //adminname = the player Who Use This command || playername = the Player who Going To Be kicked || params[2] = The Reason Of The Kick
  154. SendClientMessageToAll(red,string); // Send Message To all Players.
  155. Kick(player1);
  156. }
  157. else
  158. {
  159. SendClientMessage(playerid,0xFF0000FF,"Error: You are not admin!");
  160. }
  161. return 1;
  162. }
  163. CMD:cc(playerid,params[])
  164. {
  165. if(Player[playerid][pAdmin] >= 1)
  166. {
  167. SendClientMessageToAll(0xFFFFFFFF,"");
  168. SendClientMessageToAll(0xFFFFFFFF,"");
  169. SendClientMessageToAll(0xFFFFFFFF,"");
  170. SendClientMessageToAll(0xFFFFFFFF,"");
  171. SendClientMessageToAll(0xFFFFFFFF,"");
  172. SendClientMessageToAll(0xFFFFFFFF,"");
  173. SendClientMessageToAll(0xFFFFFFFF,"");
  174. SendClientMessageToAll(0xFFFFFFFF,"");
  175. SendClientMessageToAll(0xFFFFFFFF,"");
  176. SendClientMessageToAll(0xFFFFFFFF,"");
  177. SendClientMessageToAll(0xFFFFFFFF,"");
  178. SendClientMessageToAll(0xFFFFFFFF,"");
  179. SendClientMessageToAll(0xFFFFFFFF,"");
  180. SendClientMessageToAll(0xFFFFFFFF,"");
  181. SendClientMessageToAll(0xFFFFFFFF,"");
  182. SendClientMessageToAll(0xFFFFFFFF,"");
  183. SendClientMessageToAll(0xFFFFFFFF,"");
  184. SendClientMessageToAll(0xFFFFFFFF,"");
  185. SendClientMessageToAll(0xFFFFFFFF,"");
  186. SendClientMessageToAll(0xFFFFFFFF,"");
  187. SendClientMessageToAll(0xFFFFFFFF,"");
  188. SendClientMessageToAll(0xFFFFFFFF,"");
  189. SendClientMessageToAll(0xFFFFFFFF,"");
  190. SendClientMessageToAll(0xFFFFFFFF,"");
  191. SendClientMessageToAll(0xFFFFFFFF,"");
  192. SendClientMessageToAll(0xFFFFFFFF,"");
  193. SendClientMessageToAll(0xFFFFFFFF,"");
  194. SendClientMessageToAll(0xFFFFFFFF,"");
  195. SendClientMessageToAll(0xFFFFFFFF,"");
  196. SendClientMessageToAll(0xFFFFFFFF,"");
  197. SendClientMessageToAll(0xFFFFFFFF,"");
  198. SendClientMessageToAll(0xFFFFFFFF,"");
  199. SendClientMessageToAll(0xFFFFFFFF,"");
  200. SendClientMessageToAll(0xFFFFFFFF,"");
  201. SendClientMessageToAll(0xFFFFFFFF,"");
  202. SendClientMessageToAll(0xFFFFFFFF,"");
  203. SendClientMessageToAll(0xFFFFFFFF,"");
  204. SendClientMessageToAll(0xFFFFFFFF,"");
  205. SendClientMessageToAll(0xFFFFFFFF,"");
  206. SendClientMessageToAll(0xFFFFFFFF,"");
  207. SendClientMessageToAll(0xFFFFFFFF,"");
  208. SendClientMessageToAll(0xFFFFFFFF,"");
  209. SendClientMessageToAll(0xFFFFFFFF,"");
  210. SendClientMessageToAll(0xFFFFFFFF,"");
  211. SendClientMessageToAll(0xFFFFFFFF,"");
  212. SendClientMessageToAll(0xFFFFFFFF,"");
  213. SendClientMessageToAll(0xFFFFFFFF,"");
  214. SendClientMessageToAll(0xFFFFFFFF,"");
  215. SendClientMessageToAll(0xFFFFFFFF,"");
  216. SendClientMessageToAll(0xFFFFFFFF,"");
  217. SendClientMessageToAll(0xFFFFFFFF,"");
  218. SendClientMessageToAll(0xFFFFFFFF,"");
  219. SendClientMessageToAll(0xFFFFFFFF,"");
  220. SendClientMessageToAll(0xFFFFFFFF,"");
  221. SendClientMessageToAll(0xFFFFFFFF,"");
  222. SendClientMessageToAll(0xFFFFFFFF,"");
  223. SendClientMessageToAll(0xFFFFFFFF,"");
  224. SendClientMessageToAll(0xFFFFFFFF,"");
  225. SendClientMessageToAll(0xFFFFFFFF,"");
  226. SendClientMessageToAll(0xFFFFFFFF,"");
  227. SendClientMessageToAll(0xFFFFFFFF,"");
  228. SendClientMessageToAll(0xFFFFFFFF,"");
  229. SendClientMessageToAll(0xFFFFFFFF,"");
  230. SendClientMessageToAll(0xFFFFFFFF,"");
  231. SendClientMessageToAll(0xFFFFFFFF,"");
  232. SendClientMessageToAll(0xFFFFFFFF,"");
  233. SendClientMessageToAll(0xFFFFFFFF,"");
  234. SendClientMessageToAll(0xFFFFFFFF,"");
  235. SendClientMessageToAll(0xFFFFFFFF,"");
  236. SendClientMessageToAll(0xFFFFFFFF,"");
  237. SendClientMessageToAll(0xFFFFFFFF,"");
  238. SendClientMessageToAll(0xFFFFFFFF,"");
  239. SendClientMessageToAll(0xFFFFFFFF,"");
  240. SendClientMessageToAll(0xFFFFFFFF,"");
  241. SendClientMessageToAll(0xFFFFFFFF,"");
  242. SendClientMessageToAll(0xFFFFFFFF,"");
  243. SendClientMessageToAll(0xFFFFFFFF,"");
  244. SendClientMessageToAll(0xFFFFFFFF,"");
  245. SendClientMessageToAll(0xFFFFFFFF,"M-Admin: Administartor cleared chat!");
  246. }
  247. else
  248. {
  249. SendClientMessage(playerid,0xFF0000FF,"Error: You are not admin!");
  250. }
  251. }
  252.  
  253. public OnPlayerStateChange(playerid, newstate, oldstate)
  254. {
  255. return 1;
  256. }
  257.  
  258. public OnPlayerEnterCheckpoint(playerid)
  259. {
  260. return 1;
  261. }
  262.  
  263. public OnPlayerLeaveCheckpoint(playerid)
  264. {
  265. return 1;
  266. }
  267.  
  268. public OnPlayerEnterRaceCheckpoint(playerid)
  269. {
  270. return 1;
  271. }
  272.  
  273. public OnPlayerLeaveRaceCheckpoint(playerid)
  274. {
  275. return 1;
  276. }
  277.  
  278. public OnRconCommand(cmd[])
  279. {
  280. return 1;
  281. }
  282.  
  283. public OnPlayerRequestSpawn(playerid)
  284. {
  285. return 1;
  286. }
  287.  
  288. public OnObjectMoved(objectid)
  289. {
  290. return 1;
  291. }
  292.  
  293. public OnPlayerObjectMoved(playerid, objectid)
  294. {
  295. return 1;
  296. }
  297.  
  298. public OnPlayerPickUpPickup(playerid, pickupid)
  299. {
  300. return 1;
  301. }
  302.  
  303. public OnVehicleMod(playerid, vehicleid, componentid)
  304. {
  305. return 1;
  306. }
  307.  
  308. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  309. {
  310. return 1;
  311. }
  312.  
  313. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  314. {
  315. return 1;
  316. }
  317.  
  318. public OnPlayerSelectedMenuRow(playerid, row)
  319. {
  320. return 1;
  321. }
  322.  
  323. public OnPlayerExitedMenu(playerid)
  324. {
  325. return 1;
  326. }
  327.  
  328. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  329. {
  330. return 1;
  331. }
  332.  
  333. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  334. {
  335. return 1;
  336. }
  337.  
  338. public OnRconLoginAttempt(ip[], password[], success)
  339. {
  340. return 1;
  341. }
  342.  
  343. public OnPlayerUpdate(playerid)
  344. {
  345. return 1;
  346. }
  347.  
  348. public OnPlayerStreamIn(playerid, forplayerid)
  349. {
  350. return 1;
  351. }
  352.  
  353. public OnPlayerStreamOut(playerid, forplayerid)
  354. {
  355. return 1;
  356. }
  357.  
  358. public OnVehicleStreamIn(vehicleid, forplayerid)
  359. {
  360. return 1;
  361. }
  362.  
  363. public OnVehicleStreamOut(vehicleid, forplayerid)
  364. {
  365. return 1;
  366. }
  367.  
  368. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  369. {
  370. if(dialogid == 1)
  371. {
  372. if(response)
  373. {
  374. if(!strlen(inputtext))
  375. {
  376. ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"{FF0000}Login","{FFFFFF}Hello!\nYour account registered in server\nPlease,type your password below:","Yep","Exit");// Ïîêàçûâàåì äèàëîã âõîäà â èãðó.
  377. return 1;
  378. }
  379. new pass[64];
  380. strmid(pass,inputtext,0,strlen(inputtext),64);
  381. OnPlayerLogin(playerid,pass);
  382. }
  383. else
  384. {
  385. ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"{FF0000}Login","{FFFFFF}Hello!\nYour account registered in server\nPlease,type your password below:","Yep","Exit");// Ïîêàçûâàåì äèàëîã âõîäà â èãðó.
  386. }
  387. }
  388. if(dialogid == 2)
  389. {
  390. if(response)
  391. {
  392. if(!strlen(inputtext))
  393. {
  394. ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"{00FF00}Register","{FFFFFF}Hello!\nYour account not registered!\nType password below:","Yep","Exit");// Ïîêàçûâàåì äèàëîã ðåãèñòðàöèè.
  395. return 1;
  396. }
  397. new pass[64];
  398. strmid(pass,inputtext,0,strlen(inputtext),64);
  399. OnPlayerRegister(playerid,pass);
  400. }
  401. else
  402. {
  403. ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"{00FF00}Register","{FFFFFF}Hello!\nYour account not registered!\nType password below:","Yep","Exit");// Ïîêàçûâàåì äèàëîã ðåãèñòðàöèè.
  404. }
  405. }
  406. if(response)
  407. {
  408. switch(dialogid)
  409. {
  410. case 3:
  411. {
  412. switch(listitem)
  413. {
  414. case 0:
  415. {
  416. new strings[1000];
  417. new cash = GetPlayerMoney(playerid);
  418. new score = GetPlayerScore(playerid);
  419. new name[MAX_PLAYER_NAME];
  420. GetPlayerName(playerid, name, sizeof(name));
  421. format(strings,sizeof(strings),"{FFFFFF}Name: {00BCFF}%s\n{FFFFFF}Score: {00BCFF}%d\n{FFFFFF}Money: {00BCFF}%d",name,score,cash);
  422. ShowPlayerDialog(playerid,4,DIALOG_STYLE_MSGBOX,"Account status",strings,"Okay","");
  423. }
  424. }
  425. }
  426. }
  427. }
  428. return 1;
  429. }
  430.  
  431. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  432. {
  433. return 1;
  434. }
  435.  
  436. stock SavePlayer(playerid)
  437. {
  438. new string[64];
  439. new playername[MAX_PLAYER_NAME];
  440. GetPlayerName(playerid, playername, sizeof(playername));
  441. format(string, sizeof(string), "players/%s.ini", playername);
  442. new iniFile = ini_openFile(string);//
  443. ini_setString(iniFile,"Pass",Player[playerid][pPass]);//
  444. ini_setInteger(iniFile,"Admin",Player[playerid][pAdmin]);//
  445. ini_setInteger(iniFile,"Vip",Player[playerid][pVip]);//
  446. ini_setInteger(iniFile,"Money",Player[playerid][pMoney]);//
  447. ini_setInteger(iniFile,"Score",Player[playerid][pScore]);//
  448. ini_closeFile(iniFile);// Çàêðûâàåì ôàéë
  449. }
  450.  
  451. forward OnPlayerRegister(playerid, password[]);
  452. public OnPlayerRegister(playerid, password[])//
  453. {
  454. if(IsPlayerConnected(playerid))//
  455. {
  456. new string[64];//
  457. new playername[MAX_PLAYER_NAME];//
  458. GetPlayerName(playerid, playername, sizeof(playername));
  459. format(string,sizeof(string), "players/%s.ini", playername);
  460. new iniFile = ini_createFile(string);
  461. if(iniFile < 0)
  462. {
  463. iniFile = ini_openFile(string);
  464. }
  465. if(iniFile >= 0)
  466. {
  467. strmid(Player[playerid][pPass],password,0,strlen(password),255);
  468. ini_setString(iniFile,"Pass",Player[playerid][pPass]);
  469. ini_setInteger(iniFile,"Admin",0);
  470. ini_setInteger(iniFile,"Vip",0);
  471. ini_setInteger(iniFile,"Money",5000);
  472. ini_setInteger(iniFile,"Score",0);
  473. ini_closeFile(iniFile);
  474. ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"{FF0000}Login","{FFFFFF}Hello!\nYour account registered in server\nPlease,type your password below:","Yep","Exit");
  475. }
  476. }
  477. return 1;
  478. }
  479.  
  480. forward OnPlayerLogin(playerid,password[]);
  481. public OnPlayerLogin(playerid,password[])
  482. {
  483. if(IsPlayerConnected(playerid))
  484. {
  485. new string[64];
  486. new pass[64];
  487. new playername[MAX_PLAYER_NAME];
  488. GetPlayerName(playerid, playername, sizeof(playername));
  489. format(string,sizeof(string), "players/%s.ini", playername);
  490. new iniFile = ini_openFile(string);
  491. ini_getString(iniFile,"Pass",pass,64);
  492. ini_getInteger(iniFile,"Admin",Player[playerid][pAdmin]);
  493. ini_getInteger(iniFile,"Vip",Player[playerid][pVip]);
  494. ini_getInteger(iniFile,"Money",Player[playerid][pMoney]);
  495. ini_getInteger(iniFile,"Score",Player[playerid][pScore]);
  496. GivePlayerMoney(playerid,Player[playerid][pMoney]);
  497. if(strcmp(pass,password,true) == 0)
  498. {
  499. ini_getString(iniFile,"Pass",Player[playerid][pPass],64);
  500. ini_closeFile(iniFile);
  501. }
  502. else
  503. {
  504. ini_closeFile(iniFile);
  505. ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"{FF0000}Login","{FFFFFF}Hello!\nYour account registered in server\nPlease,type your {00FF00}correctly {FFFFFF}password below:","Yep","Exit");
  506. return 1;
  507. }
  508. SendClientMessage(playerid,0xFF00000,"Welcome to our server!");
  509. }
  510. return 1;
  511. }
  512. strtok(const string[], &index)
  513. {
  514. new length = strlen(string);
  515. while ((index < length) && (string[index] <= ' '))
  516. {
  517. index++;
  518. }
  519.  
  520. new offset = index;
  521. new result[20];
  522. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  523. {
  524. result[index - offset] = string[index];
  525. index++;
  526. }
  527. result[index - offset] = EOS;
  528. return result;
  529. }
  530.  
  531. stock GetPlayerNameEx(playerid)
  532. {
  533. new Name[MAX_PLAYER_NAME];
  534. GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
  535. return Name;
  536. }
  537. stock sscanf(string[], format[], {Float,_}:...)
  538. {
  539. #if defined isnull
  540. if (isnull(string))
  541. #else
  542. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  543. #endif
  544. {
  545. return format[0];
  546. }
  547. #pragma tabsize 4
  548. new
  549. formatPos = 0,
  550. stringPos = 0,
  551. paramPos = 2,
  552. paramCount = numargs(),
  553. delim = ' ';
  554. while (string[stringPos] && string[stringPos] <= ' ')
  555. {
  556. stringPos++;
  557. }
  558. while (paramPos < paramCount && string[stringPos])
  559. {
  560. switch (format[formatPos++])
  561. {
  562. case '\0':
  563. {
  564. return 0;
  565. }
  566. case 'i', 'd':
  567. {
  568. new
  569. neg = 1,
  570. num = 0,
  571. ch = string[stringPos];
  572. if (ch == '-')
  573. {
  574. neg = -1;
  575. ch = string[++stringPos];
  576. }
  577. do
  578. {
  579. stringPos++;
  580. if ('0' <= ch <= '9')
  581. {
  582. num = (num * 10) + (ch - '0');
  583. }
  584. else
  585. {
  586. return -1;
  587. }
  588. }
  589. while ((ch = string[stringPos]) > ' ' && ch != delim);
  590. setarg(paramPos, 0, num * neg);
  591. }
  592. case 'h', 'x':
  593. {
  594. new
  595. num = 0,
  596. ch = string[stringPos];
  597. do
  598. {
  599. stringPos++;
  600. switch (ch)
  601. {
  602. case 'x', 'X':
  603. {
  604. num = 0;
  605. continue;
  606. }
  607. case '0' .. '9':
  608. {
  609. num = (num << 4) | (ch - '0');
  610. }
  611. case 'a' .. 'f':
  612. {
  613. num = (num << 4) | (ch - ('a' - 10));
  614. }
  615. case 'A' .. 'F':
  616. {
  617. num = (num << 4) | (ch - ('A' - 10));
  618. }
  619. default:
  620. {
  621. return -1;
  622. }
  623. }
  624. }
  625. while ((ch = string[stringPos]) > ' ' && ch != delim);
  626. setarg(paramPos, 0, num);
  627. }
  628. case 'c':
  629. {
  630. setarg(paramPos, 0, string[stringPos++]);
  631. }
  632. case 'f':
  633. {
  634.  
  635. new changestr[16], changepos = 0, strpos = stringPos;
  636. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  637. {
  638. changestr[changepos++] = string[strpos++];
  639. }
  640. changestr[changepos] = '\0';
  641. setarg(paramPos,0,_:floatstr(changestr));
  642. }
  643. case 'p':
  644. {
  645. delim = format[formatPos++];
  646. continue;
  647. }
  648. case '\'':
  649. {
  650. new
  651. end = formatPos - 1,
  652. ch;
  653. while ((ch = format[++end]) && ch != '\'') {}
  654. if (!ch)
  655. {
  656. return -1;
  657. }
  658. format[end] = '\0';
  659. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  660. {
  661. if (format[end + 1])
  662. {
  663. return -1;
  664. }
  665. return 0;
  666. }
  667. format[end] = '\'';
  668. stringPos = ch + (end - formatPos);
  669. formatPos = end + 1;
  670. }
  671. case 'u':
  672. {
  673. new
  674. end = stringPos - 1,
  675. id = 0,
  676. bool:num = true,
  677. ch;
  678. while ((ch = string[++end]) && ch != delim)
  679. {
  680. if (num)
  681. {
  682. if ('0' <= ch <= '9')
  683. {
  684. id = (id * 10) + (ch - '0');
  685. }
  686. else
  687. {
  688. num = false;
  689. }
  690. }
  691. }
  692. if (num && IsPlayerConnected(id))
  693. {
  694. setarg(paramPos, 0, id);
  695. }
  696. else
  697. {
  698. #if !defined foreach
  699. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  700. #define __SSCANF_FOREACH__
  701. #endif
  702. string[end] = '\0';
  703. num = false;
  704. new
  705. name[MAX_PLAYER_NAME];
  706. id = end - stringPos;
  707. foreach (Player, playerid)
  708. {
  709. GetPlayerName(playerid, name, sizeof (name));
  710. if (!strcmp(name, string[stringPos], true, id))
  711. {
  712. setarg(paramPos, 0, playerid);
  713. num = true;
  714. break;
  715. }
  716. }
  717. if (!num)
  718. {
  719. setarg(paramPos, 0, INVALID_PLAYER_ID);
  720. }
  721. string[end] = ch;
  722. #if defined __SSCANF_FOREACH__
  723. #undef foreach
  724. #undef __SSCANF_FOREACH__
  725. #endif
  726. }
  727. stringPos = end;
  728. }
  729. case 's', 'z':
  730. {
  731. new
  732. i = 0,
  733. ch;
  734. if (format[formatPos])
  735. {
  736. while ((ch = string[stringPos++]) && ch != delim)
  737. {
  738. setarg(paramPos, i++, ch);
  739. }
  740. if (!i)
  741. {
  742. return -1;
  743. }
  744. }
  745. else
  746. {
  747. while ((ch = string[stringPos++]))
  748. {
  749. setarg(paramPos, i++, ch);
  750. }
  751. }
  752. stringPos--;
  753. setarg(paramPos, i, '\0');
  754. }
  755. default:
  756. {
  757. continue;
  758. }
  759. }
  760. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  761. {
  762. stringPos++;
  763. }
  764. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  765. {
  766. stringPos++;
  767. }
  768. paramPos++;
  769. }
  770. do
  771. {
  772. if ((delim = format[formatPos++]) > ' ')
  773. {
  774. if (delim == '\'')
  775. {
  776. while ((delim = format[formatPos++]) && delim != '\'') {}
  777. }
  778. else if (delim != 'z')
  779. {
  780. return delim;
  781. }
  782. }
  783. }
  784. while (delim > ' ');
  785. return 0;
  786. }
Advertisement
Add Comment
Please, Sign In to add comment