hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2024.06.16. 04:43



Jelenlévő felhasználók

Jelenleg 315 felhasználó van jelen :: 0 regisztrált, 0 rejtett és 315 vendég

A legtöbb felhasználó (1565 fő) 2020.11.21. 11:26-kor tartózkodott itt.

Regisztrált felhasználók: nincs regisztrált felhasználó az elmúlt 5 percben aktív felhasználók alapján

Utoljára aktív
Ahhoz hogy lásd ki volt utoljára aktív, be kell jelentkezned.



Az oldal teljeskörű
használatához regisztrálj.

Regisztráció

Kereső


Új téma nyitása  Hozzászólás a témához  [ 1 hozzászólás ] 
Szerző Üzenet
 Hozzászólás témája: Easteregg plugin átírása
HozzászólásElküldve: 2014.04.18. 15:14 
Offline
Tud valamit

Csatlakozott: 2012.01.14. 21:50
Hozzászólások: 123
Megköszönt másnak: 17 alkalommal
Megköszönték neki: 3 alkalommal
Sziasztok!

Húsvét alkalmából szeretnék feltenni a szerveremre valami húsvéti plugint, és a következőt találtam: https://forums.alliedmods.net/showthread.php?t=48703. A plugin lényege egyszerű, le lehet rakni a mapra tojásokat, amiket felszedve a játékosok pénzt kapnak. Betettem a szerverre, és össze is kötöttem az SQL-el. A probléma az, hogy elvileg az "amx_addspawnpoint" paranccsal le kéne hogy mentse a presents mappában lévő de_dust2.ini fájlba a tojás koordinátáit. A konzolba kapok egy üzenetet, hogy sikeresen lementettem, és ügyes voltam ([presentsSpawner] Your current location has been saved successfully as spawnpoint.). A fájlba is beleírja, látom a koordinátákat. A probléma az, hogy elvileg be kéne töltse a fájlból a koordinátákat, és le is kéne spawnolja, de sajnos ez nem történik meg. Valaki rá tudna nézni, hogy mi a probléma vele?
A másik gondom, hogy mivel fegyvermenü van a szerveremen, ezért nincs értéke a pénznek. Azt szeretném, ha fraget, esetleg gránátokat vagy valami hasonlókat "dobnának" a tojások.

Nagyon hálás lennék, ha valaki megcsinálná!

presentSpawner.sma
SMA Forráskód: [ Mindet kijelol ]
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <engine>
  4.  
  5.  
  6. /* Configuration */
  7.  
  8. //-----------------------------------
  9. //Only activate one of these two.
  10.  
  11. //#define XMAS
  12. #define EASTER
  13.  
  14. //-----------------------------------
  15. //Comment this if you are not using cstrike (there won't be rewards for picking up a present)
  16.  
  17. #define USING_CTRIKE
  18.  
  19. #if defined USING_CTRIKE
  20. #include <cstrike>
  21. #endif
  22.  
  23. //-----------------------------------
  24. //Maximums
  25.  
  26. #define MAX_SPAWNLOCATIONS 64
  27. #define TOTAL_COLORS 10
  28. #define EASTER_MAX_MODELS 5
  29. #define XMAS_MAX_MODELS 2
  30. //-----------------------------------
  31. //Database Info
  32.  
  33. //Comment this to not use a database
  34. //#define USING_DATABASE
  35.  
  36. #define DATABASE_HOST "*****"
  37. #define DATABASE_USERNAME "*****"
  38. #define DATABASE_PASSWORD "*****"
  39. #define DATABASE_DATABASE "*****"
  40.  
  41. #if defined USING_DATABASE
  42. #include <sqlx>
  43. #endif
  44.  
  45. /* End configuration */
  46.  
  47. #pragma semicolon 1
  48.  
  49. new gcvar_removePresents;
  50. new gcvar_presentAmount;
  51.  
  52. new g_orginFilePath[256];
  53.  
  54. new Float:g_spawnOrigins[MAX_SPAWNLOCATIONS][3];
  55. new g_totalOrigins;
  56.  
  57. #if defined USING_DATABASE
  58. new Handle:g_loginData;
  59. new Handle:g_connection;
  60. #endif
  61.  
  62. new Float:colors[TOTAL_COLORS][3] =
  63. {
  64. {95.0, 200.0, 255.0},
  65. {0.0, 150.0, 255.0},
  66. {180.0, 255.0, 175.0},
  67. {0.0, 155.0, 0.0},
  68. {255.0, 255.0, 255.0},
  69. {255.0, 190.0, 90.0},
  70. {222.0, 110.0, 0.0},
  71. {192.0, 192.0, 192.0},
  72. {190.0, 100.0, 10.0},
  73. {0.0, 0.0, 0.0}
  74. };
  75.  
  76. //----------------------------------------------------------------------------
  77. // Init
  78. //----------------------------------------------------------------------------
  79. public plugin_init()
  80. {
  81. #if defined USING_DATABASE
  82. register_plugin("presentsSpawner", "1.5_SQL", "MaximusBrood");
  83. #else
  84. register_plugin("presentsSpawner", "1.5", "MaximusBrood");
  85. #endif
  86.  
  87. register_dictionary("presentsspawner.txt");
  88.  
  89. //Commands
  90. register_clcmd("amx_addspawnpoint", "cmd_addSpawn", ADMIN_RCON, "- add a spawnpoint at your current location");
  91. register_clcmd("amx_spawnpresent", "cmd_spawnPresent", ADMIN_RCON, "- Spawns an egg with money in it");
  92. register_clcmd("amx_removepresents", "cmd_removePresents", ADMIN_RCON, "- Remove all presents from the map");
  93.  
  94. #if defined USING_DATABASE
  95. register_clcmd("say", "cmd_say");
  96. #endif
  97.  
  98. //Cvars
  99. gcvar_removePresents = register_cvar("sv_removepresents", "1");
  100. gcvar_presentAmount = register_cvar("sv_presentamount", "3");
  101.  
  102. #if defined USING_DATABASE
  103. register_cvar("presentsSpawner_version", "1.5_SQL", FCVAR_SERVER);
  104. #else
  105. register_cvar("presentsSpawner_version", "1.5", FCVAR_SERVER);
  106. #endif
  107.  
  108. //Events
  109. register_logevent("event_roundStart", 2, "1=Round_Start");
  110. register_touch("maximusbroodPresent", "player", "event_presentTouch");
  111.  
  112. //Get the path to the origin file
  113. new filepath[256];
  114. get_datadir(filepath, 255);
  115.  
  116. new mapname[32];
  117. get_mapname(mapname, 31);
  118.  
  119. format(g_orginFilePath, 255, "%s/presents/%s.ini", filepath, mapname);
  120.  
  121. //Load the locations
  122. loadData();
  123.  
  124. #if defined USING_DATABASE
  125. SQL_SetAffinity("mysql");
  126.  
  127. //Create login tuple
  128. g_loginData = SQL_MakeDbTuple(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_DATABASE);
  129.  
  130. //Connect for the simple query
  131. database_connect();
  132. #endif
  133. }
  134.  
  135. #if defined USING_DATABASE
  136. public plugin_end()
  137. {
  138. if(g_connection && g_connection != Empty_Handle)
  139. SQL_FreeHandle(g_connection);
  140. }
  141. #endif
  142.  
  143. public plugin_precache()
  144. {
  145. #if defined EASTER
  146. for(new a = 1; a <= EASTER_MAX_MODELS; ++a)
  147. formatPrecache_model("models/easteregg%d.mdl", a);
  148. #endif
  149.  
  150. #if defined XMAS
  151. for(new a = 1; a <= XMAS_MAX_MODELS; ++a)
  152. formatPrecache_model("models/xmaspresent%d.mdl", a);
  153. #endif
  154.  
  155. return PLUGIN_CONTINUE;
  156. }
  157.  
  158.  
  159. //----------------------------------------------------------------------------
  160. // File reading
  161. //----------------------------------------------------------------------------
  162.  
  163. loadData()
  164. {
  165. g_totalOrigins = 0;
  166.  
  167. //Note that we won't throw any errormessages when no presents are found
  168. new buffer[128];
  169. new strX[12], strY[12], strZ[12];
  170. if( file_exists(g_orginFilePath) )
  171. {
  172. new readPointer = fopen(g_orginFilePath, "rt");
  173.  
  174. if(!readPointer)
  175. return;
  176.  
  177. while( !feof(readPointer) )
  178. {
  179. fgets(readPointer, buffer, 127);
  180.  
  181. if(buffer[0] == ';' || !buffer[0])
  182. continue;
  183.  
  184. parse(buffer, strX, 11, strY, 11, strZ, 11);
  185.  
  186. g_spawnOrigins[g_totalOrigins][0] = float(str_to_num(strX));
  187. g_spawnOrigins[g_totalOrigins][1] = float(str_to_num(strY));
  188. g_spawnOrigins[g_totalOrigins][2] = float(str_to_num(strZ));
  189.  
  190. ++g_totalOrigins;
  191. }
  192.  
  193. fclose(readPointer);
  194. }
  195. }
  196.  
  197. //----------------------------------------------------------------------------
  198. // Commands
  199. //----------------------------------------------------------------------------
  200.  
  201. public cmd_addSpawn(id, level, cid)
  202. {
  203. if (!cmd_access(id, level, cid, 1))
  204. return PLUGIN_HANDLED;
  205.  
  206. //Check for too many spawns
  207. if(g_totalOrigins >= MAX_SPAWNLOCATIONS)
  208. {
  209. printChatAndConsole(id, "[presentsSpawner] %L", id, "MAXSPAWNS_REACHED", MAX_SPAWNLOCATIONS);
  210. return PLUGIN_CONTINUE;
  211. }
  212.  
  213. //Get the current origin
  214. new Float:currentOrigin[3];
  215. entity_get_vector(id, EV_VEC_origin, currentOrigin);
  216.  
  217. //Open the file for writing, write the origin and close up
  218. new writePointer = fopen(g_orginFilePath, "at");
  219.  
  220. if(writePointer)
  221. {
  222. server_print("Writing, coords are {%f, %f, %f} or {%d, %d, %d}", currentOrigin[0], currentOrigin[1], currentOrigin[2], floatround(currentOrigin[0]), floatround(currentOrigin[1]), floatround(currentOrigin[2]));
  223.  
  224. fprintf(writePointer, "%d %d %d^n", floatround(currentOrigin[0]), floatround(currentOrigin[1]), floatround(currentOrigin[2]) );
  225.  
  226. fclose(writePointer);
  227.  
  228. //Notify the user
  229. printChatAndConsole(id, "[presentsSpawner] %L", id, "ADD_SUCCESS");
  230.  
  231. //Reload spawnpoints
  232. loadData();
  233. } else
  234. printChatAndConsole(id, "Failed to add!");
  235.  
  236. return PLUGIN_CONTINUE;
  237. }
  238.  
  239. public cmd_spawnPresent(id, level, cid)
  240. {
  241. if (!cmd_access(id, level, cid, 1))
  242. return PLUGIN_HANDLED;
  243.  
  244. //Get the player's origin
  245. new Float:playerOrigin[3];
  246. entity_get_vector(id, EV_VEC_origin, playerOrigin);
  247.  
  248. //Pack the origin
  249. new packedOrigin[3];
  250. FVecIVec(playerOrigin, packedOrigin);
  251.  
  252. set_task(2.5, "spawnPresent", _, packedOrigin, 3);
  253.  
  254. //Don't display a message to the user, gets irritating
  255. return PLUGIN_HANDLED;
  256. }
  257.  
  258. public cmd_removePresents(id, level, cid)
  259. {
  260. if (!cmd_access(id, level, cid, 1))
  261. return PLUGIN_CONTINUE;
  262.  
  263. removePresents();
  264.  
  265. printChatAndConsole(id, "[presentsSpawner] %L", id, "REMOVED_ALL");
  266.  
  267. return PLUGIN_CONTINUE;
  268. }
  269.  
  270. #if defined USING_DATABASE
  271. public cmd_say(id)
  272. {
  273. if(id < 1)
  274. return PLUGIN_CONTINUE;
  275.  
  276. new chatMessage[191];
  277. read_args(chatMessage, 190);
  278. remove_quotes(chatMessage);
  279.  
  280. #if defined EASTER
  281. if(equali(chatMessage, "/easterrank"))
  282. {
  283. database_showRank(id);
  284. } else if(equali(chatMessage, "/eastertop10") || equali(chatMessage, "/eastertop") || equali(chatMessage, "/easterwinner"))
  285. {
  286. show_motd(id, "http://gotjuice.nl/stats/presentStats.php", "Easter Top 10");
  287. } else if(equali(chatMessage, "/easterinfo"))
  288. {
  289. show_motd(id, "http://gotjuice.nl/stats/easterInfo.html", "Easter Contest Info");
  290. } else if(equali(chatMessage, "/easternextrank"))
  291. {
  292. database_showNextRank(id);
  293. }
  294. #endif
  295.  
  296. #if defined XMAS
  297. if(equali(chatMessage, "/xmasrank"))
  298. {
  299. database_showRank(id);
  300. } else if(equali(chatMessage, "/xmastop10") || equali(chatMessage, "/xmastop") || equali(chatMessage, "/xmaswinner"))
  301. {
  302. show_motd(id, "http://gotjuice.nl/stats/presentStats.php", "Xmas Top 10");
  303. } else if(equali(chatMessage, "/xmasinfo"))
  304. {
  305. show_motd(id, "http://gotjuice.nl/stats/xmasInfo.html", "Xmas Contest Info");
  306. } else if(equali(chatMessage, "/xmasnextrank"))
  307. {
  308. database_showNextRank(id);
  309. }
  310. #endif
  311.  
  312. return PLUGIN_CONTINUE;
  313. }
  314. #endif
  315.  
  316. //----------------------------------------------------------------------------
  317. // Events
  318. //----------------------------------------------------------------------------
  319.  
  320. public event_roundStart()
  321. {
  322. //Check if there are spawnlocations to drop to
  323. if(g_totalOrigins < 0)
  324. return PLUGIN_CONTINUE;
  325.  
  326. //Get the number of players minus HLTV or bots
  327. //Only spawn presents with 2 or more real players
  328. new currPlayers, temp[32];
  329. get_players(temp, currPlayers, "ch");
  330.  
  331. if(currPlayers < 2)
  332. return PLUGIN_CONTINUE;
  333.  
  334. //Remove all eggs if requested
  335. if(get_pcvar_num(gcvar_removePresents) == 1)
  336. removePresents();
  337.  
  338. //Get the amount of eggs to drop
  339. new eggAmount = get_pcvar_num(gcvar_presentAmount);
  340.  
  341. //Plant the presents ^_-
  342. new currentOrigin[3];
  343. for(new a = 0; a < g_totalOrigins; ++a)
  344. {
  345. //Pack the origin
  346. FVecIVec(g_spawnOrigins[a], currentOrigin);
  347.  
  348. for(new b = 0; b < eggAmount; ++b)
  349. {
  350. spawnPresent(currentOrigin);
  351. }
  352. }
  353.  
  354. return PLUGIN_CONTINUE;
  355. }
  356.  
  357. public event_presentTouch(pTouched, pToucher)
  358. {
  359. //Error checking
  360. if(!is_valid_ent(pToucher) || !is_valid_ent(pTouched) || !is_user_connected(pToucher))
  361. return PLUGIN_HANDLED;
  362.  
  363. #if defined USING_CTRIKE
  364.  
  365. //Money handling for CS
  366. new randomMoney = random_num(50, 500);
  367.  
  368. cs_set_user_money(pToucher, (cs_get_user_money(pToucher) + randomMoney), 1);
  369.  
  370. #if defined EASTER
  371. client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "EASTEREGG_TOUCH_CSTRIKE", randomMoney);
  372. #endif
  373.  
  374. #if defined XMAS
  375. client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "XMASPRESENT_TOUCH_CSTRIKE", randomMoney);
  376. #endif
  377.  
  378. #if defined USING_DATABASE
  379. database_updateRecord(pToucher, randomMoney);
  380. #endif
  381.  
  382. #else
  383.  
  384. #if defined EASTER
  385. client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "EASTEREGG_TOUCH");
  386. #endif
  387.  
  388. #if defined XMAS
  389. client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "XMASPRESENT_TOUCH");
  390. #endif
  391.  
  392. #endif
  393.  
  394. //Remove the egg
  395. remove_entity(pTouched);
  396.  
  397. return PLUGIN_HANDLED;
  398. }
  399.  
  400. //----------------------------------------------------------------------------
  401. // Main Functions
  402. //----------------------------------------------------------------------------
  403.  
  404. public spawnPresent(packedOrigin[3])
  405. {
  406. //Unpack the origin
  407. new Float:origin[3];
  408. IVecFVec(packedOrigin, origin);
  409.  
  410. //Create entity and set origin and velocity
  411. new entity;
  412. entity = create_entity("info_target");
  413.  
  414. entity_set_origin(entity, origin);
  415.  
  416. new Float:velocity[3];
  417. velocity[0] = (random_float(0.0, 256.0) - 128.0);
  418. velocity[1] = (random_float(0.0, 256.0) - 128.0);
  419. velocity[2] = (random_float(0.0, 300.0) + 75.0);
  420.  
  421. entity_set_vector(entity, EV_VEC_velocity, velocity );
  422.  
  423. //Set a random model
  424. static modelName[64];
  425.  
  426. #if defined EASTER
  427. formatex(modelName, 63, "models/easteregg%d.mdl", random_num(1, EASTER_MAX_MODELS));
  428. #endif
  429.  
  430. #if defined XMAS
  431. formatex(modelName, 63, "models/xmaspresent%d.mdl", random_num(1, XMAS_MAX_MODELS));
  432. #endif
  433.  
  434. entity_set_model(entity, modelName);
  435.  
  436. //Color (75% chance)
  437. if(random_num(1, 4) > 2)
  438. {
  439. //Special effect (25% chance)
  440. if(random_num(1, 4) == 1)
  441. entity_set_int(entity, EV_INT_renderfx, kRenderFxHologram);
  442.  
  443. entity_set_vector(entity, EV_VEC_rendercolor, colors[random(TOTAL_COLORS)] );
  444.  
  445. entity_set_int(entity, EV_INT_renderfx, kRenderFxGlowShell);
  446. entity_set_float(entity, EV_FL_renderamt, 1000.0);
  447. entity_set_int(entity, EV_INT_rendermode, kRenderTransAlpha);
  448. }
  449.  
  450. //The rest of the properties
  451. entity_set_string(entity, EV_SZ_classname, "maximusbroodPresent");
  452. entity_set_int(entity, EV_INT_effects, 32);
  453. entity_set_int(entity, EV_INT_solid, SOLID_TRIGGER);
  454. entity_set_int(entity, EV_INT_movetype, MOVETYPE_TOSS);
  455.  
  456. return PLUGIN_CONTINUE;
  457. }
  458.  
  459. removePresents()
  460. {
  461. new currentEntity;
  462.  
  463. while ( (currentEntity = find_ent_by_class(currentEntity, "maximusbroodPresent")) != 0)
  464. {
  465. remove_entity(currentEntity);
  466. }
  467. }
  468.  
  469. //----------------------------------------------------------------------------
  470. // Database Functions
  471. //----------------------------------------------------------------------------
  472. #if defined USING_DATABASE
  473.  
  474. stock database_connect()
  475. {
  476. new errorCode, strError[128];
  477.  
  478. //Make the actual connection
  479. g_connection = SQL_Connect(g_loginData, errorCode, strError, 127);
  480.  
  481. //Check for errors
  482. if(g_connection == Empty_Handle)
  483. {
  484. //Log the error to file
  485. log_amx("Error while connecting to MySQL host %s with user %s", DATABASE_HOST, DATABASE_USERNAME);
  486. log_amx("Errorcode %d: %s", errorCode, strError);
  487. }
  488. }
  489.  
  490. //%%% Command showRank %%%
  491. stock database_showRank(id)
  492. {
  493. static authid[32], strQuery[256];
  494.  
  495. get_user_authid(id, authid, 31);
  496.  
  497. formatex(strQuery, 255, "SELECT rank, presentAmount, moneyAmount FROM presentStats WHERE authid = '%s';", authid);
  498.  
  499. //Send the playerid with the query
  500. new data[1];
  501. data[0] = id;
  502.  
  503. SQL_ThreadQuery(g_loginData, "database_rankCallback", strQuery, data, 1);
  504. }
  505.  
  506. public database_rankCallback(failstate, Handle:query, error[], errnum, data[], size)
  507. {
  508. //new queryerror[256];
  509. //SQL_QueryError (query, queryerror, 255);
  510. //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror);
  511.  
  512. //Check if the user is still ingame
  513. if(!is_user_connected(data[0]))
  514. return PLUGIN_HANDLED;
  515.  
  516. new rank, presents, money;
  517.  
  518. if(failstate)
  519. {
  520. client_print(data[0], print_chat, "The presents statistics are currently offline.");
  521. } else
  522. {
  523. //Check if the query did match a row
  524. if(SQL_NumResults(query) != 0)
  525. {
  526. //We only need to get 3 columns, next row is impossible and undesirable
  527. rank = SQL_ReadResult(query, 0);
  528. presents = SQL_ReadResult(query, 1);
  529. money = SQL_ReadResult(query, 2);
  530.  
  531. #if defined EASTER
  532. if(rank > 0)
  533. client_print(data[0], print_chat, "Your rank is #%d with %d presents containing %d dollars. Happy Easter!", rank, presents, money);
  534. else
  535. client_print(data[0], print_chat, "Your rank hasn't been calculated yet, but you collected %d presents containing %d dollars. Happy Easter!", presents, money);
  536. #endif
  537.  
  538. #if defined XMAS
  539. if(rank > 0)
  540. client_print(data[0], print_chat, "Your rank is #%d with %d presents containing %d dollars. Happy Xmas!", rank, presents, money);
  541. else
  542. client_print(data[0], print_chat, "Your rank hasn't been calculated yet, but you collected %d presents containing %d dollars. Happy Xmas!", presents, money);
  543. #endif
  544.  
  545. } else
  546. {
  547. client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents.");
  548. }
  549. }
  550.  
  551. return PLUGIN_HANDLED;
  552. }
  553.  
  554. //%%% Show Next Rank %%%
  555. stock database_showNextRank(id)
  556. {
  557. static authid[32], strQuery[256];
  558.  
  559. get_user_authid(id, authid, 31);
  560.  
  561. formatex(strQuery, 255, "SELECT rank, presentAmount FROM presentStats WHERE authid = '%s';", authid);
  562.  
  563. //Send the playerid with the query
  564. new data[1];
  565. data[0] = id;
  566.  
  567. SQL_ThreadQuery(g_loginData, "database_nextRankCallbackOne", strQuery, data, 1);
  568. }
  569.  
  570. public database_nextRankCallbackOne(failstate, Handle:query, error[], errnum, data[], size)
  571. {
  572. //new queryerror[256];
  573. //SQL_QueryError (query, queryerror, 255);
  574. //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror);
  575.  
  576. //Check if the user is still ingame
  577. if(!is_user_connected(data[0]))
  578. return PLUGIN_HANDLED;
  579.  
  580. new rank, presents;
  581. static strQuery[256];
  582.  
  583. if(failstate)
  584. {
  585. client_print(data[0], print_chat, "The presents statistics are currently offline.");
  586. } else
  587. {
  588. //Check if the query did match a row
  589. if(SQL_NumResults(query) != 0)
  590. {
  591. //We only need to get 2 columns, next row is impossible and undesirable
  592. rank = SQL_ReadResult(query, 0);
  593. presents = SQL_ReadResult(query, 1);
  594.  
  595. //You can't be better than #1
  596. if(rank == 1)
  597. {
  598. client_print(data[0], print_chat, "You are #1. There isn't anyone above you!");
  599. return PLUGIN_HANDLED;
  600. }
  601.  
  602. //Make a new query that checks for the next ranking person.
  603. formatex(strQuery, 255, "SELECT rank, presentAmount FROM presentStats WHERE presentAmount > %d ORDER BY presentAmount ASC LIMIT 1", presents);
  604.  
  605. //Pack the id and amount of presents and do the query
  606. new newData[2];
  607. newData[0] = data[0];
  608. newData[1] = presents;
  609.  
  610. SQL_ThreadQuery(g_loginData, "database_nextRankCallbackTwo", strQuery, newData, 2);
  611.  
  612. } else
  613. {
  614. client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents.");
  615. }
  616. }
  617.  
  618. return PLUGIN_HANDLED;
  619. }
  620.  
  621. public database_nextRankCallbackTwo(failstate, Handle:query, error[], errnum, data[], size)
  622. {
  623. //new queryerror[256];
  624. //SQL_QueryError (query, queryerror, 255);
  625. //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror);
  626.  
  627. //Check if the user is still ingame
  628. if(!is_user_connected(data[0]))
  629. return PLUGIN_HANDLED;
  630.  
  631. if(failstate)
  632. {
  633. client_print(data[0], print_chat, "The presents statistics are currently offline.");
  634. } else
  635. {
  636. //Check if the query did match a row
  637. if(SQL_NumResults(query) != 0)
  638. {
  639. //Get two columns, one row
  640. new aboveRank = SQL_ReadResult(query, 0);
  641. new abovePresents = SQL_ReadResult(query, 1);
  642.  
  643. //Output the final message to the client
  644. client_print(data[0], print_chat, "You need %d more presents to go to #%d.", ((abovePresents - data[1]) + 1), aboveRank );
  645. } else
  646. {
  647. client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents.");
  648. }
  649. }
  650.  
  651. return PLUGIN_HANDLED;
  652. }
  653.  
  654. //%%% Update player record %%%
  655. stock database_updateRecord(id, money)
  656. {
  657. //Check for database connection
  658. if(g_connection == Empty_Handle)
  659. return;
  660.  
  661. static authid[32], query[256], errorMessage[2], errorNum;
  662.  
  663. get_user_authid(id, authid, 31);
  664.  
  665. formatex(query, 255, "INSERT INTO presentStats VALUES('%s', 0, 1, %d) ON DUPLICATE KEY UPDATE presentAmount=presentAmount+1, moneyAmount=moneyAmount+%d;", authid, money, money);
  666.  
  667. //We discard the successfullness
  668. SQL_SimpleQuery (g_connection, query, errorMessage, 1, errorNum);
  669. }
  670.  
  671. #endif
  672. //----------------------------------------------------------------------------
  673. // Helpers
  674. //----------------------------------------------------------------------------
  675.  
  676. stock printChatAndConsole(id, text[], ...)
  677. {
  678. static buffer[128];
  679.  
  680. vformat(buffer, 127, text, 3);
  681.  
  682. client_print(id, print_chat, "%s", buffer);
  683. client_print(id, print_console, "%s", buffer);
  684. }
  685.  
  686. stock formatPrecache_model(name[], ...)
  687. {
  688. static buffer[256];
  689.  
  690. vformat(buffer, 255, name, 2);
  691.  
  692. precache_model(buffer);
  693. }
  694. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  695. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par }
  696. */



presentSpawnerSQL.sma
SMA Forráskód: [ Mindet kijelol ]
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <engine>
  4.  
  5.  
  6. /* Configuration */
  7.  
  8. //-----------------------------------
  9. //Only activate one of these two.
  10.  
  11. //#define XMAS
  12. #define EASTER
  13.  
  14. //-----------------------------------
  15. //Comment this if you are not using cstrike (there won't be rewards for picking up a present)
  16.  
  17. #define USING_CTRIKE
  18.  
  19. #if defined USING_CTRIKE
  20. #include <cstrike>
  21. #endif
  22.  
  23. //-----------------------------------
  24. //Maximums
  25.  
  26. #define MAX_SPAWNLOCATIONS 64
  27. #define TOTAL_COLORS 10
  28. #define EASTER_MAX_MODELS 5
  29. #define XMAS_MAX_MODELS 2
  30. //-----------------------------------
  31. //Database Info
  32.  
  33. //Comment this to not use a database
  34. #define USING_DATABASE
  35.  
  36. #define DATABASE_HOST "*****"
  37. #define DATABASE_USERNAME "*****"
  38. #define DATABASE_PASSWORD "*****"
  39. #define DATABASE_DATABASE "*****"
  40.  
  41. #if defined USING_DATABASE
  42. #include <sqlx>
  43. #endif
  44.  
  45. /* End configuration */
  46.  
  47. #pragma semicolon 1
  48.  
  49. new gcvar_removePresents;
  50. new gcvar_presentAmount;
  51.  
  52. new g_orginFilePath[256];
  53.  
  54. new Float:g_spawnOrigins[MAX_SPAWNLOCATIONS][3];
  55. new g_totalOrigins;
  56.  
  57. #if defined USING_DATABASE
  58. new Handle:g_loginData;
  59. new Handle:g_connection;
  60. #endif
  61.  
  62. new Float:colors[TOTAL_COLORS][3] =
  63. {
  64. {95.0, 200.0, 255.0},
  65. {0.0, 150.0, 255.0},
  66. {180.0, 255.0, 175.0},
  67. {0.0, 155.0, 0.0},
  68. {255.0, 255.0, 255.0},
  69. {255.0, 190.0, 90.0},
  70. {222.0, 110.0, 0.0},
  71. {192.0, 192.0, 192.0},
  72. {190.0, 100.0, 10.0},
  73. {0.0, 0.0, 0.0}
  74. };
  75.  
  76. //----------------------------------------------------------------------------
  77. // Init
  78. //----------------------------------------------------------------------------
  79. public plugin_init()
  80. {
  81. register_plugin("presentsSpawner", "1.0_SQL", "MaximusBrood");
  82. register_dictionary("presentsspawner.txt");
  83.  
  84. //Commands
  85. register_clcmd("amx_addspawnpoint", "cmd_addSpawn", ADMIN_RCON, "- add a spawnpoint at your current location");
  86. register_clcmd("amx_spawnpresent", "cmd_spawnPresent", ADMIN_RCON, "- Spawns an egg with money in it");
  87. register_clcmd("amx_removepresents", "cmd_removePresents", ADMIN_RCON, "- Remove all presents from the map");
  88.  
  89. #if defined USING_DATABASE
  90. register_clcmd("say", "cmd_say");
  91. #endif
  92.  
  93. //Cvars
  94. gcvar_removePresents = register_cvar("sv_removepresents", "1");
  95. gcvar_presentAmount = register_cvar("sv_presentamount", "3");
  96.  
  97. //Events
  98. register_logevent("event_roundStart", 2, "1=Round_Start");
  99. register_touch("maximusbroodPresent", "player", "event_presentTouch");
  100.  
  101. //Get the path to the origin file
  102. new filepath[256];
  103. get_datadir(filepath, 255);
  104.  
  105. new mapname[32];
  106. get_mapname(mapname, 31);
  107.  
  108. format(g_orginFilePath, 255, "%s/presents/%s.ini", filepath, mapname);
  109.  
  110. //Load the locations
  111. loadData();
  112.  
  113. #if defined USING_DATABASE
  114. SQL_SetAffinity("mysql");
  115.  
  116. //Create login tuple
  117. g_loginData = SQL_MakeDbTuple(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_DATABASE);
  118.  
  119. //Connect for the simple query
  120. database_connect();
  121. #endif
  122. }
  123.  
  124. #if defined USING_DATABASE
  125. public plugin_end()
  126. {
  127. if(g_connection && g_connection != Empty_Handle)
  128. SQL_FreeHandle(g_connection);
  129. }
  130. #endif
  131.  
  132. public plugin_precache()
  133. {
  134. #if defined EASTER
  135. for(new a = 1; a <= EASTER_MAX_MODELS; ++a)
  136. formatPrecache_model("models/easteregg%d.mdl", a);
  137. #endif
  138.  
  139. #if defined XMAS
  140. for(new a = 1; a <= XMAS_MAX_MODELS; ++a)
  141. formatPrecache_model("models/xmaspresent%d.mdl", a);
  142. #endif
  143.  
  144. return PLUGIN_CONTINUE;
  145. }
  146.  
  147.  
  148. //----------------------------------------------------------------------------
  149. // File reading
  150. //----------------------------------------------------------------------------
  151.  
  152. loadData()
  153. {
  154. g_totalOrigins = 0;
  155.  
  156. //Note that we won't throw any errormessages when no presents are found
  157. new buffer[128];
  158. new strX[12], strY[12], strZ[12];
  159. if( file_exists(g_orginFilePath) )
  160. {
  161. new readPointer = fopen(g_orginFilePath, "rt");
  162.  
  163. if(!readPointer)
  164. return;
  165.  
  166. while( !feof(readPointer) )
  167. {
  168. fgets(readPointer, buffer, 127);
  169.  
  170. if(buffer[0] == ';' || !buffer[0])
  171. continue;
  172.  
  173. parse(buffer, strX, 11, strY, 11, strZ, 11);
  174.  
  175. g_spawnOrigins[g_totalOrigins][0] = float(str_to_num(strX));
  176. g_spawnOrigins[g_totalOrigins][1] = float(str_to_num(strY));
  177. g_spawnOrigins[g_totalOrigins][2] = float(str_to_num(strZ));
  178.  
  179. ++g_totalOrigins;
  180. }
  181.  
  182. fclose(readPointer);
  183. }
  184. }
  185.  
  186. //----------------------------------------------------------------------------
  187. // Commands
  188. //----------------------------------------------------------------------------
  189.  
  190. public cmd_addSpawn(id, level, cid)
  191. {
  192. if (!cmd_access(id, level, cid, 1))
  193. return PLUGIN_HANDLED;
  194.  
  195. //Check for too many spawns
  196. if(g_totalOrigins >= MAX_SPAWNLOCATIONS)
  197. {
  198. printChatAndConsole(id, "[presentsSpawner] %L", id, "MAXSPAWNS_REACHED", MAX_SPAWNLOCATIONS);
  199. return PLUGIN_CONTINUE;
  200. }
  201.  
  202. //Get the current origin
  203. new Float:currentOrigin[3];
  204. entity_get_vector(id, EV_VEC_origin, currentOrigin);
  205.  
  206. //Open the file for writing, write the origin and close up
  207. new writePointer = fopen(g_orginFilePath, "at");
  208.  
  209. if(writePointer)
  210. {
  211. server_print("Writing, coords are {%f, %f, %f} or {%d, %d, %d}", currentOrigin[0], currentOrigin[1], currentOrigin[2], floatround(currentOrigin[0]), floatround(currentOrigin[1]), floatround(currentOrigin[2]));
  212.  
  213. fprintf(writePointer, "%d %d %d^n", floatround(currentOrigin[0]), floatround(currentOrigin[1]), floatround(currentOrigin[2]) );
  214.  
  215. fclose(writePointer);
  216.  
  217. //Notify the user
  218. printChatAndConsole(id, "[presentsSpawner] %L", id, "ADD_SUCCESS");
  219.  
  220. //Reload spawnpoints
  221. loadData();
  222. } else
  223. printChatAndConsole(id, "Failed to add!");
  224.  
  225. return PLUGIN_CONTINUE;
  226. }
  227.  
  228. public cmd_spawnPresent(id, level, cid)
  229. {
  230. if (!cmd_access(id, level, cid, 1))
  231. return PLUGIN_HANDLED;
  232.  
  233. //Get the player's origin
  234. new Float:playerOrigin[3];
  235. entity_get_vector(id, EV_VEC_origin, playerOrigin);
  236.  
  237. //Pack the origin
  238. new packedOrigin[3];
  239. FVecIVec(playerOrigin, packedOrigin);
  240.  
  241. set_task(2.5, "spawnPresent", _, packedOrigin, 3);
  242.  
  243. //Don't display a message to the user, gets irritating
  244. return PLUGIN_HANDLED;
  245. }
  246.  
  247. public cmd_removePresents(id, level, cid)
  248. {
  249. if (!cmd_access(id, level, cid, 1))
  250. return PLUGIN_CONTINUE;
  251.  
  252. removePresents();
  253.  
  254. printChatAndConsole(id, "[presentsSpawner] %L", id, "REMOVED_ALL");
  255.  
  256. return PLUGIN_CONTINUE;
  257. }
  258.  
  259. #if defined USING_DATABASE
  260. public cmd_say(id)
  261. {
  262. if(id < 1)
  263. return PLUGIN_CONTINUE;
  264.  
  265. new chatMessage[191];
  266. read_args(chatMessage, 190);
  267. remove_quotes(chatMessage);
  268.  
  269. #if defined EASTER
  270. if(equali(chatMessage, "/easterrank"))
  271. {
  272. database_showRank(id);
  273. } else if(equali(chatMessage, "/eastertop10") || equali(chatMessage, "/eastertop") || equali(chatMessage, "/easterwinner"))
  274. {
  275. show_motd(id, "http://gotjuice.nl/stats/presentStats.php", "Easter Top 10");
  276. } else if(equali(chatMessage, "/easterinfo"))
  277. {
  278. show_motd(id, "http://gotjuice.nl/stats/easterInfo.html", "Easter Contest Info");
  279. } else if(equali(chatMessage, "/easternextrank"))
  280. {
  281. database_showNextRank(id);
  282. }
  283. #endif
  284.  
  285. #if defined XMAS
  286. if(equali(chatMessage, "/xmasrank"))
  287. {
  288. database_showRank(id);
  289. } else if(equali(chatMessage, "/xmastop10") || equali(chatMessage, "/xmastop") || equali(chatMessage, "/xmaswinner"))
  290. {
  291. show_motd(id, "http://gotjuice.nl/stats/presentStats.php", "Xmas Top 10");
  292. } else if(equali(chatMessage, "/xmasinfo"))
  293. {
  294. show_motd(id, "http://gotjuice.nl/stats/xmasInfo.html", "Xmas Contest Info");
  295. } else if(equali(chatMessage, "/xmasnextrank"))
  296. {
  297. database_showNextRank(id);
  298. }
  299. #endif
  300.  
  301. return PLUGIN_CONTINUE;
  302. }
  303. #endif
  304.  
  305. //----------------------------------------------------------------------------
  306. // Events
  307. //----------------------------------------------------------------------------
  308.  
  309. public event_roundStart()
  310. {
  311. //Check if there are spawnlocations to drop to
  312. if(g_totalOrigins < 0)
  313. return PLUGIN_CONTINUE;
  314.  
  315. //Get the number of players minus HLTV or bots
  316. //Only spawn presents with 2 or more real players
  317. new currPlayers, temp[32];
  318. get_players(temp, currPlayers, "ch");
  319.  
  320. if(currPlayers < 2)
  321. return PLUGIN_CONTINUE;
  322.  
  323. //Remove all eggs if requested
  324. if(get_pcvar_num(gcvar_removePresents) == 1)
  325. removePresents();
  326.  
  327. //Get the amount of eggs to drop
  328. new eggAmount = get_pcvar_num(gcvar_presentAmount);
  329.  
  330. //Plant the presents ^_-
  331. new currentOrigin[3];
  332. for(new a = 0; a < g_totalOrigins; ++a)
  333. {
  334. //Pack the origin
  335. FVecIVec(g_spawnOrigins[a], currentOrigin);
  336.  
  337. for(new b = 0; b < eggAmount; ++b)
  338. {
  339. spawnPresent(currentOrigin);
  340. }
  341. }
  342.  
  343. return PLUGIN_CONTINUE;
  344. }
  345.  
  346. public event_presentTouch(pTouched, pToucher)
  347. {
  348. //Error checking
  349. if(!is_valid_ent(pToucher) || !is_valid_ent(pTouched) || !is_user_connected(pToucher))
  350. return PLUGIN_HANDLED;
  351.  
  352. #if defined USING_CTRIKE
  353.  
  354. //Money handling for CS
  355. new randomMoney = random_num(50, 500);
  356.  
  357. cs_set_user_money(pToucher, (cs_get_user_money(pToucher) + randomMoney), 1);
  358.  
  359. #if defined EASTER
  360. client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "EASTEREGG_TOUCH_CSTRIKE", randomMoney);
  361. #endif
  362.  
  363. #if defined XMAS
  364. client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "XMASPRESENT_TOUCH_CSTRIKE", randomMoney);
  365. #endif
  366.  
  367. #if defined USING_DATABASE
  368. database_updateRecord(pToucher, randomMoney);
  369. #endif
  370.  
  371. #else
  372.  
  373. #if defined EASTER
  374. client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "EASTEREGG_TOUCH");
  375. #endif
  376.  
  377. #if defined XMAS
  378. client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "XMASPRESENT_TOUCH");
  379. #endif
  380.  
  381. #endif
  382.  
  383. //Remove the egg
  384. remove_entity(pTouched);
  385.  
  386. return PLUGIN_HANDLED;
  387. }
  388.  
  389. //----------------------------------------------------------------------------
  390. // Main Functions
  391. //----------------------------------------------------------------------------
  392.  
  393. public spawnPresent(packedOrigin[3])
  394. {
  395. //Unpack the origin
  396. new Float:origin[3];
  397. IVecFVec(packedOrigin, origin);
  398.  
  399. //Create entity and set origin and velocity
  400. new entity;
  401. entity = create_entity("info_target");
  402.  
  403. entity_set_origin(entity, origin);
  404.  
  405. new Float:velocity[3];
  406. velocity[0] = (random_float(0.0, 256.0) - 128.0);
  407. velocity[1] = (random_float(0.0, 256.0) - 128.0);
  408. velocity[2] = (random_float(0.0, 300.0) + 75.0);
  409.  
  410. entity_set_vector(entity, EV_VEC_velocity, velocity );
  411.  
  412. //Set a random model
  413. static modelName[64];
  414.  
  415. #if defined EASTER
  416. formatex(modelName, 63, "models/easteregg%d.mdl", random_num(1, EASTER_MAX_MODELS));
  417. #endif
  418.  
  419. #if defined XMAS
  420. formatex(modelName, 63, "models/xmaspresent%d.mdl", random_num(1, XMAS_MAX_MODELS));
  421. #endif
  422.  
  423. entity_set_model(entity, modelName);
  424.  
  425. //Color (75% chance)
  426. if(random_num(1, 4) > 2)
  427. {
  428. //Special effect (25% chance)
  429. if(random_num(1, 4) == 1)
  430. entity_set_int(entity, EV_INT_renderfx, kRenderFxHologram);
  431.  
  432. entity_set_vector(entity, EV_VEC_rendercolor, colors[random(TOTAL_COLORS)] );
  433.  
  434. entity_set_int(entity, EV_INT_renderfx, kRenderFxGlowShell);
  435. entity_set_float(entity, EV_FL_renderamt, 1000.0);
  436. entity_set_int(entity, EV_INT_rendermode, kRenderTransAlpha);
  437. }
  438.  
  439. //The rest of the properties
  440. entity_set_string(entity, EV_SZ_classname, "maximusbroodPresent");
  441. entity_set_int(entity, EV_INT_effects, 32);
  442. entity_set_int(entity, EV_INT_solid, SOLID_TRIGGER);
  443. entity_set_int(entity, EV_INT_movetype, MOVETYPE_TOSS);
  444.  
  445. return PLUGIN_CONTINUE;
  446. }
  447.  
  448. removePresents()
  449. {
  450. new currentEntity;
  451.  
  452. while ( (currentEntity = find_ent_by_class(currentEntity, "maximusbroodPresent")) != 0)
  453. {
  454. remove_entity(currentEntity);
  455. }
  456. }
  457.  
  458. //----------------------------------------------------------------------------
  459. // Database Functions
  460. //----------------------------------------------------------------------------
  461. #if defined USING_DATABASE
  462.  
  463. stock database_connect()
  464. {
  465. new errorCode, strError[128];
  466.  
  467. //Make the actual connection
  468. g_connection = SQL_Connect(g_loginData, errorCode, strError, 127);
  469.  
  470. //Check for errors
  471. if(g_connection == Empty_Handle)
  472. {
  473. //Log the error to file
  474. log_amx("Error while connecting to MySQL host %s with user %s", DATABASE_HOST, DATABASE_USERNAME);
  475. log_amx("Errorcode %d: %s", errorCode, strError);
  476. }
  477. }
  478.  
  479. //%%% Command showRank %%%
  480. stock database_showRank(id)
  481. {
  482. static authid[32], strQuery[256];
  483.  
  484. get_user_authid(id, authid, 31);
  485.  
  486. formatex(strQuery, 255, "SELECT rank, presentAmount, moneyAmount FROM presentStats WHERE authid = '%s';", authid);
  487.  
  488. //Send the playerid with the query
  489. new data[1];
  490. data[0] = id;
  491.  
  492. SQL_ThreadQuery(g_loginData, "database_rankCallback", strQuery, data, 1);
  493. }
  494.  
  495. public database_rankCallback(failstate, Handle:query, error[], errnum, data[], size)
  496. {
  497. //new queryerror[256];
  498. //SQL_QueryError (query, queryerror, 255);
  499. //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror);
  500.  
  501. //Check if the user is still ingame
  502. if(!is_user_connected(data[0]))
  503. return PLUGIN_HANDLED;
  504.  
  505. new rank, presents, money;
  506.  
  507. if(failstate)
  508. {
  509. client_print(data[0], print_chat, "The presents statistics are currently offline.");
  510. } else
  511. {
  512. //Check if the query did match a row
  513. if(SQL_NumResults(query) != 0)
  514. {
  515. //We only need to get 3 columns, next row is impossible and undesirable
  516. rank = SQL_ReadResult(query, 0);
  517. presents = SQL_ReadResult(query, 1);
  518. money = SQL_ReadResult(query, 2);
  519.  
  520. #if defined EASTER
  521. if(rank > 0)
  522. client_print(data[0], print_chat, "Your rank is #%d with %d presents containing %d dollars. Happy Easter!", rank, presents, money);
  523. else
  524. client_print(data[0], print_chat, "Your rank hasn't been calculated yet, but you collected %d presents containing %d dollars. Happy Easter!", presents, money);
  525. #endif
  526.  
  527. #if defined XMAS
  528. if(rank > 0)
  529. client_print(data[0], print_chat, "Your rank is #%d with %d presents containing %d dollars. Happy Xmas!", rank, presents, money);
  530. else
  531. client_print(data[0], print_chat, "Your rank hasn't been calculated yet, but you collected %d presents containing %d dollars. Happy Xmas!", presents, money);
  532. #endif
  533.  
  534. } else
  535. {
  536. client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents.");
  537. }
  538. }
  539.  
  540. return PLUGIN_HANDLED;
  541. }
  542.  
  543. //%%% Show Next Rank %%%
  544. stock database_showNextRank(id)
  545. {
  546. static authid[32], strQuery[256];
  547.  
  548. get_user_authid(id, authid, 31);
  549.  
  550. formatex(strQuery, 255, "SELECT rank, presentAmount FROM presentStats WHERE authid = '%s';", authid);
  551.  
  552. //Send the playerid with the query
  553. new data[1];
  554. data[0] = id;
  555.  
  556. SQL_ThreadQuery(g_loginData, "database_nextRankCallbackOne", strQuery, data, 1);
  557. }
  558.  
  559. public database_nextRankCallbackOne(failstate, Handle:query, error[], errnum, data[], size)
  560. {
  561. //new queryerror[256];
  562. //SQL_QueryError (query, queryerror, 255);
  563. //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror);
  564.  
  565. //Check if the user is still ingame
  566. if(!is_user_connected(data[0]))
  567. return PLUGIN_HANDLED;
  568.  
  569. new rank, presents;
  570. static strQuery[256];
  571.  
  572. if(failstate)
  573. {
  574. client_print(data[0], print_chat, "The presents statistics are currently offline.");
  575. } else
  576. {
  577. //Check if the query did match a row
  578. if(SQL_NumResults(query) != 0)
  579. {
  580. //We only need to get 2 columns, next row is impossible and undesirable
  581. rank = SQL_ReadResult(query, 0);
  582. presents = SQL_ReadResult(query, 1);
  583.  
  584. //You can't be better than #1
  585. if(rank == 1)
  586. {
  587. client_print(data[0], print_chat, "You are #1. There isn't anyone above you!");
  588. return PLUGIN_HANDLED;
  589. }
  590.  
  591. //Make a new query that checks for the next ranking person.
  592. formatex(strQuery, 255, "SELECT rank, presentAmount FROM presentStats WHERE presentAmount > %d ORDER BY presentAmount ASC LIMIT 1", presents);
  593.  
  594. //Pack the id and amount of presents and do the query
  595. new newData[2];
  596. newData[0] = data[0];
  597. newData[1] = presents;
  598.  
  599. SQL_ThreadQuery(g_loginData, "database_nextRankCallbackTwo", strQuery, newData, 2);
  600.  
  601. } else
  602. {
  603. client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents.");
  604. }
  605. }
  606.  
  607. return PLUGIN_HANDLED;
  608. }
  609.  
  610. public database_nextRankCallbackTwo(failstate, Handle:query, error[], errnum, data[], size)
  611. {
  612. //new queryerror[256];
  613. //SQL_QueryError (query, queryerror, 255);
  614. //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror);
  615.  
  616. //Check if the user is still ingame
  617. if(!is_user_connected(data[0]))
  618. return PLUGIN_HANDLED;
  619.  
  620. if(failstate)
  621. {
  622. client_print(data[0], print_chat, "The presents statistics are currently offline.");
  623. } else
  624. {
  625. //Check if the query did match a row
  626. if(SQL_NumResults(query) != 0)
  627. {
  628. //Get two columns, one row
  629. new aboveRank = SQL_ReadResult(query, 0);
  630. new abovePresents = SQL_ReadResult(query, 1);
  631.  
  632. //Output the final message to the client
  633. client_print(data[0], print_chat, "You need %d more presents to go to #%d.", ((abovePresents - data[1]) + 1), aboveRank );
  634. } else
  635. {
  636. client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents.");
  637. }
  638. }
  639.  
  640. return PLUGIN_HANDLED;
  641. }
  642.  
  643. //%%% Update player record %%%
  644. stock database_updateRecord(id, money)
  645. {
  646. //Check for database connection
  647. if(g_connection == Empty_Handle)
  648. return;
  649.  
  650. static authid[32], query[256], errorMessage[2], errorNum;
  651.  
  652. get_user_authid(id, authid, 31);
  653.  
  654. formatex(query, 255, "INSERT INTO presentStats VALUES('%s', 0, 1, %d) ON DUPLICATE KEY UPDATE presentAmount=presentAmount+1, moneyAmount=moneyAmount+%d;", authid, money, money);
  655.  
  656. //We discard the successfullness
  657. SQL_SimpleQuery (g_connection, query, errorMessage, 1, errorNum);
  658. }
  659.  
  660. #endif
  661. //----------------------------------------------------------------------------
  662. // Helpers
  663. //----------------------------------------------------------------------------
  664.  
  665. stock printChatAndConsole(id, text[], ...)
  666. {
  667. static buffer[128];
  668.  
  669. vformat(buffer, 127, text, 3);
  670.  
  671. client_print(id, print_chat, "%s", buffer);
  672. client_print(id, print_console, "%s", buffer);
  673. }
  674.  
  675. stock formatPrecache_model(name[], ...)
  676. {
  677. static buffer[256];
  678.  
  679. vformat(buffer, 255, name, 2);
  680.  
  681. precache_model(buffer);
  682. }
  683. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  684. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par }
  685. */
  686.  


Hozzászólás jelentése
Vissza a tetejére
   
Hozzászólások megjelenítése:  Rendezés  
Új téma nyitása  Hozzászólás a témához  [ 1 hozzászólás ] 


Ki van itt

Jelenlévő fórumozók: nincs regisztrált felhasználó valamint 27 vendég


Nyithatsz új témákat ebben a fórumban.
Válaszolhatsz egy témára ebben a fórumban.
Nem szerkesztheted a hozzászólásaidat ebben a fórumban.
Nem törölheted a hozzászólásaidat ebben a fórumban.
Nem küldhetsz csatolmányokat ebben a fórumban.

Keresés:
Ugrás:  
Powered by phpBB® Forum Software © phpBB Limited
Magyar fordítás © Magyar phpBB Közösség
Portal: Kiss Portal Extension © Michael O'Toole