void flagResetTimerHandler::Event(bz_EventData *eventData) { switch (eventData->eventType) { case bz_eTickEvent: { double timeLimitSeconds = timeLimitMinutes*60; std::string flagname = bz_getName(0).c_str(); if(flagname=="R*" || flagname=="G*" || flagname=="B*" || flagname=="P*") { gameStyle = "ctf"; } if(nextReset<bz_getCurrentTime()) { if(gameStyle=="ctf") { for(unsigned int i = getNumTeams(); i < bz_getNumFlags(); i++) { if(bz_flagPlayer(i)==-1) bz_resetFlag(i); } } else { for(unsigned int i = 0; i < bz_getNumFlags(); i++) { if(bz_flagPlayer(i)==-1) bz_resetFlag(i); } } nextReset = bz_getCurrentTime()+timeLimitSeconds; } } break; default:break; } }
void BountyHunter::Event (bz_EventData *eventData) { switch (eventData->eventType) { case bz_eFlagDroppedEvent: // This event is called each time a flag is dropped by a player. { bz_FlagDroppedEventData_V1* flagDropData = (bz_FlagDroppedEventData_V1*)eventData; // Get the abbreviation of the flag that was dropped to check if it was a team flag std::string flag = bz_getName(flagDropData->flagID).c_str(); // If the dropped flag is a team flag, keep track of who dropped it and when if (flag == "R*" || flag == "G*" || flag == "B*" || flag == "P*") { lastFlagCarrier = flagDropData->playerID; teamFlagDropped = flag; flagCarryTime = bz_getCurrentTime(); } } break; case bz_ePlayerDieEvent: // This event is called each time a tank is killed. { bz_PlayerDieEventData_V1* dieData = (bz_PlayerDieEventData_V1*)eventData; int victimID = dieData->playerID; int killerID = dieData->killerID; // If the player did not kill themselves, then calculate the bounty points if (victimID != killerID) { // Increment the consecutive kills of the killer if the player is not the server (player ID 253) if (killerID != 253) { consecutiveKills[killerID]++; } // If the person killed had more than 0 kills, calculate the bounty points if (consecutiveKills[victimID] > 0) { // This value will keep track of how many levels of a rampage a player has gotten where each level // is an increment of 6 kills int rampageMultiplier = consecutiveKills[victimID] / 5; // The rampage multiplier times two will be the amount of bounty points granted int bountyPoints = rampageMultiplier * 2; // Only reward bounty points if it's greater than 0 if (bountyPoints > 0) { // Set the player's new points and notify them bz_setPlayerWins(killerID, bz_getPlayerWins(killerID) + bountyPoints); bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s earned %i bounty points stopping %s's rampage", bz_getPlayerByIndex(killerID)->callsign.c_str(), bountyPoints, bz_getPlayerByIndex(victimID)->callsign.c_str() ); } } // If the person killed was carrying a team flag less than 3 seconds ago, then reward the killer if (lastFlagCarrier == victimID && flagCarryTime + 3 > bz_getCurrentTime()) { // Store the team color std::string teamColor = ""; // Set the respective color judging by the team flag abbreviation if (teamFlagDropped == "R*") { teamColor = "red"; } else if (teamFlagDropped == "G*") { teamColor = "green"; } else if (teamFlagDropped == "B*") { teamColor = "blue"; } else if (teamFlagDropped == "P*") { teamColor = "purple"; } // Set the player's new points and notify them bz_setPlayerWins(killerID, bz_getPlayerWins(killerID) + 2); bz_sendTextMessagef(BZ_SERVER, killerID, "Shooting the %s team flag carrier has earned you 2 bounty points", teamColor.c_str()); } } // Reset the consecutive kills made by the player who just got killed consecutiveKills[victimID] = 0; } break; case bz_ePlayerJoinEvent: // This event is called each time a player joins the game { bz_PlayerJoinPartEventData_V1* joinData = (bz_PlayerJoinPartEventData_V1*)eventData; // Set a player's consecutive kills to 0 when they join in case the array has a null value consecutiveKills[joinData->playerID] = 0; } break; default: break; } }