new eventorganizer[MAX_PLAYERS]; new requestingevent[MAX_PLAYERS]; new requestingtitle[MAX_PLAYERS][50]; new requestinglocation[MAX_PLAYERS][50]; new requestingdescription[MAX_PLAYERS][100]; new requestingprize[MAX_PLAYERS]; new requestingtime[MAX_PLAYERS][50]; new activeevent; new eventtitle[50]; new eventlocation[50]; new eventdescription[100]; new eventprize; new eventtime[50];
requestingevent[playerid] = 0; eventorganizer[playerid] = 0;
CMD:event(playerid, params[]) { if(activeevent == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}There is currently no active event running."); new string[300], name[MAX_PLAYER_NAME]; for(new i = 0; i < MAX_PLAYERS; i ++) { if(eventorganizer[i] == 1) { GetPlayerName(i, name, sizeof(name)); } } SendClientMessage(playerid, 0xFFFFFFFF, "-------------------------------------------"); format(string, sizeof(string), "{FFFF00}Title: %s Location: %s Time: %s", eventtile, eventlocation, eventtime); SendClientMessage(playerid, 0xFFFFFFFF, string); format(string, sizeof(string), "{FFFF00}Organizer: %s Prize: $%s", third, Comma(eventprize)); SendClientMessage(playerid, 0xFFFFFFFF, string); format(string, sizeof(string), "{FFFF00}Description: %s", eventdescription); SendClientMessage(playerid, 0xFFFFFFFF, string); SendClientMessage(playerid, 0xFFFFFFFF, "-------------------------------------------"); return 1; } CMD:e(playerid, params[]) { if(eventorganizer[playerid] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}You're not the organizer of the event."); new text[250]; if(sscanf(params, "s[250]", text)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Syntax: /e [text]"); new string[300], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); format(string, sizeof(string), "{7094DB}Event Organizer %s: %s", name, text); SendClientMessageToAll(0xFFFFFFFF, string); return 1; } CMD:cancelrequest(playerid, params[]) { if(requestingevent[playerid] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}You're not requesting an event."); requestingevent[playerid] = 0; SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Your event request has been cancelled."); return 1; } CMD:stopevent(playerid, params[]) { if(activeevent == 0 && IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}There isn't any events to stop."); if(eventorganizer[playerid] == 0 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}You're not the organizer of the event."); for(new i = 0; i < MAX_PLAYERS; i ++) { eventorganizer[i] = 0; } SendClientMessageToAll(0xFFFFFFFF, "-------------------------------------------"); SendClientMessageToAll(0xFFFFFFFF, "{FFFF00}Event over."); SendClientMessageToAll(0xFFFFFFFF, "-------------------------------------------"); activeevent = 0; return 1; } CMD:acceptevent(playerid, params[]) { if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}You're not an admin."); if(activeevent == 1) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}There's already an active event."); new evetnid; if(sscanf(params, "d", eventid)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Syntax: /acceptevent [eventid]"); if(requestingevent[eventid] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Invalid event ID."); strmid(eventtitle, requestingtitle[eventid], 0, strlen(requestingtitle[eventid])); strmid(eventlocation, requestinglocation[eventid], 0, strlen(requestinglocation[eventid])); strmid(eventdescription, requestingdescription[eventid], 0, strlen(requestingdescription[eventid])); eventprize = requestingprize[eventid]; strmid(eventtime, requestingtime[eventid], 0, strlen(requestingtime[eventid])); new string[300], name[MAX_PLAYER_NAME]; GetPlayerName(eventid, name, sizeof(name)); SendClientMessageToAll(0xFFFFFFFF, "-------------------------------------------"); format(string, sizeof(string), "{FFFF00}Event: %d Title: %s Location: %s Time: %s", eventid, eventtitle, eventlocation, eventtime); SendClientMessageToAll(0xFFFFFFFF, string); format(string, sizeof(string), "{FFFF00}Organizer: %s Prize: $%s", name, Comma(eventprize)); SendClientMessageToAll(0xFFFFFFFF, string); format(string, sizeof(string), "{FFFF00}Description: %s", eventdescription); SendClientMessageToAll(0xFFFFFFFF, string); SendClientMessageToAll(0xFFFFFFFF, "-------------------------------------------"); eventorganizer[eventid] = 1; requestingevent[eventid] = 0; activeevent = 1; return 1; } CMD:requestevent(playerid, params[]) { if(activeevent == 1) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}There's already an active event."); if(requestingevent[playerid] == 1) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}You're already requesting an event, cancel it first."); new title[50], location[50], description[100], prize, time[50]; if(sscanf(params, "p<|>s[50]s[50]s[50]s[100]d", title, location, time, description, prize)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Syntax: /requestevent [Title|Location|Time|Description|Prize]"); if(strlen(title) < 1 || strlen(title) > 50) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Invalid amount of characters in title."); if(strlen(location) < 1 || strlen(location) > 50) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Invalid amount of characters in location."); if(strlen(time) < 1 || strlen(time) > 50) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Invalid amount of characters in time."); if(strlen(description) < 1 || strlen(description) > 100) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Invalid amount of characters in description."); if(prize < 1 || prize > 5000000) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Invalid prize amount."); new string[300], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); requestingevent[playerid] = 1; strmid(requestingtitle[playerid], title, 0, strlen(title)); strmid(requestinglocation[playerid], location, 0, strlen(location)); strmid(requestingdescription[playerid], description, 0, strlen(description)); requestingprize[playerid] = prize; strmid(requestingtime[playerid], time, 0, strlen(time)); if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid, 0xFFFFFFFF, "-------------------------------------------"); for(new i = 0; i < MAX_PLAYERS; i ++) { if(IsPlayerAdmin(i)) { SendClientMessage(i, 0xFFFFFFFF, "-------------------------------------------"); } } format(string, sizeof(string), "{FFFF00}Event %d has been requested, details are below.", playerid); if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid, 0xFFFFFFFF, string); for(new i = 0; i < MAX_PLAYERS; i ++) { if(IsPlayerAdmin(i)) { SendClientMessage(i, 0xFFFFFFFF, string); } } format(string, sizeof(string), "{FFFF00}Event: %d Title: %s Location: %s Time: %s", playerid, title, location, time); if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid, 0xFFFFFFFF, string); for(new i = 0; i < MAX_PLAYERS; i ++) { if(IsPlayerAdmin(i)) { SendClientMessage(i, 0xFFFFFFFF, string); } } format(string, sizeof(string), "{FFFF00}Organizer: %s Prize: $%s", name, Comma(prize)); if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid, 0xFFFFFFFF, string); for(new i = 0; i < MAX_PLAYERS; i ++) { if(IsPlayerAdmin(i)) { SendClientMessage(i, 0xFFFFFFFF, string); } } format(string, sizeof(string), "{FFFF00}Description: %s", description); if(PlayerData[playerid][pAdmin] < 1) SendClientMessage(playerid, 0xFFFFFFFF, string); for(new i = 0; i < MAX_PLAYERS; i ++) { if(IsPlayerAdmin(i)) { SendClientMessage(i, 0xFFFFFFFF, string); } } format(string, sizeof(string), "{FFFF00}Use [/acceptevent %d] to accept this event.", playerid); for(new i = 0; i < MAX_PLAYERS; i ++) { if(IsPlayerAdmin(i)) { SendClientMessage(i, 0xFFFFFFFF, string); } } SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Your event is pending approval from an admin, please wait."); if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid, 0xFFFFFFFF, "-------------------------------------------"); for(new i = 0; i < MAX_PLAYERS; i ++) { if(IsPlayerAdmin(i)) { SendClientMessage(i, 0xFFFFFFFF, string); } } return 1; } CMD:rejectevent(playerid, params[]) { if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Only admins can use this command."); new id, reason[100]; if(sscanf(params, "us[100]", id, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Syntax: /rejectevent [eventid] [reason]"); if(requestingevent[id] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Invalid event ID."); new string[300], sendername[MAX_PLAYER_NAME], receivername[MAX_PLAYER_NAME]; requestingevent[id] = 0; GetPlayerName(playerid, sendername, sizeof(sendername)); GetPlayerName(id, receivername, sizeof(receivername)); format(string, sizeof(string), "{FFFF00}Admin %s has rejected your event, reason: %s", sendername, reason); SendClientMessage(id, 0xFFFFFFFF, string); format(string, sizeof(string), "{FFFF00}You rejected %s's event, reason: %s", receivername, reason); SendClientMessage(playerid, 0xFFFFFFFF, string); return 1; } CMD:pendingevents(playerid, params[]) { if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Only admins can use this command."); new string[1000], tmpstring[100], titlestring[100], count = 0, name[MAX_PLAYER_NAME; for(new i = 0; i < MAX_PLAYERS; i ++) { if(IsPlayerConnected(i)) { if(requestingevent[i] == 1) { GetPlayerName(i, name, sizeof(name)); format(tmpstring, sizeof(tmpstring), "Name: %s | ID: %d | Title: %s", name, i, requestingtitle[i]); strcat(string, tmpstring); count ++; } } } if(count == 0) return ShowPlayerDialog(playerid, 5345, DIALOG_STYLE_MSGBOX, "Pending Requests: 0", "There are no pending requests.", "Done", ""); format(titlestring, sizeof(titlestring), "Pending Requests: %d", count); ShowPlayerDialog(playerid, 5345, DIALOG_STYLE_LIST, titlestring, string, "Done", ""); SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Use the command /checkevent to check the pending event information."); return 1; } CMD:checkevent(playerid, params[]) { if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Only admins can use this command."); new eventid; if(sscanf(params, "u", eventid)) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Syntax: /checkevent [eventid]"); if(requestingevent[eventid] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FFFF00}Invalid event ID."); new string[300], name[MAX_PLAYER_NAME]; GetPlayerName(eventid, name, sizeof(name)); SendClientMessage(playerid, 0xFFFFFFFF, "-------------------------------------------"); format(string, sizeof(string), "{FFFF00}Title: %s Location: %s Time: %s", requestingtitle[eventid], requestinglocation[eventid], requestingtime[eventid]); SendClientMessage(playerid, 0xFFFFFFFF, string); format(string, sizeof(string), "{FFFF00}Organizer: %s Prize: $%s", name, Comma(requestingprize[eventid])); SendClientMessage(playerid, 0xFFFFFFFF, string); format(string, sizeof(string), "{FFFF00}Description: %s", requestingdescription[eventid]); SendClientMessage(playerid, 0xFFFFFFFF, string); format(string, sizeof(string), "{FFFF00}Use [/acceptevent %d] to accept this event.", eventid); SendClientMessage(playerid, 0xFFFFFFFF, string); SendClientMessage(playerid, 0xFFFFFFFF, "-------------------------------------------"); return 1; }
stock Comma(numbers) { new temp[100], counter = -1; valstr(temp, numbers); for(new i = strlen(temp);i > 0; i--) { counter++; if(counter == 3) { strins(temp, ",", i); counter = 0; } } return temp; }
MAX_PLAYERS is just a macro definition of an int..
Foreach is the definition of a macro defined for() loop (I guess, never looked into its source) It's the same thing, for() while() etc etc, it's still PAWN, it's still a loop. No matter what people use, it's the same thing over and over, but how you use it is what's important. https://sampwiki.blast.hk/wiki/Control_Structures#Loops |
Code that is using foreach = Optimized, Code that is using for(new i; i < MAX_PLAYERS; i++) is unoptimized
|
Code that is using foreach = Optimized, Code that is using for(new i; i < MAX_PLAYERS; i++) is unoptimized
|
A "for" loop is essentially a compressed "while" loop. A "for" statement has three sections; initialization, condition and finalization. |
Foreach loop. Infinite loop. Control flow. For each (or foreach) is a control flow statement for traversing items in a collection. Foreach is usually used in place of a standard for statement. |
they essentially say "do this to everything in this set", rather than "do this x times". |
Code that is using foreach = Optimized, Code that is using for(new i; i < MAX_PLAYERS; i++) is unoptimized
|
MAX_PLAYERS is just a macro definition of an int..
Foreach is the definition of a macro defined for() loop (I guess, never looked into its source) It's the same thing, for() while() etc etc, it's still PAWN, it's still a loop. No matter what people use, it's the same thing over and over, but how you use it is what's important. https://sampwiki.blast.hk/wiki/Control_Structures#Loops |