Esempio n. 1
0
void CustomFlagSample::Event(bz_EventData *eventData)
{
  switch (eventData->eventType) {

  default: {
    // no, sir, we didn't ask for THIS!!
    bz_debugMessage(1, "customflagsample: received event with unrequested eventType!");
    return;
  }

  case bz_eFlagTransferredEvent: {
    bz_FlagTransferredEventData_V1* fte = (bz_FlagTransferredEventData_V1*)eventData;
    if (strcmp(fte->flagType, "CF") == 0)
	bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Custom Flag transferred!");
    break;
  }

  case bz_eFlagGrabbedEvent: {
    bz_FlagGrabbedEventData_V1* fge = (bz_FlagGrabbedEventData_V1*)eventData;
    if (strcmp(fge->flagType, "CF") == 0)
      bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Custom Flag grabbed!");
    break;
  }

  case bz_eFlagDroppedEvent: {
    bz_FlagDroppedEventData_V1* fde = (bz_FlagDroppedEventData_V1*)eventData;
    if (strcmp(fde->flagType, "CF") == 0)
      bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Custom Flag dropped!");
    break;
  }

  case bz_eShotFiredEvent: {
    bz_ShotFiredEventData_V1* sfed = (bz_ShotFiredEventData_V1*)eventData;
    int p = sfed->playerID;
    bz_BasePlayerRecord *playerRecord = bz_getPlayerByIndex(p);
    if (!playerRecord) break;
    if (playerRecord->currentFlag == "Custom Flag (+CF)")
    {
	bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Shot fired by %s with Custom Flag!", playerRecord->callsign.c_str());
	// this user must be cool, add 10 to their score
	bz_BasePlayerRecord* player = bz_getPlayerByIndex(p);
	bz_setPlayerWins(p, player->wins+10);
    }
    break;
  }

  case bz_ePlayerDieEvent: {
    bz_PlayerDieEventData_V1* deed = (bz_PlayerDieEventData_V1*)eventData;
    bz_ApiString flag = deed->flagKilledWith;
    int p = deed->playerID;
    bz_BasePlayerRecord *playerRecord = bz_getPlayerByIndex(p);
    if (flag == "CF")
      bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Player %s killed by a player with Custom Flag!", playerRecord->callsign.c_str());
    break;
  }

  }
}
Esempio n. 2
0
void killAllTeam(int winner, bz_eTeamType teamToKill, bz_eTeamType teamToAward)
{
	bz_APIIntList *playerList = bz_newIntList();
	bz_getPlayerIndexList(playerList);

	for ( unsigned int i = 0; i < playerList->size(); i++ ){
		int player = (*playerList)[i];
		bz_BasePlayerRecord *PlayerRecord = bz_getPlayerByIndex(player);
		if (PlayerRecord->team == teamToKill)
			bz_killPlayer(player,0,winner);
		else if(PlayerRecord->team == teamToAward)
			bz_setPlayerWins(player, (bz_getPlayerWins(player)+2));
		bz_freePlayerRecord(PlayerRecord);
	}	
		
	bz_setTeamWins (teamToAward, (bz_getTeamWins(teamToAward)+1));
	bz_setTeamLosses (teamToKill, (bz_getTeamLosses (teamToKill)+1));
	
}
Esempio n. 3
0
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;
    }
}