flagResetOnCap 2.0

Expand and mod your server.
Post Reply
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

flagResetOnCap 2.0

Post by allejo »

Author: allejo
Description: After every cap this plugin will reset all flags excluding team flags in order to keep flags evenly spread out and prevents a user from using the same flag too much.
Min Version: Tested on 2.4.0

Notes:
* This plugin only resets flags after each cap. This means this plugin will NOT reset flags in a FFA, KOTH, or Rabbit Hunt game.
* This plugin only works correctly if there is one team flag for every team, if a map has more than one team flag for each team (such as an HTF) this plugin will not work.

License: BSD

This plugin is on GitHub. Read further documentation and/or report any issues to GitHub.

Download
flagResetOnCap 2.0
Last edited by allejo on Sat Feb 18, 2012 10:15 pm, edited 10 times in total.
User avatar
mrapple
Sergeant Major
Sergeant Major
Posts: 460
Joined: Wed May 27, 2009 11:59 am
Location: Unknown
Contact:

Re: flagResetOnCap 1.0

Post by mrapple »

Great job! Glad you finally got it worked out.

The only thing I would recommend doing is making it auto-detect the number of teams so you dont have to put it in manually each time.

The only thing I think that would help you with that would be Bz_getTeamPlayerLimit which would still need a little manipulating to get it to work.

Good luck and nice work :)
Image
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

flagResetOnCap 1.0 (Parameter Based)

Post by allejo »

If you would like the plugin to have a parameter to state the number of teams playing in the CTF game use this source file.

How to load:

Code: Select all

   In a conf file add: -loadplugin /path/to/flagResetOnCap.so,<number of teams playing CTF(excluding rogue if any)>
   In the game type: /loadplugin /path/to/flagResetOnCap.so,<number of teams playing CTF(excluding rogue if any)>
Attachments
flagResetOnCap.cpp
v1.0 Parameter based
(2.03 KiB) Downloaded 180 times
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: flagResetOnCap 1.0

Post by allejo »

mrapplecomputer1 wrote:Great job! Glad you finally got it worked out.
Thanks :D
mrapplecomputer1 wrote:The only thing I would recommend doing is making it auto-detect the number of teams so you dont have to put it in manually each time.

The only thing I think that would help you with that would be Bz_getTeamPlayerLimit which would still need a little manipulating to get it to work.

Good luck and nice work :)
Done, the bz_getTeamPlayerLimit was used but not how most people would think. flagResetOnCap v1.1 automatically detects the number of teams playing but if you still like to use a parameter download flagResetOnCap v1.0, which is located right above this post. :D
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Re: flagResetOnCap 1.1

Post by Enigma »

For some reason I felt like cleaning up your code. There are a few guidelines you should be aware of: 1) Generally, you should only use variables if they are going to be used more than once in your code. 2) Do not Repeat Yourself (DRY). You should try to remove all repeat code.

Note that C++ treats any non-zero integer as true in boolean expressions. The getNumTeams() function uses this fact.

Code: Select all

#define TOTAL_CTF_TEAMS 4

unsigned int getNumTeams()
{
  return TOTAL_CTF_TEAMS - (!bz_getTeamPlayerLimit(eRedTeam) +
                            !bz_getTeamPlayerLimit(eGreenTeam) +
                            !bz_getTeamPlayerLimit(eBlueTeam) +
                            !bz_getTeamPlayerLimit(ePurpleTeam));
}

void ONCAPHandler::process ( bz_EventData *eventData )
{
  for(int i = getNumTeams(); i < bz_getNumFlags(); i++)
    bz_resetFlag(i);
}
All the code is here: http://pastebin.com/u6Y9hT1b
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: flagResetOnCap 1.1

Post by allejo »

Thank you Enigma for cleaning up my code. Small little update to the plugin. The plugin will only reset unused flags on cap.
User avatar
allejo
Breaker of Builds
Breaker of Builds
Posts: 809
Joined: Sun Feb 17, 2008 10:01 pm
Location: /dev/null
Contact:

Re: flagResetOnCap 2.0

Post by allejo »

Plugin updated to BZFlag 2.4. See first post
Post Reply