Offline |
![Tud valamit Tud valamit](./images/ranks/hl13.png) |
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#include <amxmodx> #include <amxmisc> #include <engine> /* Configuration */ //----------------------------------- //Only activate one of these two. //#define XMAS #define EASTER //----------------------------------- //Comment this if you are not using cstrike (there won't be rewards for picking up a present) #define USING_CTRIKE #if defined USING_CTRIKE #include <cstrike> #endif //----------------------------------- //Maximums #define MAX_SPAWNLOCATIONS 64 #define TOTAL_COLORS 10 #define EASTER_MAX_MODELS 5 #define XMAS_MAX_MODELS 2 //----------------------------------- //Database Info //Comment this to not use a database //#define USING_DATABASE #define DATABASE_HOST "*****" #define DATABASE_USERNAME "*****" #define DATABASE_PASSWORD "*****" #define DATABASE_DATABASE "*****" #if defined USING_DATABASE #include <sqlx> #endif /* End configuration */ #pragma semicolon 1 new gcvar_removePresents; new gcvar_presentAmount; new g_orginFilePath[256]; new Float:g_spawnOrigins[MAX_SPAWNLOCATIONS][3]; new g_totalOrigins; #if defined USING_DATABASE new Handle:g_loginData; new Handle:g_connection; #endif new Float:colors[TOTAL_COLORS][3] = { {95.0, 200.0, 255.0}, {0.0, 150.0, 255.0}, {180.0, 255.0, 175.0}, {0.0, 155.0, 0.0}, {255.0, 255.0, 255.0}, {255.0, 190.0, 90.0}, {222.0, 110.0, 0.0}, {192.0, 192.0, 192.0}, {190.0, 100.0, 10.0}, {0.0, 0.0, 0.0} }; //---------------------------------------------------------------------------- // Init //---------------------------------------------------------------------------- public plugin_init() { #if defined USING_DATABASE register_plugin("presentsSpawner", "1.5_SQL", "MaximusBrood"); #else register_plugin("presentsSpawner", "1.5", "MaximusBrood"); #endif register_dictionary("presentsspawner.txt"); //Commands register_clcmd("amx_addspawnpoint", "cmd_addSpawn", ADMIN_RCON, "- add a spawnpoint at your current location"); register_clcmd("amx_spawnpresent", "cmd_spawnPresent", ADMIN_RCON, "- Spawns an egg with money in it"); register_clcmd("amx_removepresents", "cmd_removePresents", ADMIN_RCON, "- Remove all presents from the map"); #if defined USING_DATABASE register_clcmd("say", "cmd_say"); #endif //Cvars gcvar_removePresents = register_cvar("sv_removepresents", "1"); gcvar_presentAmount = register_cvar("sv_presentamount", "3"); #if defined USING_DATABASE register_cvar("presentsSpawner_version", "1.5_SQL", FCVAR_SERVER); #else register_cvar("presentsSpawner_version", "1.5", FCVAR_SERVER); #endif //Events register_logevent("event_roundStart", 2, "1=Round_Start"); register_touch("maximusbroodPresent", "player", "event_presentTouch"); //Get the path to the origin file new filepath[256]; get_datadir(filepath, 255); new mapname[32]; get_mapname(mapname, 31); format(g_orginFilePath, 255, "%s/presents/%s.ini", filepath, mapname); //Load the locations loadData(); #if defined USING_DATABASE SQL_SetAffinity("mysql"); //Create login tuple g_loginData = SQL_MakeDbTuple(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_DATABASE); //Connect for the simple query database_connect(); #endif } #if defined USING_DATABASE public plugin_end() { if(g_connection && g_connection != Empty_Handle) SQL_FreeHandle(g_connection); } #endif public plugin_precache() { #if defined EASTER for(new a = 1; a <= EASTER_MAX_MODELS; ++a) formatPrecache_model("models/easteregg%d.mdl", a); #endif #if defined XMAS for(new a = 1; a <= XMAS_MAX_MODELS; ++a) formatPrecache_model("models/xmaspresent%d.mdl", a); #endif return PLUGIN_CONTINUE; } //---------------------------------------------------------------------------- // File reading //---------------------------------------------------------------------------- loadData() { g_totalOrigins = 0; //Note that we won't throw any errormessages when no presents are found new buffer[128]; new strX[12], strY[12], strZ[12]; if( file_exists(g_orginFilePath) ) { new readPointer = fopen(g_orginFilePath, "rt"); if(!readPointer) return; while( !feof(readPointer) ) { fgets(readPointer, buffer, 127); if(buffer[0] == ';' || !buffer[0]) continue; parse(buffer, strX, 11, strY, 11, strZ, 11); g_spawnOrigins[g_totalOrigins][0] = float(str_to_num(strX)); g_spawnOrigins[g_totalOrigins][1] = float(str_to_num(strY)); g_spawnOrigins[g_totalOrigins][2] = float(str_to_num(strZ)); ++g_totalOrigins; } fclose(readPointer); } } //---------------------------------------------------------------------------- // Commands //---------------------------------------------------------------------------- public cmd_addSpawn(id, level, cid) { if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED; //Check for too many spawns if(g_totalOrigins >= MAX_SPAWNLOCATIONS) { printChatAndConsole(id, "[presentsSpawner] %L", id, "MAXSPAWNS_REACHED", MAX_SPAWNLOCATIONS); return PLUGIN_CONTINUE; } //Get the current origin new Float:currentOrigin[3]; entity_get_vector(id, EV_VEC_origin, currentOrigin); //Open the file for writing, write the origin and close up new writePointer = fopen(g_orginFilePath, "at"); if(writePointer) { 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])); fprintf(writePointer, "%d %d %d^n", floatround(currentOrigin[0]), floatround(currentOrigin[1]), floatround(currentOrigin[2]) ); fclose(writePointer); //Notify the user printChatAndConsole(id, "[presentsSpawner] %L", id, "ADD_SUCCESS"); //Reload spawnpoints loadData(); } else printChatAndConsole(id, "Failed to add!"); return PLUGIN_CONTINUE; } public cmd_spawnPresent(id, level, cid) { if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED; //Get the player's origin new Float:playerOrigin[3]; entity_get_vector(id, EV_VEC_origin, playerOrigin); //Pack the origin new packedOrigin[3]; FVecIVec(playerOrigin, packedOrigin); set_task(2.5, "spawnPresent", _, packedOrigin, 3); //Don't display a message to the user, gets irritating return PLUGIN_HANDLED; } public cmd_removePresents(id, level, cid) { if (!cmd_access(id, level, cid, 1)) return PLUGIN_CONTINUE; removePresents(); printChatAndConsole(id, "[presentsSpawner] %L", id, "REMOVED_ALL"); return PLUGIN_CONTINUE; } #if defined USING_DATABASE public cmd_say(id) { if(id < 1) return PLUGIN_CONTINUE; new chatMessage[191]; read_args(chatMessage, 190); remove_quotes(chatMessage); #if defined EASTER if(equali(chatMessage, "/easterrank")) { database_showRank(id); } else if(equali(chatMessage, "/eastertop10") || equali(chatMessage, "/eastertop") || equali(chatMessage, "/easterwinner")) { show_motd(id, "http://gotjuice.nl/stats/presentStats.php", "Easter Top 10"); } else if(equali(chatMessage, "/easterinfo")) { show_motd(id, "http://gotjuice.nl/stats/easterInfo.html", "Easter Contest Info"); } else if(equali(chatMessage, "/easternextrank")) { database_showNextRank(id); } #endif #if defined XMAS if(equali(chatMessage, "/xmasrank")) { database_showRank(id); } else if(equali(chatMessage, "/xmastop10") || equali(chatMessage, "/xmastop") || equali(chatMessage, "/xmaswinner")) { show_motd(id, "http://gotjuice.nl/stats/presentStats.php", "Xmas Top 10"); } else if(equali(chatMessage, "/xmasinfo")) { show_motd(id, "http://gotjuice.nl/stats/xmasInfo.html", "Xmas Contest Info"); } else if(equali(chatMessage, "/xmasnextrank")) { database_showNextRank(id); } #endif return PLUGIN_CONTINUE; } #endif //---------------------------------------------------------------------------- // Events //---------------------------------------------------------------------------- public event_roundStart() { //Check if there are spawnlocations to drop to if(g_totalOrigins < 0) return PLUGIN_CONTINUE; //Get the number of players minus HLTV or bots //Only spawn presents with 2 or more real players new currPlayers, temp[32]; get_players(temp, currPlayers, "ch"); if(currPlayers < 2) return PLUGIN_CONTINUE; //Remove all eggs if requested if(get_pcvar_num(gcvar_removePresents) == 1) removePresents(); //Get the amount of eggs to drop new eggAmount = get_pcvar_num(gcvar_presentAmount); //Plant the presents ^_- new currentOrigin[3]; for(new a = 0; a < g_totalOrigins; ++a) { //Pack the origin FVecIVec(g_spawnOrigins[a], currentOrigin); for(new b = 0; b < eggAmount; ++b) { spawnPresent(currentOrigin); } } return PLUGIN_CONTINUE; } public event_presentTouch(pTouched, pToucher) { //Error checking if(!is_valid_ent(pToucher) || !is_valid_ent(pTouched) || !is_user_connected(pToucher)) return PLUGIN_HANDLED; #if defined USING_CTRIKE //Money handling for CS new randomMoney = random_num(50, 500); cs_set_user_money(pToucher, (cs_get_user_money(pToucher) + randomMoney), 1); #if defined EASTER client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "EASTEREGG_TOUCH_CSTRIKE", randomMoney); #endif #if defined XMAS client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "XMASPRESENT_TOUCH_CSTRIKE", randomMoney); #endif #if defined USING_DATABASE database_updateRecord(pToucher, randomMoney); #endif #else #if defined EASTER client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "EASTEREGG_TOUCH"); #endif #if defined XMAS client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "XMASPRESENT_TOUCH"); #endif #endif //Remove the egg remove_entity(pTouched); return PLUGIN_HANDLED; } //---------------------------------------------------------------------------- // Main Functions //---------------------------------------------------------------------------- public spawnPresent(packedOrigin[3]) { //Unpack the origin new Float:origin[3]; IVecFVec(packedOrigin, origin); //Create entity and set origin and velocity new entity; entity = create_entity("info_target"); entity_set_origin(entity, origin); new Float:velocity[3]; velocity[0] = (random_float(0.0, 256.0) - 128.0); velocity[1] = (random_float(0.0, 256.0) - 128.0); velocity[2] = (random_float(0.0, 300.0) + 75.0); entity_set_vector(entity, EV_VEC_velocity, velocity ); //Set a random model static modelName[64]; #if defined EASTER formatex(modelName, 63, "models/easteregg%d.mdl", random_num(1, EASTER_MAX_MODELS)); #endif #if defined XMAS formatex(modelName, 63, "models/xmaspresent%d.mdl", random_num(1, XMAS_MAX_MODELS)); #endif entity_set_model(entity, modelName); //Color (75% chance) if(random_num(1, 4) > 2) { //Special effect (25% chance) if(random_num(1, 4) == 1) entity_set_int(entity, EV_INT_renderfx, kRenderFxHologram); entity_set_vector(entity, EV_VEC_rendercolor, colors[random(TOTAL_COLORS)] ); entity_set_int(entity, EV_INT_renderfx, kRenderFxGlowShell); entity_set_float(entity, EV_FL_renderamt, 1000.0); entity_set_int(entity, EV_INT_rendermode, kRenderTransAlpha); } //The rest of the properties entity_set_string(entity, EV_SZ_classname, "maximusbroodPresent"); entity_set_int(entity, EV_INT_effects, 32); entity_set_int(entity, EV_INT_solid, SOLID_TRIGGER); entity_set_int(entity, EV_INT_movetype, MOVETYPE_TOSS); return PLUGIN_CONTINUE; } removePresents() { new currentEntity; while ( (currentEntity = find_ent_by_class(currentEntity, "maximusbroodPresent")) != 0) { remove_entity(currentEntity); } } //---------------------------------------------------------------------------- // Database Functions //---------------------------------------------------------------------------- #if defined USING_DATABASE stock database_connect() { new errorCode, strError[128]; //Make the actual connection g_connection = SQL_Connect(g_loginData, errorCode, strError, 127); //Check for errors if(g_connection == Empty_Handle) { //Log the error to file log_amx("Error while connecting to MySQL host %s with user %s", DATABASE_HOST, DATABASE_USERNAME); log_amx("Errorcode %d: %s", errorCode, strError); } } //%%% Command showRank %%% stock database_showRank(id) { static authid[32], strQuery[256]; get_user_authid(id, authid, 31); formatex(strQuery, 255, "SELECT rank, presentAmount, moneyAmount FROM presentStats WHERE authid = '%s';", authid); //Send the playerid with the query new data[1]; data[0] = id; SQL_ThreadQuery(g_loginData, "database_rankCallback", strQuery, data, 1); } public database_rankCallback(failstate, Handle:query, error[], errnum, data[], size) { //new queryerror[256]; //SQL_QueryError (query, queryerror, 255); //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror); //Check if the user is still ingame if(!is_user_connected(data[0])) return PLUGIN_HANDLED; new rank, presents, money; if(failstate) { client_print(data[0], print_chat, "The presents statistics are currently offline."); } else { //Check if the query did match a row if(SQL_NumResults(query) != 0) { //We only need to get 3 columns, next row is impossible and undesirable rank = SQL_ReadResult(query, 0); presents = SQL_ReadResult(query, 1); money = SQL_ReadResult(query, 2); #if defined EASTER if(rank > 0) client_print(data[0], print_chat, "Your rank is #%d with %d presents containing %d dollars. Happy Easter!", rank, presents, money); else 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); #endif #if defined XMAS if(rank > 0) client_print(data[0], print_chat, "Your rank is #%d with %d presents containing %d dollars. Happy Xmas!", rank, presents, money); else 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); #endif } else { client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents."); } } return PLUGIN_HANDLED; } //%%% Show Next Rank %%% stock database_showNextRank(id) { static authid[32], strQuery[256]; get_user_authid(id, authid, 31); formatex(strQuery, 255, "SELECT rank, presentAmount FROM presentStats WHERE authid = '%s';", authid); //Send the playerid with the query new data[1]; data[0] = id; SQL_ThreadQuery(g_loginData, "database_nextRankCallbackOne", strQuery, data, 1); } public database_nextRankCallbackOne(failstate, Handle:query, error[], errnum, data[], size) { //new queryerror[256]; //SQL_QueryError (query, queryerror, 255); //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror); //Check if the user is still ingame if(!is_user_connected(data[0])) return PLUGIN_HANDLED; new rank, presents; static strQuery[256]; if(failstate) { client_print(data[0], print_chat, "The presents statistics are currently offline."); } else { //Check if the query did match a row if(SQL_NumResults(query) != 0) { //We only need to get 2 columns, next row is impossible and undesirable rank = SQL_ReadResult(query, 0); presents = SQL_ReadResult(query, 1); //You can't be better than #1 if(rank == 1) { client_print(data[0], print_chat, "You are #1. There isn't anyone above you!"); return PLUGIN_HANDLED; } //Make a new query that checks for the next ranking person. formatex(strQuery, 255, "SELECT rank, presentAmount FROM presentStats WHERE presentAmount > %d ORDER BY presentAmount ASC LIMIT 1", presents); //Pack the id and amount of presents and do the query new newData[2]; newData[0] = data[0]; newData[1] = presents; SQL_ThreadQuery(g_loginData, "database_nextRankCallbackTwo", strQuery, newData, 2); } else { client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents."); } } return PLUGIN_HANDLED; } public database_nextRankCallbackTwo(failstate, Handle:query, error[], errnum, data[], size) { //new queryerror[256]; //SQL_QueryError (query, queryerror, 255); //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror); //Check if the user is still ingame if(!is_user_connected(data[0])) return PLUGIN_HANDLED; if(failstate) { client_print(data[0], print_chat, "The presents statistics are currently offline."); } else { //Check if the query did match a row if(SQL_NumResults(query) != 0) { //Get two columns, one row new aboveRank = SQL_ReadResult(query, 0); new abovePresents = SQL_ReadResult(query, 1); //Output the final message to the client client_print(data[0], print_chat, "You need %d more presents to go to #%d.", ((abovePresents - data[1]) + 1), aboveRank ); } else { client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents."); } } return PLUGIN_HANDLED; } //%%% Update player record %%% stock database_updateRecord(id, money) { //Check for database connection if(g_connection == Empty_Handle) return; static authid[32], query[256], errorMessage[2], errorNum; get_user_authid(id, authid, 31); formatex(query, 255, "INSERT INTO presentStats VALUES('%s', 0, 1, %d) ON DUPLICATE KEY UPDATE presentAmount=presentAmount+1, moneyAmount=moneyAmount+%d;", authid, money, money); //We discard the successfullness SQL_SimpleQuery (g_connection, query, errorMessage, 1, errorNum); } #endif //---------------------------------------------------------------------------- // Helpers //---------------------------------------------------------------------------- stock printChatAndConsole(id, text[], ...) { static buffer[128]; vformat(buffer, 127, text, 3); client_print(id, print_chat, "%s", buffer); client_print(id, print_console, "%s", buffer); } stock formatPrecache_model(name[], ...) { static buffer[256]; vformat(buffer, 255, name, 2); precache_model(buffer); } /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par } */
presentSpawnerSQL.sma#include <amxmodx> #include <amxmisc> #include <engine> /* Configuration */ //----------------------------------- //Only activate one of these two. //#define XMAS #define EASTER //----------------------------------- //Comment this if you are not using cstrike (there won't be rewards for picking up a present) #define USING_CTRIKE #if defined USING_CTRIKE #include <cstrike> #endif //----------------------------------- //Maximums #define MAX_SPAWNLOCATIONS 64 #define TOTAL_COLORS 10 #define EASTER_MAX_MODELS 5 #define XMAS_MAX_MODELS 2 //----------------------------------- //Database Info //Comment this to not use a database #define USING_DATABASE #define DATABASE_HOST "*****" #define DATABASE_USERNAME "*****" #define DATABASE_PASSWORD "*****" #define DATABASE_DATABASE "*****" #if defined USING_DATABASE #include <sqlx> #endif /* End configuration */ #pragma semicolon 1 new gcvar_removePresents; new gcvar_presentAmount; new g_orginFilePath[256]; new Float:g_spawnOrigins[MAX_SPAWNLOCATIONS][3]; new g_totalOrigins; #if defined USING_DATABASE new Handle:g_loginData; new Handle:g_connection; #endif new Float:colors[TOTAL_COLORS][3] = { {95.0, 200.0, 255.0}, {0.0, 150.0, 255.0}, {180.0, 255.0, 175.0}, {0.0, 155.0, 0.0}, {255.0, 255.0, 255.0}, {255.0, 190.0, 90.0}, {222.0, 110.0, 0.0}, {192.0, 192.0, 192.0}, {190.0, 100.0, 10.0}, {0.0, 0.0, 0.0} }; //---------------------------------------------------------------------------- // Init //---------------------------------------------------------------------------- public plugin_init() { register_plugin("presentsSpawner", "1.0_SQL", "MaximusBrood"); register_dictionary("presentsspawner.txt"); //Commands register_clcmd("amx_addspawnpoint", "cmd_addSpawn", ADMIN_RCON, "- add a spawnpoint at your current location"); register_clcmd("amx_spawnpresent", "cmd_spawnPresent", ADMIN_RCON, "- Spawns an egg with money in it"); register_clcmd("amx_removepresents", "cmd_removePresents", ADMIN_RCON, "- Remove all presents from the map"); #if defined USING_DATABASE register_clcmd("say", "cmd_say"); #endif //Cvars gcvar_removePresents = register_cvar("sv_removepresents", "1"); gcvar_presentAmount = register_cvar("sv_presentamount", "3"); //Events register_logevent("event_roundStart", 2, "1=Round_Start"); register_touch("maximusbroodPresent", "player", "event_presentTouch"); //Get the path to the origin file new filepath[256]; get_datadir(filepath, 255); new mapname[32]; get_mapname(mapname, 31); format(g_orginFilePath, 255, "%s/presents/%s.ini", filepath, mapname); //Load the locations loadData(); #if defined USING_DATABASE SQL_SetAffinity("mysql"); //Create login tuple g_loginData = SQL_MakeDbTuple(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_DATABASE); //Connect for the simple query database_connect(); #endif } #if defined USING_DATABASE public plugin_end() { if(g_connection && g_connection != Empty_Handle) SQL_FreeHandle(g_connection); } #endif public plugin_precache() { #if defined EASTER for(new a = 1; a <= EASTER_MAX_MODELS; ++a) formatPrecache_model("models/easteregg%d.mdl", a); #endif #if defined XMAS for(new a = 1; a <= XMAS_MAX_MODELS; ++a) formatPrecache_model("models/xmaspresent%d.mdl", a); #endif return PLUGIN_CONTINUE; } //---------------------------------------------------------------------------- // File reading //---------------------------------------------------------------------------- loadData() { g_totalOrigins = 0; //Note that we won't throw any errormessages when no presents are found new buffer[128]; new strX[12], strY[12], strZ[12]; if( file_exists(g_orginFilePath) ) { new readPointer = fopen(g_orginFilePath, "rt"); if(!readPointer) return; while( !feof(readPointer) ) { fgets(readPointer, buffer, 127); if(buffer[0] == ';' || !buffer[0]) continue; parse(buffer, strX, 11, strY, 11, strZ, 11); g_spawnOrigins[g_totalOrigins][0] = float(str_to_num(strX)); g_spawnOrigins[g_totalOrigins][1] = float(str_to_num(strY)); g_spawnOrigins[g_totalOrigins][2] = float(str_to_num(strZ)); ++g_totalOrigins; } fclose(readPointer); } } //---------------------------------------------------------------------------- // Commands //---------------------------------------------------------------------------- public cmd_addSpawn(id, level, cid) { if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED; //Check for too many spawns if(g_totalOrigins >= MAX_SPAWNLOCATIONS) { printChatAndConsole(id, "[presentsSpawner] %L", id, "MAXSPAWNS_REACHED", MAX_SPAWNLOCATIONS); return PLUGIN_CONTINUE; } //Get the current origin new Float:currentOrigin[3]; entity_get_vector(id, EV_VEC_origin, currentOrigin); //Open the file for writing, write the origin and close up new writePointer = fopen(g_orginFilePath, "at"); if(writePointer) { 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])); fprintf(writePointer, "%d %d %d^n", floatround(currentOrigin[0]), floatround(currentOrigin[1]), floatround(currentOrigin[2]) ); fclose(writePointer); //Notify the user printChatAndConsole(id, "[presentsSpawner] %L", id, "ADD_SUCCESS"); //Reload spawnpoints loadData(); } else printChatAndConsole(id, "Failed to add!"); return PLUGIN_CONTINUE; } public cmd_spawnPresent(id, level, cid) { if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED; //Get the player's origin new Float:playerOrigin[3]; entity_get_vector(id, EV_VEC_origin, playerOrigin); //Pack the origin new packedOrigin[3]; FVecIVec(playerOrigin, packedOrigin); set_task(2.5, "spawnPresent", _, packedOrigin, 3); //Don't display a message to the user, gets irritating return PLUGIN_HANDLED; } public cmd_removePresents(id, level, cid) { if (!cmd_access(id, level, cid, 1)) return PLUGIN_CONTINUE; removePresents(); printChatAndConsole(id, "[presentsSpawner] %L", id, "REMOVED_ALL"); return PLUGIN_CONTINUE; } #if defined USING_DATABASE public cmd_say(id) { if(id < 1) return PLUGIN_CONTINUE; new chatMessage[191]; read_args(chatMessage, 190); remove_quotes(chatMessage); #if defined EASTER if(equali(chatMessage, "/easterrank")) { database_showRank(id); } else if(equali(chatMessage, "/eastertop10") || equali(chatMessage, "/eastertop") || equali(chatMessage, "/easterwinner")) { show_motd(id, "http://gotjuice.nl/stats/presentStats.php", "Easter Top 10"); } else if(equali(chatMessage, "/easterinfo")) { show_motd(id, "http://gotjuice.nl/stats/easterInfo.html", "Easter Contest Info"); } else if(equali(chatMessage, "/easternextrank")) { database_showNextRank(id); } #endif #if defined XMAS if(equali(chatMessage, "/xmasrank")) { database_showRank(id); } else if(equali(chatMessage, "/xmastop10") || equali(chatMessage, "/xmastop") || equali(chatMessage, "/xmaswinner")) { show_motd(id, "http://gotjuice.nl/stats/presentStats.php", "Xmas Top 10"); } else if(equali(chatMessage, "/xmasinfo")) { show_motd(id, "http://gotjuice.nl/stats/xmasInfo.html", "Xmas Contest Info"); } else if(equali(chatMessage, "/xmasnextrank")) { database_showNextRank(id); } #endif return PLUGIN_CONTINUE; } #endif //---------------------------------------------------------------------------- // Events //---------------------------------------------------------------------------- public event_roundStart() { //Check if there are spawnlocations to drop to if(g_totalOrigins < 0) return PLUGIN_CONTINUE; //Get the number of players minus HLTV or bots //Only spawn presents with 2 or more real players new currPlayers, temp[32]; get_players(temp, currPlayers, "ch"); if(currPlayers < 2) return PLUGIN_CONTINUE; //Remove all eggs if requested if(get_pcvar_num(gcvar_removePresents) == 1) removePresents(); //Get the amount of eggs to drop new eggAmount = get_pcvar_num(gcvar_presentAmount); //Plant the presents ^_- new currentOrigin[3]; for(new a = 0; a < g_totalOrigins; ++a) { //Pack the origin FVecIVec(g_spawnOrigins[a], currentOrigin); for(new b = 0; b < eggAmount; ++b) { spawnPresent(currentOrigin); } } return PLUGIN_CONTINUE; } public event_presentTouch(pTouched, pToucher) { //Error checking if(!is_valid_ent(pToucher) || !is_valid_ent(pTouched) || !is_user_connected(pToucher)) return PLUGIN_HANDLED; #if defined USING_CTRIKE //Money handling for CS new randomMoney = random_num(50, 500); cs_set_user_money(pToucher, (cs_get_user_money(pToucher) + randomMoney), 1); #if defined EASTER client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "EASTEREGG_TOUCH_CSTRIKE", randomMoney); #endif #if defined XMAS client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "XMASPRESENT_TOUCH_CSTRIKE", randomMoney); #endif #if defined USING_DATABASE database_updateRecord(pToucher, randomMoney); #endif #else #if defined EASTER client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "EASTEREGG_TOUCH"); #endif #if defined XMAS client_print(pToucher, print_chat, "[presentsSpawner] %L", pToucher, "XMASPRESENT_TOUCH"); #endif #endif //Remove the egg remove_entity(pTouched); return PLUGIN_HANDLED; } //---------------------------------------------------------------------------- // Main Functions //---------------------------------------------------------------------------- public spawnPresent(packedOrigin[3]) { //Unpack the origin new Float:origin[3]; IVecFVec(packedOrigin, origin); //Create entity and set origin and velocity new entity; entity = create_entity("info_target"); entity_set_origin(entity, origin); new Float:velocity[3]; velocity[0] = (random_float(0.0, 256.0) - 128.0); velocity[1] = (random_float(0.0, 256.0) - 128.0); velocity[2] = (random_float(0.0, 300.0) + 75.0); entity_set_vector(entity, EV_VEC_velocity, velocity ); //Set a random model static modelName[64]; #if defined EASTER formatex(modelName, 63, "models/easteregg%d.mdl", random_num(1, EASTER_MAX_MODELS)); #endif #if defined XMAS formatex(modelName, 63, "models/xmaspresent%d.mdl", random_num(1, XMAS_MAX_MODELS)); #endif entity_set_model(entity, modelName); //Color (75% chance) if(random_num(1, 4) > 2) { //Special effect (25% chance) if(random_num(1, 4) == 1) entity_set_int(entity, EV_INT_renderfx, kRenderFxHologram); entity_set_vector(entity, EV_VEC_rendercolor, colors[random(TOTAL_COLORS)] ); entity_set_int(entity, EV_INT_renderfx, kRenderFxGlowShell); entity_set_float(entity, EV_FL_renderamt, 1000.0); entity_set_int(entity, EV_INT_rendermode, kRenderTransAlpha); } //The rest of the properties entity_set_string(entity, EV_SZ_classname, "maximusbroodPresent"); entity_set_int(entity, EV_INT_effects, 32); entity_set_int(entity, EV_INT_solid, SOLID_TRIGGER); entity_set_int(entity, EV_INT_movetype, MOVETYPE_TOSS); return PLUGIN_CONTINUE; } removePresents() { new currentEntity; while ( (currentEntity = find_ent_by_class(currentEntity, "maximusbroodPresent")) != 0) { remove_entity(currentEntity); } } //---------------------------------------------------------------------------- // Database Functions //---------------------------------------------------------------------------- #if defined USING_DATABASE stock database_connect() { new errorCode, strError[128]; //Make the actual connection g_connection = SQL_Connect(g_loginData, errorCode, strError, 127); //Check for errors if(g_connection == Empty_Handle) { //Log the error to file log_amx("Error while connecting to MySQL host %s with user %s", DATABASE_HOST, DATABASE_USERNAME); log_amx("Errorcode %d: %s", errorCode, strError); } } //%%% Command showRank %%% stock database_showRank(id) { static authid[32], strQuery[256]; get_user_authid(id, authid, 31); formatex(strQuery, 255, "SELECT rank, presentAmount, moneyAmount FROM presentStats WHERE authid = '%s';", authid); //Send the playerid with the query new data[1]; data[0] = id; SQL_ThreadQuery(g_loginData, "database_rankCallback", strQuery, data, 1); } public database_rankCallback(failstate, Handle:query, error[], errnum, data[], size) { //new queryerror[256]; //SQL_QueryError (query, queryerror, 255); //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror); //Check if the user is still ingame if(!is_user_connected(data[0])) return PLUGIN_HANDLED; new rank, presents, money; if(failstate) { client_print(data[0], print_chat, "The presents statistics are currently offline."); } else { //Check if the query did match a row if(SQL_NumResults(query) != 0) { //We only need to get 3 columns, next row is impossible and undesirable rank = SQL_ReadResult(query, 0); presents = SQL_ReadResult(query, 1); money = SQL_ReadResult(query, 2); #if defined EASTER if(rank > 0) client_print(data[0], print_chat, "Your rank is #%d with %d presents containing %d dollars. Happy Easter!", rank, presents, money); else 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); #endif #if defined XMAS if(rank > 0) client_print(data[0], print_chat, "Your rank is #%d with %d presents containing %d dollars. Happy Xmas!", rank, presents, money); else 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); #endif } else { client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents."); } } return PLUGIN_HANDLED; } //%%% Show Next Rank %%% stock database_showNextRank(id) { static authid[32], strQuery[256]; get_user_authid(id, authid, 31); formatex(strQuery, 255, "SELECT rank, presentAmount FROM presentStats WHERE authid = '%s';", authid); //Send the playerid with the query new data[1]; data[0] = id; SQL_ThreadQuery(g_loginData, "database_nextRankCallbackOne", strQuery, data, 1); } public database_nextRankCallbackOne(failstate, Handle:query, error[], errnum, data[], size) { //new queryerror[256]; //SQL_QueryError (query, queryerror, 255); //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror); //Check if the user is still ingame if(!is_user_connected(data[0])) return PLUGIN_HANDLED; new rank, presents; static strQuery[256]; if(failstate) { client_print(data[0], print_chat, "The presents statistics are currently offline."); } else { //Check if the query did match a row if(SQL_NumResults(query) != 0) { //We only need to get 2 columns, next row is impossible and undesirable rank = SQL_ReadResult(query, 0); presents = SQL_ReadResult(query, 1); //You can't be better than #1 if(rank == 1) { client_print(data[0], print_chat, "You are #1. There isn't anyone above you!"); return PLUGIN_HANDLED; } //Make a new query that checks for the next ranking person. formatex(strQuery, 255, "SELECT rank, presentAmount FROM presentStats WHERE presentAmount > %d ORDER BY presentAmount ASC LIMIT 1", presents); //Pack the id and amount of presents and do the query new newData[2]; newData[0] = data[0]; newData[1] = presents; SQL_ThreadQuery(g_loginData, "database_nextRankCallbackTwo", strQuery, newData, 2); } else { client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents."); } } return PLUGIN_HANDLED; } public database_nextRankCallbackTwo(failstate, Handle:query, error[], errnum, data[], size) { //new queryerror[256]; //SQL_QueryError (query, queryerror, 255); //server_print("Data is -> id: %d [*] queryerror: %s", data[0], queryerror); //Check if the user is still ingame if(!is_user_connected(data[0])) return PLUGIN_HANDLED; if(failstate) { client_print(data[0], print_chat, "The presents statistics are currently offline."); } else { //Check if the query did match a row if(SQL_NumResults(query) != 0) { //Get two columns, one row new aboveRank = SQL_ReadResult(query, 0); new abovePresents = SQL_ReadResult(query, 1); //Output the final message to the client client_print(data[0], print_chat, "You need %d more presents to go to #%d.", ((abovePresents - data[1]) + 1), aboveRank ); } else { client_print(data[0], print_chat, "Your rank hasn't been calculated yet or you didn't pickup any presents."); } } return PLUGIN_HANDLED; } //%%% Update player record %%% stock database_updateRecord(id, money) { //Check for database connection if(g_connection == Empty_Handle) return; static authid[32], query[256], errorMessage[2], errorNum; get_user_authid(id, authid, 31); formatex(query, 255, "INSERT INTO presentStats VALUES('%s', 0, 1, %d) ON DUPLICATE KEY UPDATE presentAmount=presentAmount+1, moneyAmount=moneyAmount+%d;", authid, money, money); //We discard the successfullness SQL_SimpleQuery (g_connection, query, errorMessage, 1, errorNum); } #endif //---------------------------------------------------------------------------- // Helpers //---------------------------------------------------------------------------- stock printChatAndConsole(id, text[], ...) { static buffer[128]; vformat(buffer, 127, text, 3); client_print(id, print_chat, "%s", buffer); client_print(id, print_console, "%s", buffer); } stock formatPrecache_model(name[], ...) { static buffer[256]; vformat(buffer, 255, name, 2); precache_model(buffer); } /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1038\\ f0\\ fs16 \n\\ par } */
|
|