a query about c_scan

Posted By: jigalypuff

a query about c_scan - 08/11/07 16:46

i am trying to write a targeting code, i figured c_scan would be the best thing for this as c_trace only goes in a straight line and this is for a spaceship, which should be able to scan all around itself. i want it to run all the time, but i`m a bit stumped on how this actually works, all the tuts seem to require a button being pressed, but i want it to scan automaticly then if it finds a target i want it to lock on to that target untill it is destroyed. i have a bit of test code and would dearly love some pointers on which way to work this, thanks.
Code:

function c_ship
{
player = my;
my.scale_x = 1.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
while(1)
{
if (key_1 == on)
{
c_scan(player.x, temp, vector(360, 60, 1000), ignore_me);

}
wait(1);
}
}

function f_ship
{
enemy = my;
my.scale_x = 2.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
my.enable_scan = on;
my.event = event_scn;
}

function event_scn()
{
if (event_type == event_scan)
{
ent_create(lockon, my.x, got_target);
}
}

function got_target
{
my.scale_x = 0.1;
my.scale_y = my.scale_x;////scale the sprite so it`s no huge

}


Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 17:10

Code:
function c_ship
{
player = my;
my.scale_x = 1.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
while(1)
{
c_scan(player.x, temp, vector(360, 60, 1000), ignore_me);
wait(-0.25); // we musn't scan every frame; c_scan is too slow for that
}

}



I just took out the IF statement and put in a larger wait value. It scans permanently every quarter second. See if that's more like what you're looking for?
Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 17:14

excellent job mate thanks, now to try and get it to work as a target lol. damn i spoke to soon, i added another enemy into the test and the targeting sprite also appears on that one, i need to be able to terget only one enemy at a time, is there a way to stop the scan after it has gotten the closest target and the nrestart after that enemy is dead?
Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 17:20

Well, for that I'd just write a script that makes the target entity always at the same location as the enemy (but a litte bit forward so it isn't clipped) and then just write a code that says if(something is targeted) { fire the weapon in the direction of the target and not the regular direction }

If you want your weapons to lock onto the target and "seek" it, that's deceptively easy as well. Just call vec_to_angle every frame during the movement function of the weapon.

If you want any examples or anything please let me know.
Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 17:23

examples would be great, it is far easier for me to look at code and figure it out than write my own from scratch, i`m a total novice at this lol
Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 17:29

For the target to follow the enemy around, I'd try this:

Code:

var enemy_handle; // a global handle we can use for transferring pointers

function event_scn()
{
if (event_type == event_scan)
{
enemy_handle = handle(you);
ent_create(lockon, my.x, got_target);
}
}

function got_target
{
my.scale_x = 0.1;
my.scale_y = my.scale_x;////scale the sprite so it`s no huge
you = ptr_for_handle(enemy_handle); // now YOU is the enemy
while(you)
{
vec_set(temp,player.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp); // turn the target toward the player

vec_set(temp,nullvector);
temp.x = 20; // change this if you need to - the distance in front of the enemy
vec_rotate(temp,my.pan);
vec_add(temp,your.x);
vec_set(my.x,temp);

wait(1);
}

}



The temp.x = 20 line might need to be temp.x = -20, but I'm not sure, I haven't done the math. Test that and see how it serves you.
Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 17:36

well that seems to work ok apart from the targeting sprite appears over both enemys, i need to target one at a time i added another enemy into the test and the targeting sprite also appears on that one, i need to be able to terget only one enemy at a time, is there a way to stop the scan after it has gotten the closest target and the nrestart after that enemy is dead? with the temp.x = i had to put 120, anything over that and they don`t appear, i`m guessing that 120 is how far away the enemy is from my ship
Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 17:44

Okay, cool. So in the player action, inside the while(1) loop, put the c_scan and stuff inside an "if(!you)" statement.

And, the temp.x value is actually the distance from the TARGET SPRITE to the enemy ship, not the player ship from the enemy ship. I just included that value so you could set the target a little in front of the enemy ship so that it doesn't look all bad. And P.S. - don't overestimate the size of quants. 120 quants is a pretty short distance. In fact, it's as far as the target sprite is away from the enemy ship.
Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 18:25

do you mean like this? cos the sprite no longer appears for some reason
Code:

function c_ship
{
player = my;
my.scale_x = 1.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
while(1)
{
if(!you)
{
c_scan(player.x, temp, vector(360, 60, 1000), ignore_me);
wait(-0.25);
}
wait(1);
}
}


Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 18:28

Hmm. Yeah that's what I meant. Try a you = null right before the while(1).
Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 18:53

ok tried that but no joy, the sprite still will not appear,
Code:

function c_ship
{
player = my;
my.scale_x = 1.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
you = null ;
while(1)
{
if(!you)
{
c_scan(player.x, temp, vector(360, 60, 1000), ignore_me);
wait(-0.25);
}wait(1);
}
}


Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 19:32

I'm testing my code and debugging it. I'll post the working version in a minute.
Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 19:36

Haha okay. I have a tendency to write really buggy code and then slowly debug it over time. It always ends up working, but I NEVER do it right the first time.

In any case, here's your whole code, which should work like magic.

Code:
 
function c_ship
{
player = my;
my.scale_x = 1.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
while(1)
{
if(you == null)
{
c_scan(player.x, temp, vector(360, 60, 1000),ignore_me+ignore_you);
}
wait(-0.25);
}
}

function event_scn();
function got_target();

function f_ship
{
my.scale_x = 2.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
my.enable_scan = on;
my.event = event_scn;
}

var enemy_handle; // a global handle we can use for transferring pointers
function event_scn()
{
if (event_type == event_scan)
{
enemy_handle = handle(me);
ent_create("cross.pcx", my.x, got_target);
}
}

function got_target
{
my.scale_x = 0.1;
my.scale_y = my.scale_x;
my.oriented = on;
my.facing = off;
you = ptr_for_handle(enemy_handle); // now YOU is the enemy
while(you != null)
{
vec_set(temp,player.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp); // turn the target toward the player
vec_set(temp,nullvector);
temp.x = 20; // change this if you need to - the distance in front of the enemy
vec_rotate(temp,my.pan);
vec_add(temp,your.x);
vec_set(my.x,temp);
wait(1);
}
ent_remove(me);
}


Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 19:51

i`m getting a parameter unknown event_scn bad keyword in {}

here is the event_scn it is the same as your code above is`nt it?
Code:

event_scn()
{
if (event_type == event_scan)
{
enemy_handle = handle(me);
ent_create(lockon, my.x, got_target);
}
}


o and thanks for all this help btw
Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 20:37

Yeah, it's the same, except yours just says event_scn, not function event scan. Was that just a post typo?

EDIT: And did you include the function protoypes from my code up there? ^^ Those are very important.
Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 20:59

man i`m a dunce, i forgot to write function, however the target sprite still is not appearing, here is all the code from the test level
Code:

string stars_mdl = "stars.mdl";
string galor_mdl = "galor.mdl";
string excelsior_mdl = "excelsior.mdl";

entity* enemy;

string lockon = "lockon+3.tga";
string cphaser_mdl = "cphaser.mdl";

bmap hempire_tga = "hempire.tga";

function stars();
function c_ship();
function f_ship();
function event_scn();
function got_target();
//function beam_weapons();

function main
{
///init_radar();
mouse_map = hempire_tga;
mouse_mode = 1;
level_load ("new_beginings.wmb");
wait(1);
ent_create (stars_mdl, nullvector, stars);
ent_create (galor_mdl, vector(0, 0, 0), c_ship);
ent_create (excelsior_mdl, vector(100,0,0), f_ship);
///ent_create (excelsior_mdl, vector(200,40,0), f_ship);
///ent_create (jungle_mdl, vector(1500, 10000, 0), planets);
///ent_create (clouds_mdl, vector(1500, 10000, 0), clouds);
///ent_create (jungle_mdl, vector(25000, 10000, 0), planets);
/// ent_create (clouds_mdl, vector(25000, 10000, 0), clouds);
while (1)
{
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;
wait (5);
}
}

function c_ship
{
player = my;
my.scale_x = 1.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
while(1)
{
if(you == null)
{
c_scan(player.x, temp, vector(360, 60, 1000),ignore_me+ignore_you);
}
wait(-0.25);
}
}

function f_ship
{
my.scale_x = 2.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
my.enable_scan = on;
my.event = event_scn;
}

var enemy_handle; // a global handle we can use for transferring pointersfunction

function event_scn()
{
if (event_type == event_scan)
{
enemy_handle = handle(me);
ent_create(lockon, my.x, got_target);
}
}

function got_target
{
my.scale_x = 0.1;
my.scale_y = my.scale_x;
my.oriented = on;
my.facing = off;
you = ptr_for_handle(enemy_handle); // now YOU is the enemy
while(you != null)
{
vec_set(temp,player.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp); // turn the target toward the player
vec_set(temp,nullvector);
temp.x = 20; // change this if you need to - the distance in front of the enemy
vec_rotate(temp,my.pan);
vec_add(temp,your.x);
vec_set(my.x,temp);
wait(1);
}
ent_remove(me);
}


Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 21:06

first put you = null back the player function. then try making the enemy transparent to see if the target is inside him. if so, inscrease the temp.x value.
Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 21:42

ok tried the you = null; still no joy, i also made the scale of the sprite bigger so i`d see it regardless of were it was, but it does not appear, here is the player function now i think i put the you = null in the right spot
Code:

function c_ship
{
player = my;
my.scale_x = 1.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
you = null;
while(1)
{
if(you == null)
{
c_scan(player.x, temp, vector(360, 60, 1000),ignore_me+ignore_you);
}
wait(-0.25);
}
}


Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 22:28

It's weird, I have your exact code running in SED and it works fine. The only other thing I can think of is that your player function has something else that's changing the YOU pointer for some reason. Try this.

entity* target_entity;

And then, in the player action, change the while loop to this:

Code:

while(1)
{
if(target_entity == null)
{
target_entity = c_scan(player.x, temp, vector(360, 60, 50),ignore_me);
}
wait(-0.25);
}



That might work?
Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 22:48

i think it must be me, what i have done is compile the level and zipped it, would you be good enough to dl it and look over the code, perhaps you`ll see were i`ve gone wrong, i know it`s a lot to ask mate.

http://www.4shared.com/file/21849860/893a13a5/test_level.html
Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 22:56

I'm taking a look as we speak, hold on...
Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 23:19

Okay, change the scan range to 1000 instead of 50 (I changed it to 50 for debugging... oops), and then change the target's scale to 0.1, not 10.1.
Posted By: jigalypuff

Re: a query about c_scan - 08/11/07 23:25

i had it at 10 so i`d see if it appeared lol, but hooray it works, just one other thing (aint there always lol) if there is more than one enemy in the level the targeting sprite appears over both enemy vessels, is it possible to just have it appear over one and then when it`s destroyed it`ll look for a new target? and thank you for all your help mate, it is truely appreciated
Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 23:28

I'm working on that right now.
Posted By: LogantheHogan

Re: a query about c_scan - 08/11/07 23:37

The problem was that the c_scan function was detecting the star dome, which was jacking everything up. I'm going to upload the fixed WDL file and send you the link in a PM.
Posted By: LogantheHogan

Re: a query about c_scan - 08/12/07 06:40

PM sent
© 2024 lite-C Forums