crazy laser (maybe a boxy war add)

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
User avatar
BinarySpike
Corporal
Corporal
Posts: 735
Joined: Mon Mar 28, 2005 11:58 pm
Contact:

crazy laser (maybe a boxy war add)

Post by BinarySpike »

after finding out "make -n" shows the linking commands... I can edit them to include the correct libcurl and dlcompat... I can run plugins and libcurl on my mac ;-)

Now anyway, I'm working on a plugin called crazy laser, it works in rabbit hunt, ctf, and ffa...

You define a laser position, time, and several settings

the laser fires from it's position every "time" seconds... so if you set a laser for for 3 seconds
The laser would target players every 3 seconds and fire... (tracking them with laser)


Basically there are some things... Player and Distance and Flag.

Player is the highest player, Distance is the closest player to the "objective", and Flag is a good or bad flag

For example, CTF would be a base... so if a high ranking player was near a base then the claser would be more apt to shoot him...

The claser does NOT target ST's, or CL's ;-)

For example ;-) you could set Player to any, Distance to any, and Flag to bad, and set the time to 3... now when the laser doesn't have anybody to target it will idle when that happens it has to "load" up and will shoot the moment it has a target and is loaded...

so in this case whenever somebody picked a bad flag up the laser will load for three seconds (if time is 3) and then fire at the player...

Laggy players it won't shoot to well ;-) but I hope to have a doppler calculator (which is cake to make)

The targeting and the firing should be easy but the actually setting's setting should be hard... :( I've only done one other plugin so far... anyway... what do you guys think?
User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once »

...we got Death Star!
...This has been a recording.
User avatar
chandler583
Private First Class
Private First Class
Posts: 33
Joined: Fri Jan 07, 2005 12:01 am
Location: Brenham
Contact:

Post by chandler583 »

Sounds pretty good, can't wait to see it for real. :lol:
Reality is nice place to visit, but i wouldn't want to live there. :)
User avatar
L4m3r
Hater of Everything
Hater of Everything
Posts: 724
Joined: Tue Feb 08, 2005 5:15 am
Location: Los Angeles

Post by L4m3r »

I've thought about doing some sort of sentry gun, and a laser is definitely the way to go, thanks to a negligeable travel time.

You'd need to do a little trig and some dead reckoning (for lag). I think it could be done easily enough.
Optimism is just a milder alternative to denial.
User avatar
BinarySpike
Corporal
Corporal
Posts: 735
Joined: Mon Mar 28, 2005 11:58 pm
Contact:

Post by BinarySpike »

requires a server mod :(

My trig won't work... I've tryed everything I could think of...
(i'm not a math wiz... I do know some trig but this is just to hard)


I could mod the server so that we could use something other than direction and tilt (which is throwing me off)

That "might" be nice but would probably not sit well with the devs if I sent a patch in... if ya'll want to see my code here it is...
(I tried converting to degrees... radians works ONLY if the x isn't negative... and I don't know enough about radians/atan to tell what I'm doing wrong)

Code: Select all

void claser::process(bz_EventData *eventData)
{
bzAPIIntList targetsList;
//bz_PlayerRecord * targetRec;

bz_PlayerSpawnEventData *targetRec = (bz_PlayerSpawnEventData*)eventData;


//targetRec = bz_getPlayerByIndex(0);

if (targetRec == NULL /*!= NULL && !bz_updatePlayerData (targetRec)*/)    // update the target
    {
    bz_debugMessage(4, "couldn't update target");
    }

float reloadTime = (float)bz_getBZDBDouble("_reloadTime") * (float)bz_getBZDBDouble("_laserAdRate");

// calculate direction and tilt...
float x = targetRec->pos[0] - laserpos[0], y = targetRec->pos[1] - laserpos[1], z = targetRec->pos[2] - laserpos[2];

// convert targetDir to a tilt and direction
float tilt = 0, direction;

#define myPI 3.14159265
  float tiltX = sqrt(pow(x,2) + pow(y,2));
  float dirX = sqrt(pow(x,2) + pow(z,2));

direction = atan2(y,dirX);
tilt = atan2(z, tiltX);

bz_fireWorldWep("L",reloadTime,BZ_SERVER,laserpos,tilt, direction, 0, 0.0f);
bz_debugMessage(0, bz_format("xyz %f %f %f, tilt %f, direction %f", x, y, z, tilt, direction));
}
It fires correctly if x isn't negative... it misses if it is... also laserpos is the location of the laser... which in this case is 0,0,15 (center, 15 units up)
User avatar
Hannibal
Private First Class
Private First Class
Posts: 1073
Joined: Mon May 02, 2005 10:27 pm
Contact:

Post by Hannibal »

I love the idea..works wonders for the Planet Mofo theme..
Games don't make people violent, lag does.
ImageImage
User avatar
BinarySpike
Corporal
Corporal
Posts: 735
Joined: Mon Mar 28, 2005 11:58 pm
Contact:

Post by BinarySpike »

It requires a server mod for timestamps on players last update...
User avatar
Waistless
Private First Class
Private First Class
Posts: 51
Joined: Sat Mar 19, 2005 10:09 am
Location: Australia

Post by Waistless »

man that would rock! having a bad flag which would make a world weapon fire on you :D

on thing though, for laser would it be able to sucessfully shoot players with lag? *cough*myself*cough*

better still, have a flag which launches "TAG(Target Aquisition and Guidance)Bullets", and when they hit the player, the world weapon then starts firing upon them, OR have you (or other players) automatically aim and fire at them.
Could this tank perhaps go a little bit faster, so it's not being overtaken by stationary objects.
"Words in parentheses can (not) be ignored." -Unknown
User avatar
MonsterMan++
Private First Class
Private First Class
Posts: 189
Joined: Thu Apr 13, 2006 11:32 am

Post by MonsterMan++ »

Hey it looks good! Actually that's pretty awesome. It's a smart laser, so you should make it a little less better.
Fighting for peace is like screwing for virginity.
-George Carlin

If you can't beat them, arrange to have them beaten.
-George Carlin

Nobody goes there anymore. It's too crowded.
-Yogi Berra

Better a broken promise than none at all.
-Mark Twain
User avatar
BinarySpike
Corporal
Corporal
Posts: 735
Joined: Mon Mar 28, 2005 11:58 pm
Contact:

Post by BinarySpike »

Waistless wrote:man that would rock! having a bad flag which would make a world weapon fire on you :D

on thing though, for laser would it be able to successfully shoot players with lag? *cough*myself*cough*

better still, have a flag which launches "TAG(Target Acquisition and Guidance)Bullets", and when they hit the player, the world weapon then starts firing upon them, OR have you (or other players) automatically aim and fire at them.
That would require a massive client mod, along with a massive server mod... waaay to hard for me... and I can't even get my trig to work fully...

About the lag, that's easy... can't remember what JeffM called it but I call it doppler... (yeah totally out of context)


I've tried this exact same thing using a client mod... (where I could shoot a player that was below me or to my side... and hit him)

But lag made me miss... so I had to hit non-moving tanks...

I might just compensate for lag only if the player has a bunch of it... that way the laser wouldn't hit players moving perpendicular to it (like a GM dodge) but stopped/parallel it would hit
User avatar
BinarySpike
Corporal
Corporal
Posts: 735
Joined: Mon Mar 28, 2005 11:58 pm
Contact:

Post by BinarySpike »

To hard to make... not the trig... would require to much of a server mod to do it... useless except on custom servers... so no... I'm gonna work on obj to bzw instead
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Post by Enigma »

BinarySpike wrote:requires a server mod :(

My trig won't work... I've tryed everything I could think of...
(i'm not a math wiz... I do know some trig but this is just to hard)


I could mod the server so that we could use something other than direction and tilt (which is throwing me off)

That "might" be nice but would probably not sit well with the devs if I sent a patch in... if ya'll want to see my code here it is...
(I tried converting to degrees... radians works ONLY if the x isn't negative... and I don't know enough about radians/atan to tell what I'm doing wrong)

Code: Select all

void claser::process(bz_EventData *eventData)
{
bzAPIIntList targetsList;
//bz_PlayerRecord * targetRec;

bz_PlayerSpawnEventData *targetRec = (bz_PlayerSpawnEventData*)eventData;


//targetRec = bz_getPlayerByIndex(0);

if (targetRec == NULL /*!= NULL && !bz_updatePlayerData (targetRec)*/)    // update the target
    {
    bz_debugMessage(4, "couldn't update target");
    }

float reloadTime = (float)bz_getBZDBDouble("_reloadTime") * (float)bz_getBZDBDouble("_laserAdRate");

// calculate direction and tilt...
float x = targetRec->pos[0] - laserpos[0], y = targetRec->pos[1] - laserpos[1], z = targetRec->pos[2] - laserpos[2];

// convert targetDir to a tilt and direction
float tilt = 0, direction;

#define myPI 3.14159265
  float tiltX = sqrt(pow(x,2) + pow(y,2));
  float dirX = sqrt(pow(x,2) + pow(z,2));

direction = atan2(y,dirX);
tilt = atan2(z, tiltX);

bz_fireWorldWep("L",reloadTime,BZ_SERVER,laserpos,tilt, direction, 0, 0.0f);
bz_debugMessage(0, bz_format("xyz %f %f %f, tilt %f, direction %f", x, y, z, tilt, direction));
}
It fires correctly if x isn't negative... it misses if it is... also laserpos is the location of the laser... which in this case is 0,0,15 (center, 15 units up)
I haven't read the documentation for all of these functions, but I'm guessing tilt is an angle for up/down and direction is for left/right. If so, I think you should use the normal arctan function instead of atan2 when calculating the tilt. I think your problem is that atan2 returns an angle in the correct quadrant based on the signs of the parameters.

EDIT: Just a side note: x*x is faster than pow(x,2).

YET ANOTHER EDIT:
This part of your code doesn't make sense:

Code: Select all

  float tiltX = sqrt(pow(x,2) + pow(y,2));
  float dirX = sqrt(pow(x,2) + pow(z,2));
  direction = atan2(y,dirX);
  tilt = atan2(z, tiltX);
It looks like you have a point in space with your x, y, and z variables (basically a vector), and you want to find an angle between the vector and an axis. If the sqrt(x^2 + y^2) equation gives you the magnitude of the vector (the hypotenuse), why are you using arctan(some_side/hypotenuse) when tan(theta) = opposite/adjacent and arctan(opp/adj) = theta?
Last edited by Enigma on Sun Aug 13, 2006 1:20 am, edited 1 time in total.
User avatar
GMMan
Private First Class
Private First Class
Posts: 186
Joined: Sat May 13, 2006 9:32 pm
Location: On the time-space continuum

Post by GMMan »

This plugin would probably drive me nuts trying to dodge it (if possible!) Though still, this is a great idea. It might work for a map I'm thinking of making.
I haven't touched BZFlag for years, but maybe sometime I'll make a comeback.

I'm on Twitter. And I mess with webOS. This signature is not a blog.
User avatar
BinarySpike
Corporal
Corporal
Posts: 735
Joined: Mon Mar 28, 2005 11:58 pm
Contact:

Post by BinarySpike »

Ok for everyone's information, with inchworm's help I was able to figure the problem out.

As slayer++ said, atan2 only gives me correct information for a specific quadrant (at the time I didn't know what a quadrant is)

Strangly I figured this, not in the exact sense, but I thought how I would do it, but didn't want to sit down and write it all out...


Like I said, there would need to be and update for a timestamp to actually calculate a tanks position, based on his speed and the last update and the current time, you could extropolate a "current" position minus lag, then add a lag fudge.

Also, GMMan, the laser wouldn't be accurate, if you stopped moving it would kill you in an instant, but depending on lag, and how MsgPlayerUpdate works, you would get hit less.

I could also add a "player" target, higher lag players that don't get hit as much could be targeted, or based on how many times the laser has hit a specific tank. That way it wouldn't go after less laggy players more. kidna like handicap :)

Atm I'm finishing up my iBZEdit, but I might go ahead and do this now with my knowledge of atan2 :)

I'll start a new post if I get anything, thanks :)
Post Reply