local FlagTeam *GetFlagTeam(Arena *a, int freq) { DEF_AD(a); MYGLOCK; FlagTeam *team = NULL; Link *link = LLGetHead(ad->FlagTeams); int freqs = LLCount(ad->FlagTeams); for(int i = 0; i < freqs; i++) { if(link) { team = (FlagTeam*)link->data; if(team->Freq == freq) { break; } else { team = NULL; } link = link->next; } } MYGUNLOCK; if(!team) { team = CreateFlagTeam(a, freq); } return team; }
//Misc/Utilities local int getNumberOfAwers(Player *p) { LinkedList awers; int numAwers = 0; LLInit(&awers); game->IsAntiwarped(p, &awers); numAwers = LLCount(&awers); LLEmpty(&awers); return numAwers; }
local void grantCommand(const char *command, const char *params, Player *p, const Target *target) { int force = 0; int quiet = 0; char *next; char *message; int amount; while (params != NULL) //get the flags { if (strncmp(params, "-f", 2) == 0) { force = 1; } else if (strncmp(params, "-q", 2) == 0) { quiet = 1; } else { break; } params = strchr(params, ' '); if (params) //check so that params can still == NULL { params++; //we want *after* the space } } if (params == NULL) { chat->SendMessage(p, "Grant: invalid usage."); return; } amount = strtol(params, &next, 0); if (next == params) { chat->SendMessage(p, "Grant: bad amount."); return; } while (*next == ' ') next++; //remove whitespace before the message message = next; if (message[0] == '\0') { message = NULL; } //all the parsing is now complete if (target->type == T_PLAYER) //private command { Player *t = target->u.p; if (!force) { if (database->isLoaded(t)) { giveMoney(t, amount, MONEY_TYPE_GRANT); mysql->Query(NULL, NULL, 0, "INSERT INTO hs_transactions (srcplayer, tgtplayer, action, amount) VALUES(#,#,#,#)", database->getPerPlayerData(p)->id, database->getPerPlayerData(t)->id, MONEY_TYPE_GRANT, amount); giveDegrantToPlayer("CypherJF", amount); if (quiet) { chat->SendMessage(p, "Quietly granted player %s $%i.", t->name, amount); } else { char messageType; Link plink = {NULL, t}; LinkedList lst = { &plink, &plink }; if (amount > 0) messageType = MSG_ARENA; else messageType = MSG_SYSOPWARNING; if (message == NULL) { chat->SendAnyMessage(&lst, messageType, 0, NULL, "You were granted $%i.", amount); } else { chat->SendAnyMessage(&lst, messageType, 0, NULL, "You were granted $%i %s", amount, message); } chat->SendMessage(p, "Granted player %s $%i.", t->name, amount); } } else { chat->SendMessage(p, "Player %s has no data loaded.", t->name); } } else { chat->SendMessage(p, "Whoa there, bud. The -f is only for arena and freq messages."); } } else //not private { if (force) { LinkedList set = LL_INITIALIZER; Link *link; int count; int totalAmount = 0; pd->TargetToSet(target, &set); for (link = LLGetHead(&set); link; link = link->next) { Player *t = link->data; if (database->isLoaded(t)) { giveMoney(t, amount, MONEY_TYPE_GRANT); mysql->Query(NULL, NULL, 0, "INSERT INTO hs_transactions (srcplayer, tgtplayer, action, amount) VALUES(#,#,#,#)", database->getPerPlayerData(p)->id, database->getPerPlayerData(t)->id, MONEY_TYPE_GRANT, amount); totalAmount -= amount; if (!quiet) { if (message == NULL) { chat->SendMessage(t, "You were granted $%i.", amount); } else { chat->SendMessage(t, "You were granted $%i %s", amount, message); } } } else { chat->SendMessage(p, "Player %s has no data loaded.", t->name); } } count = LLCount(&set); LLEmpty(&set); giveDegrantToPlayer("CypherJF", totalAmount); chat->SendMessage(p, "You granted $%i to %i players.", amount, count); } else { chat->SendMessage(p, "For typo safety, the -f must be specified for arena and freq targets."); } } }
local void setExpCommand(const char *command, const char *params, Player *p, const Target *target) { int force = 0; int quiet = 0; char *next; char *message; int amount; while (params != NULL) //get the flags { if (strncmp(params, "-f", 2) == 0) { force = 1; } else if (strncmp(params, "-q", 2) == 0) { quiet = 1; } else { break; } params = strchr(params, ' '); if (params) //check so that params can still == NULL { params++; //we want *after* the space } } if (params == NULL) { chat->SendMessage(p, "Grantexp: invalid usage."); return; } amount = strtol(params, &next, 0); if (next == params) { chat->SendMessage(p, "Grantexp: bad amount."); return; } while (*next == ' ') next++; //remove whitespace before the message message = next; if (message[0] == '\0') { message = NULL; } //all the parsing is now complete if (target->type == T_PLAYER) //private command { Player *t = target->u.p; if (!force) { if (database->isLoaded(t)) { int oldAmount = getExp(t); setExp(t, amount); if (quiet) { chat->SendMessage(p, "Quietly set player %s's exp to %i (from %i).", t->name, amount, oldAmount); } else { if (message == NULL) { chat->SendMessage(t, "Your exp was set to %i.", amount); } else { chat->SendMessage(t, "Your exp was set to %i %s", amount, message); } chat->SendMessage(p, "Set player %s's exp to %i (from %i).", t->name, amount, oldAmount); } } else { chat->SendMessage(p, "Player %s has no data loaded.", t->name); } } else { chat->SendMessage(p, "Whoa there, bud. The -f is only for arena and freq messages."); } } else //not private { if (force) { LinkedList set = LL_INITIALIZER; Link *link; int count; pd->TargetToSet(target, &set); for (link = LLGetHead(&set); link; link = link->next) { Player *t = link->data; if (database->isLoaded(t)) { setExp(t, amount); if (!quiet) { if (message == NULL) { chat->SendMessage(t, "Your exp was set to %i.", amount); } else { chat->SendMessage(t, "Your exp was set to %i %s", amount, message); } } } else { chat->SendMessage(p, "Player %s has no data loaded.", t->name); } } count = LLCount(&set); LLEmpty(&set); chat->SendMessage(p, "You set %i players exp to %i.", count, amount); } else { chat->SendMessage(p, "For typo safety, the -f must be specified for arena and freq targets."); } } }