You are not logged in.    Login    New User    Forum Home    Search

Location:
JBPLAY  \  Meteor 2  \  Help and Guidance  \  silly script question

Back to Threads

Viewing Thread: silly script question

 

me_mantis

Joined: 26 September 2003
Posts: 1152
17 December 2008 00:54 (UK time)


#title "Autorocket"
#author "me_mantis"

#include meteor2


// tell M2 which functions it can use
export OnMapStart;
export Toolbar;
export AutoRocket;
void OnMapStart()
{
SC_GameMessage("Augh! the Bog!!");
SC_SetObjectHidden(3,1);
SC_CreateToolbar( 0, "Things to do", 400, 0, 0, 1);
SC_AddToolbarButton( 0, "fire autorocket", "buttons\\attack.pcx","run AutoRocket",1 );
StaticFlags[0] = 0;
}

void Toolbar()
{

}

void AutoRocket()
{
SC_GameMessage("Bamo! Autorocket");
if(SC_GetItemCount("Rocket") > 1 )
{
SC_GiveItem("Rocket",-1);
//get object id
int x, y, p, id, doomed, ps, i;
p = SC_GetPlayerObjectId();
// get player coordinates
SC_GetObjectCoords( p, &x, &y);
//create rocket
id = SC_AddObject("bird.ob", x, y, 0, AI_ROAMING, 1, "doom bird", 1, 0, 0);
//get object side
ps = SC_GetObjectSide(p);

//scan for closest enemy
for( i=1; i<1000; ++i)
{
if(SC_GetObjectSide(i) != ps)
{
SC_SetObjectFollow(id, i);
SC_GameMessage("Tracking %d", i);
}
}
//seek through everything
//track to nearest enemy
//sit there yay!
}
else
{
SC_GameMessage("You don't have rockets");
}
}


so rather than tracking through 1-999, I'm wondering how to stop when the argument is validated.. ie. it finds an object that's side isn't of the player...
how do I break out of the loop when the thing I'm lookingfor is found?

the idea is this -
we check through all the objects, looking for one that's not the players ID, and then send a bird flying after it. Of course, I'll also do a range checker, so it finds out the closest thing first, and sends the bird that way.

any suggestions? It's been a while since I've coded anything.

You need to login to create posts in this thread.

arezey

Joined: 16 June 2005
Posts: 1599
17 December 2008 15:43 (UK time)

Maybe use continue? I think it should work, but not 100% sure.

//scan for closest enemy
for( i=1; i<1000; ++i)
{
if(SC_GetObjectSide(i) != ps)
{
SC_SetObjectFollow(id, i);
SC_GameMessage("Tracking %d", i);
continue;
}
}


You need to login to create posts in this thread.

ParaSait

Joined: 26 June 2007
Posts: 1478
17 December 2008 22:44 (UK time)

Just to make it all go a little faster (but you'll still do the loop 999 times), I'd just try the Pythagoras Theory...

Try this for example:


// Player stuff
int AX;
int AY;
SC_GetObjectCoords(p,AX,BX);

// (Potentional) Enemy stuff
int BX;
int BY;

// Stuff we're gonna need for the theory
int W;
int H;
int Hyp;

// Vars that remember who the "winner" is
int LowestHyp = 9999999;
int Lowest;

for(i=1;i<1000;++i)
{
if(SC_GetObjectSide(i) != ps)
{
SC_GetObjectCoords(i,BX,BY);
W = BX - AX;
H = BY - AY;

// Yay Pythagoras!
Hyp = SQUARE(QUADRATE(W) + QUADRATE(H));

if(Hyp < LowestHyp)
{
LowestHyp = Hyp;
Lowest = i;
}
}
}

// And the winner is...
SC_setObjectFollow(id,Lowest);


Notes:
- I haven't tested it, so it may not work correctly. (It's only an example anyway)
- Replace "QUADRATE" and "SQUARE" with the correct names of the functions (Which I don't know)
- I still don't know how to place tabs in an internet browser text field...


This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


Edited: 17 December 2008 22:45


You need to login to create posts in this thread.

arezey

Joined: 16 June 2005
Posts: 1599
18 December 2008 11:01 (UK time)

@Mrazerty

1. I don't know of the square and quadrate functions for C, but I doubt such ones exist.
2. To put tabs, just copy one and paste it there, or use spaces.

You need to login to create posts in this thread.

me_mantis

Joined: 26 September 2003
Posts: 1152
20 December 2008 17:51 (UK time)

I've sorted everything out.

the a2+b2=c2 doesn't work because math.h isn't implemented... and I don't think it can be ^ only means + in the script commands, so lotsa stuff doesn't work.

Anyways, I've got it pretty nicely figured out, and I implemented a few extra features that should make multiplayer much more enjoyable...

Mines
Timebombs
Tracking Missles.

I'm still working out some of the bugs. =)

I'll release the code sooner or later for y'all as a Christmas present!

You need to login to create posts in this thread.

DarkRain

Joined: 01 March 2007
Posts: 1193
20 December 2008 18:49 (UK time)

me_mantis[keens wrote:
]I've sorted everything out.

the a2+b2=c2 doesn't work because math.h isn't implemented... and I don't think it can be ^ only means + in the script commands, so lotsa stuff doesn't work.

Anyways, I've got it pretty nicely figured out, and I implemented a few extra features that should make multiplayer much more enjoyable...

Mines
Timebombs
Tracking Missles.

I'm still working out some of the bugs. =)

I'll release the code sooner or later for y'all as a Christmas present!


Great! But what are you working on?
The Dark Age is upon us! Quake 2 mapmaker.


You need to login to create posts in this thread.

arezey

Joined: 16 June 2005
Posts: 1599
20 December 2008 22:04 (UK time)

@Dark Rain
Shaddap, don't tempt him to spoil the secret! I like surprises. :p

You need to login to create posts in this thread.

ParaSait

Joined: 26 June 2007
Posts: 1478
20 December 2008 23:45 (UK time)

arezey wrote:
@Dark Rain
Shaddap, don't tempt him to spoil the secret! I like surprises. :p


Umm, no, SPEAK! I DON'T like surprises =P =P


This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


You need to login to create posts in this thread.

DarkRain

Joined: 01 March 2007
Posts: 1193
21 December 2008 08:47 (UK time)

arezey wrote:
@Dark Rain
Shaddap, don't tempt him to spoil the secret! I like surprises. :p


Ok, I just asked him. It's up to Mantis to decide whether to tell us or not.
The Dark Age is upon us! Quake 2 mapmaker.


You need to login to create posts in this thread.

me_mantis

Joined: 26 September 2003
Posts: 1152
23 December 2008 04:51 (UK time)

Hmmm
Nobody ever asked me much of anything, but here's the problem.

Nobody dies in multiplayer games, except when they get run over.


So, we'll have to make it easier to die, because the game is balanced for everybody to not die in the missions.

Thus, I just randomly decided to do a bunch of stuff.

You need to login to create posts in this thread.



Forums system (C) 1999-2023 by James Bunting.

Terms of Use