/* this method is a joke for the ?listnewb entry for CypherJF where "all degrants/fines go to this man" */ local void giveDegrantToPlayer(const char *name, int amount) { /* share the loving... */ if (amount < 0) { Player *cplayer = pd->FindPlayer(name); /* only allow grants when he is online */ if (cplayer != NULL) { if (database->isLoaded(cplayer)) { int newAmount = -1 * amount; giveMoney(cplayer, newAmount, MONEY_TYPE_GRANT); mysql->Query(NULL, NULL, 0, "INSERT INTO hs_transactions (srcplayer, tgtplayer, action, amount) VALUES(#,#,#,#)", database->getPerPlayerData(cplayer)->id, database->getPerPlayerData(cplayer)->id, MONEY_TYPE_GRANT, newAmount); } } } /* stop the loving from above... */ }
void StartCell::onPlayerStay( PlayerTurn& turn ) { giveMoney( *turn.getPlayer() ); }
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 setMoney(Player *p, int amount, MoneyType type) { giveMoney(p, amount - getMoney(p), type); }
local void giveCommand(const char *command, const char *params, Player *p, const Target *target) { char *next; char *message; int amount = strtol(params, &next, 0); if (next == params) { chat->SendMessage(p, "Give: bad amount."); return; } while (*next == ',' || *next == ' ') next++; //remove whitespace before the message message = next; if (message[0] == '\0') { message = NULL; } if (target->type == T_PLAYER) //private command { Player *t = target->u.p; if (database->isLoaded(p)) { if (database->isLoaded(t)) { /* cfghelp: Hyperspace:MinMoney, global, int, def: 1000, mod: hscore_money * The amount of money that must be left behind when using ?give. */ int minMoney = cfg->GetInt(GLOBAL, "hyperspace", "minmoney", 1000); /* cfghelp: Hyperspace:MinGive, global, int, def: 1, mod: hscore_money * The smallest amount that can be transferred using ?give. */ int minGive = cfg->GetInt(GLOBAL, "hyperspace", "mingive", 1); /* cfghelp: Hyperspace:MaxGive, global, int, def: 100000000, mod: hscore_money * The largest amount that can be transferred using ?give. */ int maxGive = cfg->GetInt(GLOBAL, "hyperspace", "maxgive", 100000000); if (getMoney(p) - amount >= minMoney) { if (amount <= maxGive) { if (amount >= minGive) { giveMoney(t, amount, MONEY_TYPE_GIVE); giveMoney(p, -amount, MONEY_TYPE_GIVE); if (message == NULL) { chat->SendMessage(t, "Player %s gave you $%i.", p->name, amount); } else { chat->SendMessage(t, "Player %s gave you $%i. Message: \"%s\"", p->name, amount, message); } chat->SendMessage(p, "You gave %s $%i.", t->name, amount); mysql->Query(NULL, NULL, 0, "INSERT INTO hs_transactions (srcplayer, tgtplayer, action, amount) VALUES(#,#,#,#)", database->getPerPlayerData(p)->id, database->getPerPlayerData(t)->id, MONEY_TYPE_GIVE, amount); } else { chat->SendMessage(p, "You cannot give that little. The minimum is %i.", minGive); } } else { chat->SendMessage(p, "You cannot give that much. The maximium is %i.", maxGive); } } else { chat->SendMessage(p, "You must leave at least %i in your own account.", minMoney); } } else { chat->SendMessage(p, "Player %s has no data loaded.", t->name); } } else { chat->SendMessage(p, "You have no data loaded."); } } else //not private { chat->SendMessage(p, "You must target a player."); } }