04.07.2017, 06:22
Hey guys, I have two questions.
First is whenever I try adding the include y_ini it crashes my whole gamemode, and I'm really not sure why. These are my includes.
Now, the next question is a bit of a different story.
I just finished changing this code so that it can be done whilst the player affected is offline, but it's super long and repetitive. I was wondering if there's any either simpler way of doing things or a way to optimize this code. If so, if it isn't too much to ask could you please explain why you chose to do it the method you do it, and why it works (if they aren't the same question). Thanks so much.
First is whenever I try adding the include y_ini it crashes my whole gamemode, and I'm really not sure why. These are my includes.
Код:
#include <a_samp> #include <core> #include <fixes> #include <zcmd> #include <sscanf2> #include <streamer> #include <a_mysql> #include <foreach> //#include <YSI\y_ini> #include <YSI\y_iterate> #include <YSI\y_timers>
I just finished changing this code so that it can be done whilst the player affected is offline, but it's super long and repetitive. I was wondering if there's any either simpler way of doing things or a way to optimize this code. If so, if it isn't too much to ask could you please explain why you chose to do it the method you do it, and why it works (if they aren't the same question). Thanks so much.
Код:
CMD:setvip(playerid, params[]) { new string[250], length, name[24], level, query[250], join[80], expire[80], PlayerID, ban, NZD; if(PlayerInfo[playerid][AdminLevel] < 4) return 0; if(sscanf(params, "s[24]dd", name, level, length)) return SendClientMessage(playerid, WHITE, "Usage: /setvip [Player Name] [Level] [Length 0, 1, 6, 12]"); if(level < 0 || level > 3) return SendClientMessage(playerid, RED, "Error: Invalid VIP Level"); mysql_format(ServerMySQL, query, sizeof(query), "SELECT `Name`, `uID` FROM `Users` WHERE Name='%s'", name); // You need to fetch player IP first new Cache:d = mysql_query(ServerMySQL, query); if(cache_num_rows()) { PlayerID = cache_get_field_content_int(0, "uID"); mysql_format(ServerMySQL, query,sizeof(query), "SELECT `NZT` FROM `Inventory` WHERE uID=%d",PlayerID); new Cache:i = mysql_query(ServerMySQL, query); if(cache_num_rows()) { NZD = cache_get_field_content_int(0, "NZT"); mysql_format(ServerMySQL, query,sizeof(query), "SELECT `Bank` FROM `Ownered` WHERE uID=%d",PlayerID); new Cache:b = mysql_query(ServerMySQL, query); if(cache_num_rows()) { ban = cache_get_field_content_int(0, "Bank"); mysql_format(ServerMySQL, query, sizeof(query), "SELECT `VIP` FROM `Users` WHERE Name='%s'", name); new Cache:c = mysql_query(ServerMySQL, query); if (!cache_affected_rows(ServerMySQL)) { cache_delete©; return SendClientMessage(playerid, RED, "[Admin Notice] - Player is already VIP."); } if(length == 0) { format(string,sizeof(string), "[Admin Log]: %s has removed %s VIP.", PlayerName(playerid), name); SendMessageToAdmins(COLOR_ADMIN, string, 1); strmid(join, "-", 0, strlen("-"), 255); strmid(expire, "-", 0, strlen("-"), 255); mysql_format(ServerMySQL,query,sizeof(query), "UPDATE `Users` SET `VIP`=%d, `VIPJoinDate`='%s', `VIPExpireDate`='%s' WHERE `Name`='%s'", 0, join, expire, name); mysql_tquery(ServerMySQL, query, "", ""); } else if(level == 1) { if(length == 1) { // SendClientMessage(ID, COLOR_VIP1, "You have been promoted to VIP Level 1. Thank you for supporting the server."); format(string,sizeof(string), "%s has given %s VIP Level 1 for 1 month.", PlayerName(playerid), name); SendMessageToAdmins(COLOR_ADMIN, string, 1); new Year, Month, Day; getdate(Year, Month, Day); format(string,32,"%02d/%02d/%02d", Day, Month, Year); strmid(join, string, 0, strlen(string), 255); format(string, 32, "%02d/%02d/%d", Day, Month +1, Year); strmid(expire, string, 0, strlen(string), 255); if(Month == 12) { format(expire, 32, "%02d/%02d/%d", Day,1, Year +1); } format(string, sizeof(string), "[D/M/Y] Join Date: %s | Expire Date: %s", join, expire); //SendClientMessage(ID, COLOR_VIP1, str); SendClientMessage(playerid, ORANGE, string); NZD += 5; ban += 300000; //Locker[ID][NZT]+=5; //Ownered[ID][Bank]=Ownered[ID][Bank]+300000; mysql_format(ServerMySQL,query,sizeof(query), "UPDATE `Users` SET `VIP`=%d, `VIPJoinDate`='%s', `VIPExpireDate`='%s' WHERE `Name`='%s'", 1, join, expire, name); mysql_tquery(ServerMySQL, query, "", ""); } if(length == 6) { //if(PlayerInfo[ID][VIP] > 1)return SendClientMessage(playerid, RED, "Error: Player is already VIP."); //PlayerInfo[ID][VIP] = 1; //SendClientMessage(ID, COLOR_VIP1, "You have been promoted to VIP Level 1. Thank you for supporting the server."); format(string,sizeof(string), "%s has given %s VIP Level 1 for 6 months.", PlayerName(playerid), name); new Year, Month, Day; getdate(Year, Month, Day); format(string,32,"%02d/%02d/%02d", Day, Month, Year); strmid(join, string, 0, strlen(string), 255); format(string, 32, "%02d/%02d/%d", Day, Month +6, Year); strmid(expire, string, 0, strlen(string), 255); if(Month == 12) { format(expire, 32, "%02d/%02d/%d", Day, 1, Year +1); } format(string, sizeof(string), "[D/M/Y] Join Date: %s | Expire Date: %s", join,expire); // SendClientMessage(ID, COLOR_VIP1, string); SendClientMessage(playerid, ORANGE, string); //Locker[ID][NZT]+=10; //Ownered[ID][Bank]=Ownered[ID][Bank]+600000; NZD += 10; ban += 600000; mysql_format(ServerMySQL,query,sizeof(query), "UPDATE `Users` SET `VIP`=%d, `VIPJoinDate`='%s', `VIPExpireDate`='%s' WHERE `Name`='%s'", 1, join, expire, name); mysql_tquery(ServerMySQL, query, "", ""); } if(length == 12) { //if(PlayerInfo[ID][VIP] > 1)return SendClientMessage(playerid, RED, "Error: Player is already VIP."); //PlayerInfo[ID][VIP] = 1; //SendClientMessage(ID, COLOR_VIP1, "You have been promoted to VIP Level 1. Thank you for supporting the server."); format(string,sizeof(string), "%s has given %s VIP Level 1 for 12 months.", PlayerName(playerid), name); SendMessageToAdmins(COLOR_ADMIN, string, 1); new Year, Month, Day; getdate(Year, Month, Day); format(string,32,"%02d/%02d/%02d", Day, Month, Year); strmid(join, string, 0, strlen(string), 255); format(string, 32, "%02d/%02d/%d", Day, Month, Year +1); strmid(expire, string, 0, strlen(string), 255); if(Month == 12) { format(expire, 32, "%02d/%02d/%d", Day, 1, Year +1); } format(string, sizeof(string), "[D/M/Y] Join Date: %s | Expire Date: %s", join,expire); // SendClientMessage(ID, COLOR_VIP1, string); SendClientMessage(playerid, ORANGE, string); NZD += 12; ban += 1200000; //Locker[ID][NZT]+=12; //Ownered[ID][Bank]=Ownered[ID][Bank]; mysql_format(ServerMySQL,query,sizeof(query), "UPDATE `Users` SET `VIP`=%d, `VIPJoinDate`='%s', `VIPExpireDate`='%s' WHERE `Name`='%s'", 1, join, expire, name); mysql_tquery(ServerMySQL, query, "", ""); } } else if(level == 2) { if(length == 1) { //if(PlayerInfo[ID][VIP] > 1)return SendClientMessage(playerid, RED, "Error: Player is already VIP."); //PlayerInfo[ID][VIP] = 2; //SendClientMessage(ID, COLOR_VIP2, "You have been promoted to VIP Level 2. Thank you for supporting the server."); format(string,sizeof(string), "%s has given %s VIP Level 2 for 1 month.", PlayerName(playerid), name); SendMessageToAdmins(COLOR_ADMIN, string, 1); new Year, Month, Day; getdate(Year, Month, Day); format(string,32,"%02d/%02d/%02d", Day, Month, Year); strmid(join, string, 0, strlen(string), 255); format(string, 32, "%02d/%02d/%d", Day, Month +1, Year); strmid(expire, string, 0, strlen(string), 255); if(Month == 12) { format(expire, 32, "%02d/%02d/%d", Day,1, Year +1); } format(string, sizeof(string), "[D/M/Y] Join Date: %s | Expire Date: %s", join,expire); //SendClientMessage(ID, COLOR_VIP2, string); SendClientMessage(playerid, ORANGE, string); //Locker[ID][NZT]+=15; //Ownered[ID][Bank]=Ownered[ID][Bank]+750000; NZD += 15; ban += 750000; mysql_format(ServerMySQL,query,sizeof(query), "UPDATE `Users` SET `VIP`=%d, `VIPJoinDate`='%s', `VIPExpireDate`='%s' WHERE `Name`='%s'", 2, join, expire, name); mysql_tquery(ServerMySQL, query, "", ""); } if(length == 6) { //if(PlayerInfo[ID][VIP] > 1)return SendClientMessage(playerid, RED, "Error: Player is already VIP."); //PlayerInfo[ID][VIP] = 2; //SendClientMessage(ID, COLOR_VIP2, "You have been promoted to VIP Level 2. Thank you for supporting the server."); format(string,sizeof(string), "%s has given %s VIP Level 2 for 6 months.", PlayerName(playerid), name); SendMessageToAdmins(COLOR_ADMIN, string, 1); new Year, Month, Day; getdate(Year, Month, Day); format(string,32,"%02d/%02d/%02d", Day, Month, Year); strmid(join, string, 0, strlen(string), 255); format(string, 32, "%02d/%02d/%d", Day, Month +6, Year); strmid(expire, string, 0, strlen(string), 255); if(Month == 12) { format(expire, 32, "%02d/%02d/%d", Day, 1, Year +1); } format(string, sizeof(string), "[D/M/Y] Join Date: %s | Expire Date: %s", join,expire); //SendClientMessage(ID, COLOR_VIP2, string); SendClientMessage(playerid, ORANGE, string); NZD += 20; ban += 1500000; mysql_format(ServerMySQL,query,sizeof(query), "UPDATE `Users` SET `VIP`=%d, `VIPJoinDate`='%s', `VIPExpireDate`='%s' WHERE `Name`='%s'", 2, join, expire, name); mysql_tquery(ServerMySQL, query, "", ""); } if(length == 12) { //if(PlayerInfo[ID][VIP] > 1)return SendClientMessage(playerid, RED, "Error: Player is already VIP."); //PlayerInfo[ID][VIP] = 1; //SendClientMessage(ID, COLOR_VIP1, "You have been promoted to VIP Level 1. Thank you for supporting the server."); format(string,sizeof(string), "%s has given %s VIP Level 1 for 12 months.", PlayerName(playerid), name); SendMessageToAdmins(COLOR_ADMIN, string, 1); new Year, Month, Day; getdate(Year, Month, Day); format(string,32,"%02d/%02d/%02d", Day, Month, Year); strmid(join, string, 0, strlen(string), 255); format(string, 32, "%02d/%02d/%d", Day, Month, Year +1); strmid(expire, string, 0, strlen(string), 255); if(Month == 12) { format(expire, 32, "%02d/%02d/%d", Day, 1, Year +1); } format(string, sizeof(string), "[D/M/Y] Join Date: %s | Expire Date: %s", join, expire); //SendClientMessage(ID, COLOR_VIP1, string); SendClientMessage(playerid, ORANGE, string); NZD += 25; ban += 5000000; mysql_format(ServerMySQL,query,sizeof(query), "UPDATE `Users` SET `VIP`=%d, `VIPJoinDate`='%s', `VIPExpireDate`='%s' WHERE `Name`='%s'", 2, join, expire, name); mysql_tquery(ServerMySQL, query, "", ""); } } foreach(new p : Player) { GetPlayerName(p, string, 24); if(!strcmp(string, name, true)) { if(length == 0) { SendClientMessage(p, ORANGE, "Your VIP has been removed by an Administrator"); } if(length == 1 && level == 1) { SendClientMessage(p, COLOR_VIP1, "You have been promoted to VIP Level 1. Thank you for supporting the server."); SendClientMessage(p, ORANGE, "Use /vipdate in order to see when your VIP is set to expire."); } if(length == 1 && level == 2) { SendClientMessage(p, COLOR_VIP2, "You have been promoted to VIP Level 2. Thank you for supporting the server."); SendClientMessage(p, ORANGE, "Use /vipdate in order to see when your VIP is set to expire."); } if(length == 6 && level == 1) { SendClientMessage(p, COLOR_VIP1, "You have been promoted to VIP Level 1. Thank you for supporting the server."); SendClientMessage(p, ORANGE, "Use /vipdate in order to see when your VIP is set to expire."); } if(length == 6 && level == 2) { SendClientMessage(p, COLOR_VIP2, "You have been promoted to VIP Level 2. Thank you for supporting the server."); SendClientMessage(p, ORANGE, "Use /vipdate in order to see when your VIP is set to expire."); } if(length == 12 && level == 1) { SendClientMessage(p, COLOR_VIP1, "You have been promoted to VIP Level 1. Thank you for supporting the server."); SendClientMessage(p, ORANGE, "Use /vipdate in order to see when your VIP is set to expire."); } if(length == 12 && level == 2) { SendClientMessage(p, COLOR_VIP2, "You have been promoted to VIP Level 2. Thank you for supporting the server."); SendClientMessage(p, ORANGE, "Use /vipdate in order to see when your VIP is set to expire."); } break; } cache_delete©; } cache_delete(b); } cache_delete(i); } } cache_delete(d); return 1; }