Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,561 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Limiting c_scan #389147
12/10/11 21:37
12/10/11 21:37
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
I'm trying to make NPCs detect enemies using c_scan. This works when there's only one copy of the NPC, but when there are 2 next to each other, they can't find the enemies. This is because c_scan looks for the closest entity, which in the NPC's case, is the other NPC, rather than an enemy.

Is it possible to force c_scan to continue searching further and further if nothing can be found? That is, if this NPC's skill, "Team," is set to 1, then the c_scan finds the next closest thing, and continues searching until it finds something that has Team set to 2. Is that possible?

Thanks.

Re: Limiting c_scan [Re: Valdsator] #389149
12/10/11 22:08
12/10/11 22:08
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You can use EVENT_SCAN and for example handles:

#define enemy skill99

void enemy_event()
{
if(event_type == EVENT_SCAN) your.enemy = handle(me);
}

my.event = enemy_event;
my.emask |= ENABLE_SCAN;


...
In your NPC event:

if(my.enemy)
{
you = ptr_for_handle(my.enemy);
...
}


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Limiting c_scan [Re: Superku] #389169
12/11/11 00:47
12/11/11 00:47
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
I don't really understand what that does. So, the NPC's c_scan sets of the EVENT_SCAN of the enemy... does that activate enemy_event? What does that do?

Actually, hold on. I made a mistake, I might be able to get it to work now... tongue

EDIT:Alright, it works. Heh, thanks. laugh

EDIT2: Or... not. Now I have a different problem. The NPCs don't detect the closest enemy anymore. Anyone know why that might be? :|

Last edited by Valdsator; 12/11/11 01:13.
Re: Limiting c_scan [Re: Valdsator] #389172
12/11/11 01:39
12/11/11 01:39
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Ah I forgot, you have to do a distance check, of course:

#define enemy_dist skill98
#define enemy skill99

void enemy_event()
{
if(event_type == EVENT_SCAN)
if(result < your.enemy_dist) // result is automatically set
{
your.enemy = handle(me);
your.enemy_dist = result;
}
}

my.event = enemy_event;
my.emask |= ENABLE_SCAN;


...
In your NPC action:

my.enemy_dist = 1000; // your scan range
c_scan(my.x,...)
if(my.enemy)
{
you = ptr_for_handle(my.enemy);
...
}


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Limiting c_scan [Re: Superku] #389175
12/11/11 02:24
12/11/11 02:24
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
Ah, nice. Thank you!

Re: Limiting c_scan [Re: Valdsator] #389179
12/11/11 06:52
12/11/11 06:52
Joined: Dec 2003
Posts: 988
Germany, Magdeburg
JoGa Offline
User
JoGa  Offline
User

Joined: Dec 2003
Posts: 988
Germany, Magdeburg
Just a little workaround, mayby it helps:
I use c_scan for detecting, too. But also for collecting items, Share Xp, ... in my game. So I needed "different" c-scans. For this I use a gobal variable "indicator".
For every "scan-event" I define a other indicator, eg. int ind_detecting_enemies = 1; int ind_collecting_gold = 2; ....
Before every scan, i set the global indicator equal to the reason I scan: indicator = ind_detecting_enemies;
In the event of the NPC, I check, if the indicator was detecting_enemies - otherwise I would detect them if i collect gold :-)

Re: Limiting c_scan [Re: JoGa] #389195
12/11/11 14:13
12/11/11 14:13
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
Oh, that's clever. Although, I'm not really using this for a game, more like a simple "simulation," so that workaround isn't required. laugh

I have another question, though. At the moment the NPC's are getting in eachother's way trying to get to the enemy, so there's often a line of NPC's running at an enemy, while only one can reach them. Can I add a c_trace somewhere in there, so if an NPC can't see the closest enemy, it chooses the next closest?

EDIT: Alright, I tried something out but it doesn't seem to work. After the NPC sends out a c_scan searching for enemies, if it has found an entity, it does a c_trace from my.x (the npc) to you.x (the entitiy it found). This has ACTIVATE_SHOOT set. On the enemy action, I have emask set to ENABLE_SCAN as well as ENABLE_SHOOT.
Code:
my.emask |= ENABLE_SCAN|ENABLE_SHOOT;


In the enemy_event function I have it check for both of these.
Code:
if(event_type == EVENT_SCAN && EVENT_SHOOT){


So, what I'm thinking is, that if the c_trace can't activate the event_shoot, the NPC is obviously not in line of sight, and it doesn't think this entity is an enemy, which would make the NPC search for others. Problem is, it doesn't work.

I put a wall in front of an NPC. Behind the wall there's an enemy that's considered closer. On the side, there's an enemy that is farther away. If this c_trace were to work, the NPC should go for the enemy that's farther away, but it doesn't. Does the c_trace activate the EVENT_SHOOT even if there's an obstacle in the way? What should I do? D:

Quick replies would be appreciated, because I need to get this thing done. tongue

Last edited by Valdsator; 12/11/11 16:22.
Re: Limiting c_scan [Re: Valdsator] #389216
12/11/11 18:56
12/11/11 18:56
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
Well, as always, after posting a wall of text I've experimented more and solved the issue. It seems putting EVENT_SHOOT before EVENT_SCAN makes it work.

Yay.


Gamestudio download | 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