"Tag! your it!!!" plug-in

Expand and mod your server.
Post Reply
User avatar
TheFish
Private First Class
Private First Class
Posts: 25
Joined: Sun Nov 02, 2008 11:11 pm
Location: Texas
Contact:

"Tag! your it!!!" plug-in

Post by TheFish » Sat Apr 11, 2009 1:56 am

This is my first plug-in, its make a server a "tag" game. When you spawn you are given a SR "Steam-roller" flag, then when you tag some one else the server makes you drop the flag, they die, and when they re-spawn they get the SR flag. The more SR flags you have on your map the more people who can tag at one time.

Here is the source for the ".cpp" file.

Code: Select all

// my_first_plugin.cpp : Defines the entry point for the DLL application.
//

#include "bzfsAPI.h"

BZ_GET_PLUGIN_VERSION

bool spawnpos[256]={0};
bool shield=0;
float outspawns[5][5]={{0}};


class my_first_plugin_events : public bz_EventHandler
{
  virtual void process ( bz_EventData *eventData )
  {
     if(eventData->eventType==bz_ePlayerDieEvent)
    {
      bz_PlayerDieEventData* data = (bz_PlayerDieEventData*)eventData;
      bz_removePlayerFlag(data->killerID);
    }
     if(eventData->eventType==bz_ePlayerDieEvent)
    {
      bz_PlayerDieEventData* data = (bz_PlayerDieEventData*)eventData;
      bz_sendTextMessage(BZ_SERVER,data->playerID,"TAG YOUR IT!!!");
      bz_sendTextMessage(BZ_SERVER,data->killerID,"TAG, Your Not it any more!!!");
    }
    if(eventData->eventType==bz_ePlayerSpawnEvent)
    {
      bz_PlayerSpawnEventData* data = (bz_PlayerSpawnEventData*)eventData;
      bz_givePlayerFlag(data->playerID,"SR",0);
    }
  }

};

my_first_plugin_events my_first_plugin_events;

class my_first_plugin_slashcommands : public bz_CustomSlashCommandHandler
{

};


BZF_PLUGIN_CALL int bz_Load ( const char* commandLine )
{
  bz_debugMessage(4,"my_first_plugin plugin loaded");
  bz_registerEvent(bz_ePlayerDieEvent,&my_first_plugin_events);
  bz_registerEvent(bz_eCaptureEvent,&my_first_plugin_events);
  bz_registerEvent(bz_eGetPlayerSpawnPosEvent,&my_first_plugin_events);
  bz_registerEvent(bz_ePlayerSpawnEvent,&my_first_plugin_events);
  return 0;
}

BZF_PLUGIN_CALL int bz_Unload ( void )
{
  bz_debugMessage(4,"my_first_plugin plugin unloaded");
  bz_removeEvent(bz_ePlayerDieEvent,&my_first_plugin_events);
  bz_removeEvent(bz_eCaptureEvent,&my_first_plugin_events);
  bz_removeEvent(bz_eGetPlayerSpawnPosEvent,&my_first_plugin_events);
  bz_removeEvent(bz_ePlayerSpawnEvent,&my_first_plugin_events);
  return 0;
}

// Local Variables: ***
// mode:C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
Thank you flaying-popcorn for the plug-in writing tutorial.
http://my.bzflag.org/bb/viewtopic.php?f ... 62&start=0
Last edited by TheFish on Thu May 14, 2009 3:55 am, edited 1 time in total.
oof.wav

User avatar
Bambino
Private First Class
Private First Class
Posts: 1210
Joined: Mon Apr 21, 2008 10:27 pm
Location: Alberta, Canada

Re: "Tag! your it!!!" plug-in

Post by Bambino » Sat Apr 11, 2009 2:57 am

Yeah, I was on it and basically what happens is,
someone has SR and he kills you, now you're "it"
you spawn and instantly grab SR, kill, he's "it"
then he gets SR, repeat.
I found that it didn't really go anywhere, and that you would just hover around -1 to +1 on the scoreboard.
"Anyone who has never made a mistake has never tried anything new." -- Albert Einstein
GU League | Ducati League | OpenLeague

User avatar
lep
Private First Class
Private First Class
Posts: 227
Joined: Tue Jun 17, 2008 12:03 am
Location: San Diego, CA
Contact:

Re: "Tag! your it!!!" plug-in

Post by lep » Sat Apr 11, 2009 3:05 pm

When a game repeats back and forth too quickly, it becomes a bit a boring...Try finding a way to slow it down a bit and make more opportunities to score. -1 and +1 aren't where scores should stop...

Monster
Private First Class
Private First Class
Posts: 209
Joined: Thu Sep 20, 2007 7:06 pm

Re: "Tag! your it!!!" plug-in

Post by Monster » Mon Apr 27, 2009 2:23 pm

I like this plugin. It could be usefull for a hide and seek map ;)

applecake
Private First Class
Private First Class
Posts: 38
Joined: Sat Aug 23, 2008 4:08 pm
Location: somewhere in the woodlands of Sweden

Re: "Tag! your it!!!" plug-in

Post by applecake » Mon May 04, 2009 10:57 am

Monster wrote:I like this plugin. It could be usefull for a hide and seek map ;)
Such an map would be very fun. Problem is that it may not be so much "action" and people would get bored. But I have also thought of a hide and seek map..
-Ehm.. Mr president, you got applecake in ur eye!
-Well..I see that..
=====================================
And now some advertising:
http://type-your-name-here.deviantart.com/gallery/ My Deviantart!
http://action.cubers.net/ Another fun and free game

User avatar
Pizzahead
Corporal
Corporal
Posts: 48
Joined: Mon Dec 24, 2007 6:42 pm
Location: New York, USA
Contact:

Re: "Tag! your it!!!" plug-in

Post by Pizzahead » Wed May 27, 2009 11:02 pm

hide and seek map.... there's hide and seek hills :)
Let's not bicker and argue about who killed who.

applecake
Private First Class
Private First Class
Posts: 38
Joined: Sat Aug 23, 2008 4:08 pm
Location: somewhere in the woodlands of Sweden

Re: "Tag! your it!!!" plug-in

Post by applecake » Fri May 29, 2009 1:10 pm

Hide n seek hills is more like a WG map... :)
-Ehm.. Mr president, you got applecake in ur eye!
-Well..I see that..
=====================================
And now some advertising:
http://type-your-name-here.deviantart.com/gallery/ My Deviantart!
http://action.cubers.net/ Another fun and free game

Enigma
Private First Class
Private First Class
Posts: 211
Joined: Sat Apr 23, 2005 3:13 am

Re: "Tag! your it!!!" plug-in

Post by Enigma » Sun May 31, 2009 4:54 am

Code: Select all

bool spawnpos[256]={0};
bool shield=0;
float outspawns[5][5]={{0}};
What are these variables for? When I see a variable named 'spawnpos', I assume it would contain Cartesian coordinates in either R2 or R3. You have an array of 256 boolean values that you never use. Actually you don't use any of those variables.

User avatar
TheFish
Private First Class
Private First Class
Posts: 25
Joined: Sun Nov 02, 2008 11:11 pm
Location: Texas
Contact:

Re: "Tag! your it!!!" plug-in

Post by TheFish » Tue Jun 02, 2009 2:35 am

Enigma wrote:

Code: Select all

bool spawnpos[256]={0};
bool shield=0;
float outspawns[5][5]={{0}};
What are these variables for? When I see a variable named 'spawnpos', I assume it would contain Cartesian coordinates in either R2 or R3. You have an array of 256 boolean values that you never use. Actually you don't use any of those variables.

I'm new to programming, this is my first plug-in that I have ever made.

Enigma
Private First Class
Private First Class
Posts: 211
Joined: Sat Apr 23, 2005 3:13 am

Re: "Tag! your it!!!" plug-in

Post by Enigma » Sat Jun 06, 2009 1:50 am

TheFish wrote: I'm new to programming, this is my first plug-in that I have ever made.
Sorry, I didn't mean to act like a jerk. I tend to notice things that are wrong, rather than those that are right. I apologize for that.

Creating a plug-in when you are new to programming is actually quite good, in my opinion. Although the plug-in doesn't do much, it looks like it was meant to be a learning exercise. If you ever need any help, just ask.

To expand on your idea, maybe you could add a timer. What I mean is, after getting tagged, you would have a time limit to tag someone else. If you don't tag someone in that time limit, you blow up.

While writing this, I just thought of a good plug-in idea. There was a plug-in (I think it was a plug-in) that assigned flags to a specific team. For instance, the green team would get laser, the purple team would get guided missile, etc... The only limitation is you had to have that one type of flag the entire time. This wouldn't be a limitation with BZFlag 3.0 (whenever it is released). To be more specific, you could change the shot types for a specific team, while still being able to grab other flags. That is, every player on the green team could have the laser shot type, while still possessing the ability to grab other flags, such as cloaking, wings, and tiny. You could fly around with the wings flag and have the guided missile shot type!

Does that sound like a good idea? I'll work with you on it, if you want.
Last edited by Enigma on Sat Jun 06, 2009 7:13 am, edited 1 time in total.

Enigma
Private First Class
Private First Class
Posts: 211
Joined: Sat Apr 23, 2005 3:13 am

Re: "Tag! your it!!!" plug-in

Post by Enigma » Sat Jun 06, 2009 2:40 am

Here is an example of how it could work. This is sort of off the top of my head, so I'm sure it is incomplete. There is a little bit of example code, but I pretty much just wrote comments describing how it could work.

Code: Select all

// All flags with non-standard shot types.
// These are the possible shot types that can be used.

#define CLOAKED_SHOT "CS"
#define GUIDED_MISSILE "GM"
#define INVISIBLE_BULLET "IB"
#define LASER "L"
#define MACHINE_GUN "MG"
#define PHANTOM_ZONE "PZ"
#define RAPID_FIRE "F"
#define RICOCHET "R"
#define SHOCKWAVE "SW"
#define SUPPER_BULLET "SB"
#define THIEF "TH"

typedef int PlayerID;

std::map<PlayerID, bz_eTeamType> playerTeams;
std::map<bz_eTeamType, bz_eShotType> teamShotTypes;

// This is in the API for setting a player's shots.
// BZF_API bool bz_setPlayerShotType( int playerId, bz_eShotType shotType );

// With the maps, you can write code like this...
// Assume 5 is a player id.

bz_setPlayerShotType(5, teamShotTypes[playerTeams[5]])

// This way, if you change the shot type for a team when
// the plug-in is loaded, you only have to update it in one spot:
// the shot types map.  When it is updated there, the shot types for 
// every player on a team are updated at once.

// initialize the shot type map.
// This is just an example.  The actual types
// would be variable, not constant.

teamShotTypes[eRedTeam] = eGMShot;
teamShotTypes[eGreenTeam] = eLaserShot;
teamShotTypes[eBlueTeam] = eShockWaveShot;
teamShotTypes[ePurpleTeam] = eCloakedShot;

// Filling the playerTeams map would be similar.
// Use bz_getPlayerIndexList() to get all of the players

// The part and join events would need to
// manage the player teams map

// I believe the spawn event needs to be used to set the shot
// type for a player.  I think the shot type is reset
// everytime a player respawns.


Anxuiz
Private First Class
Private First Class
Posts: 31
Joined: Fri Sep 05, 2008 3:38 am

Re: "Tag! your it!!!" plug-in

Post by Anxuiz » Mon Jun 08, 2009 10:53 pm

Enigma wrote:...
Creating a plug-in when you are new to programming is actually quite good, in my opinion. Although the plug-in doesn't do much, it looks like it was meant to be a learning exercise.
...
I agree. Plug-ins are very simple (the API does the most of the work) with lots of good "feedback" (like seeing a world weapon fire, or seeing chat text from the server that you made) for little effort. I actually started learning C++ using the BZFS plug-ins. They can be as simple or complex as you want them to be and it doesn't need to be complex to have fun with it. As you progress you can start to add features like a timer and stuff, but no need to feel rushed in creating a plug-in.

Another thing that I realized is that if you want to provide a lot of features, don't chose a limiting idea. This "Tag! You're it!" is a very "open" plug-in; you can add many features to it that aren't a waste of your time (people won't use them).

Who knows, maybe you'll even become a good BZFlag dev someday ;)

- Yassen

User avatar
flying_popcorn
Private First Class
Private First Class
Posts: 88
Joined: Wed Dec 14, 2005 2:40 am
Contact:

Re: "Tag! your it!!!" plug-in

Post by flying_popcorn » Thu Jun 11, 2009 2:14 am

Enigma: Those variables look like they were left over from an example in my plugin tutorial.
Anyway, TheFish, there is a bit of extra code you don't need in the plugin. All it does is flagtake when someone dies and flaggive when someone spawns, you don't need any of those variables. Also, you don't need to register events that you aren't using.
(Also, I would prefer "you're" to "your" :))

User avatar
TheFish
Private First Class
Private First Class
Posts: 25
Joined: Sun Nov 02, 2008 11:11 pm
Location: Texas
Contact:

Re: "Tag! your it!!!" plug-in

Post by TheFish » Thu Jun 11, 2009 8:21 pm

thanks for all of the help, ill be sure to watch for things like that next time, especially spelling "you're" correctly. :P

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest