Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (Quad, AndrewAMD), 1,007 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
nearest entity on screen??? #283755
08/09/09 21:09
08/09/09 21:09
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Hi there..

i´m wokring on a 2,5D Shooter.. And i worked hard to get movement and weapon changes to work.

But now i stuck at a problem.
The Rockets!


What i need:
A Script that Scans the Screen for all objects with a 5 in Skill99.
From all this, it should notice the nearest to the player, and set his angle to look at that object ( so my rocket seeks it ).

I hope really someone can help me here ( it´s the last weapon before i start mapping ).


Edit:
Some Ingame Screens of Weapons and Stuff ( click to enlarge ):


Last edited by Espér; 08/09/09 21:18.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: nearest entity on screen??? [Re: Espér] #283787
08/10/09 06:02
08/10/09 06:02
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline
Junior Member
GorNaKosh  Offline
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
Also wenn du Entities für die Objekte benutzt, versuch sowas mal:
Code:
ENTITY* nextEnt;

void event_scan() {
     if(event_type == EVENT_SCAN && my.skill[5] == 5) {
          if(nextEnt == NULL || vec_dist(me.x,you.x) < vec_dist(nextEnt.x,you.x)) {
          nextEnt = me;
          }
     }
}

action object() {
     my.emask |= ENABLE_SCAN;
     my.event = event_scan;
}



Wenn du deine eigenen Structs hast, könntest du die Pointer aller sichtbaren Objekte in einer Liste verwalten und diese bei jedem mal durchlaufen wenn gescannt werden soll. Für jedes Objekt muss dann wieder die Entfernung - ähnlich wie oben - gecheckt werden...
Hoffe ich hab die Frage richtig verstanden und konnte helfen wink

Re: nearest entity on screen??? [Re: GorNaKosh] #283877
08/10/09 14:50
08/10/09 14:50
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Das prob ist.. das die Racketen Scannen sollen.. und der gegner damit nix zu tun hat...
Also, der gegner scannt lediglich nach dem helden.. sonst nach nix.


English:
GorNaKosh´s code let´s the enemy react on a Scan from the rockets... But i need the rockets only to change to direction to the nearest enemy ( Skill99 == 5 ). So the enemy just scans for the player, and for nothing more. While the rockets scan for enemies.


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: nearest entity on screen??? [Re: Espér] #283883
08/10/09 15:26
08/10/09 15:26
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl

didnt test the code and need some change but its just for the idea

Code:
var dist;
ENTITY* close_ent;

	dist = 0;
	you = ent_next(NULL); // retrieve first entity
 	while (you) // repeat until there are no more entities
	{ 
		if(Skill99 == 5 )
		{
			if(vec_dist(player.x,you.x) == dist)
			{
				dist = vec_dist(player.x,you.x);
				close_ent = you;
			}
		}
 		you = ent_next(you); // get next entity
 	}
 	
	vec_set(temp,close_ent.x); 
	vec_sub(temp,weapon.x);
	vec_to_angle(weapon.pan,temp);




"empty"
Re: nearest entity on screen??? [Re: flits] #283895
08/10/09 16:08
08/10/09 16:08
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
== dist won't work, dist won't ever be 0...

Code:
var dist;
ENTITY* close_ent;

	dist = 100000;     //maximum dist that the rocket can 'see' entities at
	you = ent_next(NULL); // retrieve first entity
 	while (you) // repeat until there are no more entities
	{ 
		if(Skill99 == 5 )
		{
			if(vec_dist(player.x,you.x) < dist)
			{
				dist = vec_dist(player.x,you.x);
				close_ent = you;
			}
		}
 		you = ent_next(you); // get next entity
 	}
 	
	vec_set(temp,close_ent.x); 
	vec_sub(temp,weapon.x);
	vec_to_angle(weapon.pan,temp);




~"I never let school interfere with my education"~
-Mark Twain
Re: nearest entity on screen??? [Re: Germanunkol] #284134
08/11/09 21:13
08/11/09 21:13
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
ok.. a problem appeared..:

this is the rocket code:
Code:
action i_rocket()
{
	var dist;
	var dist2 = 100;
	var destroyme = 0;
	my.skill2   = 0;
	my.skill1 = reedeem2;
	
	if(reedeem2 == 1){reedeem2 = 2;}
	else{reedeem2 = 1;}
	
	ENTITY* close_ent;
	VECTOR* temp;
	
	set(my, PASSABLE);
	
	while(my.skill2 < 50)
	{
		if(my.skill1 == 1)
		{
			c_move(my, vector(0,-40*time_step,0), nullvector, NULL);
			my.pan += 4*time_step;
		}
		
		if(my.skill1 == 2)
		{
			c_move(my, vector(0,-40*time_step,0), nullvector, NULL);
			my.pan -= 4*time_step;
		}
		rocketeer();
		my.skill2 += 1;
		wait(1);
	}
	
	
	dist = 100000;     //maximum dist that the rocket can 'see' entities at
	while(dist2 > 30 && my.x > -1600 && my.x < 1600 && my.y > -500 && my.y < 5000)
	{
		you = ent_next(NULL); // retrieve first entity
		while(you) // repeat until there are no more entities
		{
			if(you.skill99 >= 5)
			{
				if(vec_dist(my.x,you.x) < dist)
				{
					dist = vec_dist(my.x,you.x);
					dist2 = vec_dist(my.x,you.x);
					close_ent = you;
				}
			}
			you = ent_next(you); // get next entity
			wait(1);
		}
//		if(close_ent != NULL)
//		{
			while(dist2 > 30 && my.x > -1600 && my.x < 1600 && my.y > -500 && my.y < 5000)
			{
				error("1")
				dist2 = vec_dist(my.x, close_ent.x);
				error("1")
				vec_set(temp, close_ent.x);
				error("2")
				vec_sub(temp, my.x);
				error("3")
				vec_to_angle(my.pan, temp);
				error("4")
				c_move(my, vector(50*time_step,0,0), nullvector, NULL);
				error("5")
				rocketeer();
				error("6")
				my.z = 0;
				error("7")
				wait(1);
			}
//		}
		wait(1);
	}
	//	exploding_1(my);
	wait(1);
	ent_remove(my);
}



The problem:
The rocket appears...
makes it´s startin curve-flight
and is away.. from one frame to another...

Odd: the player moves now only diagonal ( lower_left to upper_right and reverse.. nothing else ).
And the next rockets are flying down out of the screen, when an error "Crash in i_rocket" appears...

like you see, i´ve written some errors with numbers..
After Error "1", but BEFORE Error "2", i got an
"Empty ointer in i_rocket"



Any idea what could be wrong????

Last edited by Espér; 08/12/09 06:08.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: nearest entity on screen??? [Re: Espér] #284149
08/11/09 22:41
08/11/09 22:41
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
ok.. little problem ( see post above )...

Last edited by Espér; 08/11/09 22:41.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: nearest entity on screen??? [Re: Espér] #284210
08/12/09 08:09
08/12/09 08:09
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
i gues the pointer is destroyed by your rocket ore somthing else

Code:
if(close_ent != NULL)
//		{
			while(dist2 > 30 && my.x > -1600 && my.x < 1600 && my.y > -500 && my.y < 5000 && close_ent != NULL)
			{
				error("1")
				dist2 = vec_dist(my.x, close_ent.x);
				error("1")
				vec_set(temp, close_ent.x);
				error("2")
				vec_sub(temp, my.x);
				error("3")
				vec_to_angle(my.pan, temp);
				error("4")
				c_move(my, vector(50*time_step,0,0), nullvector, NULL);
				error("5")
				rocketeer();
				error("6")
				my.z = 0;
				error("7")
				wait(1);
			}
//		}




"empty"
Re: nearest entity on screen??? [Re: flits] #284219
08/12/09 09:08
08/12/09 09:08
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
no, not really.. i can see the model of the dummy-enemy all the time ( it´s not destroyed )..

Last edited by Espér; 08/12/09 09:11.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: nearest entity on screen??? [Re: Espér] #284223
08/12/09 09:30
08/12/09 09:30
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
dont know if this is the problem but you dont got the ";" afer the error("1")

and not importend but you wont need the wait(1); in this loop

you = ent_next(NULL); // retrieve first entity
while(you) // repeat until there are no more entities
{
...
// wait(1);
}


"empty"
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1