Why is this not working?

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
Geobot
Private
Private
Posts: 3
Joined: Mon Dec 18, 2006 6:12 am

Why is this not working?

Post by Geobot »

Ok, so I decided to make a plugin. I threw some code together and I came up with something that i SWEAR should work, but it doesn't for some reason.

it's supposed to change every shot to a specified shot type(ie laser, shockwave). however.... it doesn't seem to want to work. here's the code, anyone wanna give a look?

Code: Select all

#include "bzfsAPI.h"
#include <string>

BZ_GET_PLUGIN_VERSION

class BBCapHandler : public bz_EventHandler
{
public:
  virtual void	process ( bz_EventData *eventData );
  std::string shootType;
};

BBCapHandler	bbCapHandler;

BZF_PLUGIN_CALL int bz_Load ( const char* commandLine )
{
  bz_debugMessage(4,"BaseBuilder plugin loaded");

//  if (commandLine)			//Commented for testing purposes
// {
//	  bbCapHandler.shoottype = commandLine;
 // } else {
	  bbCapHandler.shootType = "L";
 // }
   
  bz_registerEvent(bz_eShotFiredEvent,&bbCapHandler);
  return 0;
}

BZF_PLUGIN_CALL int bz_Unload ( void )
{
  bz_debugMessage(4,"BaseBuilder plugin unloaded");
  return 0;
}

void BBCapHandler::process ( bz_EventData *eventData )
{
	  bzApiString shotType = bzApiString(shootType);

	  if (eventData->eventType != bz_eShotFiredEvent)
		return;

	  bz_ShotFiredEventData *shot = (bz_ShotFiredEventData*)eventData;

   	  bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, shot->type.c_str());  //simply for testing 
	  
	  shot->type = shotType; 
	  shot->changed = true;
	  
	  bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, shot->type.c_str());  //again, testing
}

you can see the commenting in the command line section, that's just until i can actually get it to work, right now it should be set to perma-laser.

farther down you can see the server messages being sent. when i have it loaded, it tells me what shot i'm firing, before and after the plugin modifies it. THAT does update, meaning, that in-game it gives the abbv for whatever flag i have, and then on the next line says "L". however, it does not modify the actual shot.

i know i've seen a couple references to a zombie mod where the shots get PZ'd, but i couldn't find it, so i couldn't compare it to what i have.

i've been staring at this for hours now trying to figure out why it won't work, but i'm at my wits end. any ideas?
User avatar
A Meteorite
Private First Class
Private First Class
Posts: 1786
Joined: Thu Apr 28, 2005 12:56 am
Location: California, U.S.
Contact:

Post by A Meteorite »

I've never changed a shot's type as I haven't gotten to that yet, but you should use bz_removeEvent() in bz_Unload(), ex:

Code: Select all

bz_removeEvent(bz_eShotFiredEvent,&bbCapHandler)
On changing a shot's type... I would ask the developers in #bzflag on IRC.
Image
Owner @ BZFX
Core Admin @ CAN

Email me: bzmet…@gmail.com
Geobot
Private
Private
Posts: 3
Joined: Mon Dec 18, 2006 6:12 am

Post by Geobot »

heh, yea, seemed to have overlooked that one..... thanks.

i was wondering if ShotFiredEvent was fully implemented, since it's not in the API doc's, but it IS in the API, and i found the event caller in bzfs.cxx, so i dunno why it shouldn't work. everything seems to check out fine as far as i can tell.
User avatar
A Meteorite
Private First Class
Private First Class
Posts: 1786
Joined: Thu Apr 28, 2005 12:56 am
Location: California, U.S.
Contact:

Post by A Meteorite »

Geobot wrote:heh, yea, seemed to have overlooked that one..... thanks.
Hehe. :)
Geobot wrote:i was wondering if ShotFiredEvent was fully implemented, since it's not in the API doc's, but it IS in the API, and i found the event caller in bzfs.cxx, so i dunno why it shouldn't work. everything seems to check out fine as far as i can tell.
I've seen it used on servers (like the PZ one you mentioned), but I haven't seen any example plugin code. So something must be implemented somewhere... or the API was modified (doubtful)... :|
Image
Owner @ BZFX
Core Admin @ CAN

Email me: bzmet…@gmail.com
User avatar
Tropican8
Private First Class
Private First Class
Posts: 312
Joined: Fri Mar 18, 2005 11:51 pm
Location: As close to the grove as you can get

Post by Tropican8 »

A Meteorite wrote:I've seen it used on servers (like the PZ one you mentioned), but I haven't seen any example plugin code. So something must be implemented somewhere... or the API was modified (doubtful)... :|
L4m3r has the code somewhere...

And the API was not modded.
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5196
Joined: Fri Dec 13, 2002 4:11 am

Post by JeffM »

you should note, that if you change the shot type, it will ONLY change the shot type for the shots OTHERS see, not your own. Your client won't know that the shot was changed, because it was changed on the server, after the client generated the shot.

It's generally not a good idea to change the shot to one of the other major shot types, as they behave differently and will cause game states to be out of sync.

We will probably have a better way of changing shots in a future version, one where when you pick up a flag, the server tells the client the shot type to use with it.
ImageJeffM
Geobot
Private
Private
Posts: 3
Joined: Mon Dec 18, 2006 6:12 am

Post by Geobot »

ok, well, thanks for the info. i thought about that after i'd posted last night, so i tried watching it on my wife's screen while i shot past her. that didn't really work either.

anyways, thanks again ^^
Post Reply