Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
c_scan and "you" pointer to closest entity? #188505
03/15/08 10:21
03/15/08 10:21
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
I know...this is simple stuff and has been asked before (even recently on this forum). Unfortunately all answers diden't really help me
I manage to get a handle on the closest entity but the handle won't switch when a second entity comes closer than the first.
I use "my.enemy" as skill to determine the current enemy.

Please...can someone post a piece of code that accomplishes that in a simple way (in good old c-script) ?

Thank you!

Re: c_scan and "you" pointer to closest entity? [Re: Loopix] #188506
03/15/08 12:27
03/15/08 12:27
Joined: Jul 2005
Posts: 1,930
Austria
Dark_samurai Offline
Serious User
Dark_samurai  Offline
Serious User

Joined: Jul 2005
Posts: 1,930
Austria
You have to do the scanning in a loop, so that you always have the right entity.
If you want more help, please post your code.

Dark_Samurai


ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)!
get free version
Re: c_scan and "you" pointer to closest entity? [Re: Dark_samurai] #188507
03/15/08 15:40
03/15/08 15:40
Joined: Aug 2005
Posts: 312
Sweden
tindust Offline
Senior Member
tindust  Offline
Senior Member

Joined: Aug 2005
Posts: 312
Sweden
Dark_Samurai is right, you need to put the scan in a refresh loop. Something like this:

Code:
while(scanner_is_on)
{
c_scan(blah);
wait(5);
}


No need to have the scan done every cycle, saves processing power. This will update the you pointer accordingly.

cheers,

Re: c_scan and "you" pointer to closest entity? [Re: tindust] #188508
03/15/08 19:02
03/15/08 19:02
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Thanks guys...I got it working (at least I think so...). I had to change my scan event like this:
Code:

var min_dist;
////scans for enemies
function scan_enemies()
{
min_dist = 999999;
////we are scanning
my.is_scanning = on;

////set scan mode
my.scan_mode = scan_search;

////set scan cone
temp.x = 360;
temp.y = 0;
temp.z = my.attack_range;

////do the search/scan
c_scan(my.x,my.pan,temp,ignore_me + scan_ents);

////wait a little before next scan (performance reasons)
wait(-scan_search_sleep);

////we have finished scanning
my.is_scanning = off;
}

function entity_search_scan_event_fight()
{
if(event_type == event_scan){

if(you){
////some conditions to set the handle
if(you.scan_mode == scan_search && vec_dist(you.x,my.x) < you.attack_range && you.entity_type_id >= 0 && you.allied_id != my.allied_id){


if(vec_dist(my.x, you.x) < min_dist)
{
min_dist = vec_dist(my.x,you.x);
you.enemy = handle(my);
}
}
}
}
}



Then I simple do like this in the entity action:
Code:


...

if(my.is_scanning == off)
{
////scan for enemies
scan_enemies();
}

if(my.enemy){

//get a pointer to the enemy!
you = ptr_for_handle(my.enemy);

//if the pointer is valid
if(you){
blablabla...do things!
}


}

...




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