144655 entities instead of 5 entities...

Posted By: JokeSpeaker

144655 entities instead of 5 entities... - 02/25/08 15:02

hi, I use A6 extra and scripted following code:
Code:
action enemy_creator
{
my.passable = on;
my.invisible = on;
while(1)
{
if(enemy_count < max_enemy_count) //max_enemy_count = 5
{
ent_create("speeder.mdl",my.x,enemy_flight);
enemy_count += 1;
}
wait(5);
}
}
action enemy_flight
{
counter += 1;
}



The creator should create 5 entities. But when I run it, it creates 144655 entities (I see it at the var counter and at the many entities) and enemy_count is 5! What I make wrong?
Posted By: zwecklos

Re: 144655 entities instead of 5 entities... - 02/25/08 15:59

I dont know exactly why it doesnt stop when the counter reachs 5, but to solve the problem, try to leave the while after your counter reaches 5.

if(entity_counter >= 5)
{
break;
}

put this within your while loop should work for you.
Hope this helps.

cheers
Posted By: Havoc22

Re: 144655 entities instead of 5 entities... - 02/25/08 16:15

just to test it, remove max_enemy_count and replace it with 5 and see if that works. Maybe max_enemy_count is being changed somewhere, or not defined as 5. If you replace it with 5 and it still does it, that's weird.
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/25/08 16:40

@zwecklos: This must while endless because if the enemy_count lose a worth, a new enemy should be created.

@Havoc22: It run still not right.

The first enemy are created right, but when all have an ent_move with moving ahead of themselves, the 144654 other enemys are at one position with very very little distances and flying very low, because they collide with the others.
Posted By: mpdeveloper_B

Re: 144655 entities instead of 5 entities... - 02/25/08 17:47

the problem could be because you created them at the my.x position of the first box, try using a random value, like:

Code:

action enemy_creator
{
var pos_;
////////set the maximum distance from the spawn box
var max_x_ = 300;
var max_y_ = 300;
var max_z_ = 0;
my.passable = on;
my.invisible = on;
while(1)
{
while(enemy_count < 5) //max_enemy_count = 5
{
vec_set (pos_.x, my.x);
pos_.x += random (max_x_) - random (max_x_ *1.5);
pos_.y += random (max_y_) - random (max_y_ *1.5);
pos_.z += random (max_z_) - random (max_z_ *1.5);
ent_create("speeder.mdl",pos_,enemy_flight);
enemy_count += 1;
}
wait(5);
}
}



i also changed the "if" to a "while" so that it should stop, although if it doesn't it'll create millions more, also, have you tried making max_enemy_count a local var instead?
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/25/08 19:28

It shouldn't stop, that always 5 enemys are here.
Yes, max_enemy_count is a local var.
Your random script functions, but now I have a very big swarm with 144566 enemys...

The script should always run, because I want endless 5 enemys. Enemy_count controls the count of the enemies and max_enemy_count controls the maximal count of enemies.
Posted By: Xarthor

Re: 144655 entities instead of 5 entities... - 02/25/08 19:33

Quote:


Yes, max_enemy_count is a local var.





And where did you define it INSIDE the action? I cannot see it (must be blind ).

Code:

action enemy_creator
{
my.passable = on;
my.invisible = on;
while(1)
{
if(enemy_count < max_enemy_count) //max_enemy_count = 5
{
ent_create("speeder.mdl",my.x,enemy_flight);
enemy_count += 1;
}
wait(5);
}
}


Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/25/08 19:41

Er, local is the definition outside of a function?

I meant max_entity_count is defined at start, not in function.

EDIT: Now are the models right, I don't know why Oo
But the var is 144655 and lose a worth if one enemy killed.

EDIT²: How can I set, while the creating, the enemies the pointers enemy1,...enemy5? And it should set right, so that no pointer is double, thus I mean when enemy2 is killed, the creator should'nt create an enemy5, but enemy2.
Posted By: Xarthor

Re: 144655 entities instead of 5 entities... - 02/25/08 21:12

nope local means inside a function/action
global means outside of it.

How did you define that var enemy_count?
This way:
var enemy_count;

or:
var enemy_count = 0;
Posted By: zwecklos

Re: 144655 entities instead of 5 entities... - 02/26/08 03:40

Dont know, its late, but maybe this is what you are looking for

Code:

recheck_if_I_have_to_create:
while(1)
{

if(enemy_count < max_enemy_count) //No enemies created yet or there are dead ones
{
ent_create("speeder.mdl",my.x,enemy_flight);
enemy_count += 1;
}
else//there are 5 enemies created atm
{
break;
}

wait(5);
}
goto recheck_if_I_have_to_create;




Hope this helps...

For your 2. question, use my.skill.
For example:
Code:

define ent_id;

action
{
id_counter += 1;
my.ent_id = id_counter;
}


Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/26/08 07:40

Quote:

For your 2. question, use my.skill.
For example:
Code:

define ent_id;

action
{
id_counter += 1;
my.ent_id = id_counter;
}






thx, but which code can now looking to the for example ent_id == 2? Should I write all enemies a pointer called enemy and then for example: if(enemy.ent_id == 2) {ent_remove(enemy);}
This code is only an example. That I need this way, because the friends should looking at the enemies and per random through the ids.
I hope, I write it understandable.

@Xarthor: with = 0;
Posted By: tindust

Re: 144655 entities instead of 5 entities... - 02/26/08 08:50

Suggested code based on your original script:

Code:
// Global definitions:
define enemy_number, SKILL51;
var max_enemy_count = 5; //max_enemy_count = 5 or whatever, can be changed in script
var enemy_count = 0;

// Actions:

action enemy_creator
{
my.passable = on;
my.invisible = on;
while(1)
{
if(enemy_count < max_enemy_count)
{
//get a randomized position here before creation if you want
ent_create("speeder.mdl",my.x,enemy_flight);
}
wait(5);
}
}

action enemy_flight
{
enemy_count += 1;
my.enemy_number = enemy_count;
while(1)
{
// set this entities enemy_number to 0 whenever you want it to die
if(my.enemy_number == 0)
{
ent_remove(me);
enemy_count -= 1;
// break; // automatic when enemy entity is removed
}
wait(1);
}
}





cheers
Posted By: Xarthor

Re: 144655 entities instead of 5 entities... - 02/26/08 17:07

bad code tindust. At least that enemy_flight action.
Better imho:
Code:

action enemy_flight
{
enemy_count += 1;
my.enemy_number = enemy_count;

while(my.enemy_number)
{
// set this entities enemy_number to 0 whenever you want it to die
// do whatever you want
wait(1);
}
wait(1);

ent_remove(me); //remove it
}


Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/26/08 18:03

Sry, but I meant something other, but this code is nice, too.

I need Pointers to the enemies. So that I can use the computer intelligence.

Now it must described more better, I hope.
Posted By: tindust

Re: 144655 entities instead of 5 entities... - 02/27/08 02:07

@Xarthor: Yeah I've coded it that or a similar way a few times, but my experience is that once in a while I get the code to proceed past the while loop. Why that happens is unclear. It shouldn't. I know the code in the post is not pretty but it works. In any case I would keep the line with -= 1 count down for each removed ent to keep the current enemy ent number between 0-5.

@JokeSpeaker: Do you mean that you want each enemy to have its own pointer id? You give each new created enemy that by keeping a running count as said earlier. Keep the var "total_enemies_created" counter in the beginning of the enemy action. Not sure I understand exactly what you want to accomplish ...

cheers,
Posted By: zwecklos

Re: 144655 entities instead of 5 entities... - 02/27/08 03:38

Hi there,
Again, Its late, and Im not sure if this gonna help you but is it a collision that causes the enemies death?
If yes, you could use an event to use the "you" pointer.

In the momemt, where a enemy dies trough a collision, the "you" pointer is set
to that enemies id. That means you can directly access the enemy's attribut with an event.

Code:

define ent_id, skill54;
var id_counter;

function check_death_id()
{
if(event_type == EVENT_IMPACT)
{
if(you.ent_id == 1) && (you.health <= 0)//enemy dies trough a collision
{
id_counter = 0;
enemy_count -= 1;
ptr_remove(you);
}

if(you.ent_id == 2) && (you.health <= 0)
{
id_counter = 1;
enemy_count -= 1;
ptr_remove(you);
}

if(you.ent_id == 3) && (you.health <= 0)
{
id_counter = 2;
enemy_count -= 1;
ptr_remove(you);
}

if(you.ent_id == 4) && (you.health <= 0)
{
id_counter = 3;
enemy_count -= 1;
ptr_remove(you);
}

if(you.ent_id == 5) && (you.health <= 0)
{
id_counter = 4;
enemy_count -= 1;
ptr_remove(you);
}
}
}

action enemy_creator()
{
...
check_if_I_have_to_create:
while(1)
{
if(enemy_count < max_enemy_count) //No enemies created yet or there are dead ones
{
ent_create("speeder.mdl",my.x,enemy_flight);
enemy_count += 1;
}
else//there are 5 enemies created atm and everyone is alive
{
break;
}

wait(5);
}
goto check_if_I_have_to_create;

}

action enemy_flight()
{

id_counter += 1;
my.ent_id = id_counter;

my.ENABLE_IMPACT = ON; // sensible for push collision
my.emask |= ENABLE_IMPACT;
my.event = check_death_id;
...

}



This code is not tested, maybe you can use the logical process behind it...
Important is, that you make sure that the "you" pointer is the hitten entity.
You can control this by using the impact-event(my.ENABLE_IMPACT = ON;) in the right action (for example on an action for a bullet or a player that hit the enemy).

cheers

zwecklos
Posted By: testDummy

Re: 144655 entities instead of 5 entities... - 02/27/08 07:51

Just theory, but similar works:
entity linked lists
Code:

define nunsI, 0;
define ratsI, 1;

function eCreate(_str, _index, _count) {
if (_str == 0 || _count < 1 || _index < 0) { // ops not optimized in C-Script
return(0);
}
// assumes ent_create does not fail?
while (elCount(_index) < _count) {
if (elAdd(_index, ent_create(_str, pos, fn)) == 0) {
break;
}
}
return(elCount(_index));
}
// ...
// 5 nuns
eCreate("nun.mdl", nunsI, 5);
// 2 rats
eCreate("rat.mdl", ratsI, 2);
// ...
entity* e0; // can use directly without pointer also
e0 = NULL;
// give me nun 3
e0 = eGet(nunsI, 3-1);
// give me 1st rat
e0 = eGet(ratsI, 1-1);


Assign values to locals.
http://testdummy93.tripod.com
Errors here?, Makes sense?, 'get it', use it or don't. I don't have the time.
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/27/08 11:47

I see, I explained it bad, sry.

First I explain it in german then in english. Maybe someone can translate it better as I.

German: Ich will eine Raumschlacht erstellen, in der der Player (Raumschiff) mit 4 computergesteuerte freundliche Raumschiffe gegen 5 computergesteuerte Feinde kämpft. Wenn ein Feind zerstört ist, wird sofort ein neuer erstellt. Die Feinde können nur durch Schüsse vernichtet werden. Sie haben ent_move, allerdings gehen sie nicht durch Kollision kaputt.
Und die Freunde suchen sich per random() zufällig einen Feind aus, Fliegen nur in dessen Richtung und schießen. DAZU brauche ich Pointer.
Das erstellen klappt gut, allerdings brauchen die Feinde je auch einen Pointer.

English: I want create a space-battle, in that the player fly a spaceship and he has 4 no-player-controlled (NPC) friendly spaceships. And they must fight with 5 enemies. If an enemy is destroyed, a new will be created. The enemies can be only destroyed by shots. They have ent_move but they don't get destroyed if they collide.
And the friends search per random() an enemy and fly only to him and shoot. FOR IT I need pointers.
The creating runs good, but the enemies needs all a pointer.


Short: I need only the script, in that the pointers will be set. All other I have.
Posted By: tindust

Re: 144655 entities instead of 5 entities... - 02/27/08 12:00

OK I see. Well, a pointer is essentially a var. So one way is to declare global pointers that are assigned when the enemy is created.

You could either assign pointers with individual names like:

var pEnemy_1;
var pEnemy_2;
...etc.

Then in the action of the enemy asign the pointer:

action enemy_flight
{
pEnemy_1 = me;
...
}

You could also use a pointer array:

var pEnemy[5];

and assign it through

pEnemy[1] = me;
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/27/08 17:29

Thank you, your array helped me. I thank also all who helped me.
I hope the friends accept the pointers. ^^
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/28/08 14:03

So I have now two problems.

1. At the (event_type == event_entity) the you is always null, too by collisions with entities. Which premises are for you that it will set right?

2. If the enemy looks with
vec_set(temp,you_pos);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);
to another entity, it will done suddenly and not soft. How can I make it, that it rotate slower to the another entity?
Posted By: tindust

Re: 144655 entities instead of 5 entities... - 02/28/08 16:42

For 1. I think you need to use event_impact,
For 2. You can do it several ways. If you want to make it look real and "organic" you need to use physics entities and apply rotational force so that the entity turns in a realistic way. Another way, which is a bit more "robotic" is to use a while-loop to change the rotation in small steps until the desired direction is reached.
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/28/08 18:03

1. I tested it yet with impact, but I will try it again.
EDIT: It didn't run, too. ><

2. Physics can't I use, for that my version is too low. And the other I tried, but it didn't run right. I will try it again, too. But it is nice, if someone can post me his idea.
Posted By: tindust

Re: 144655 entities instead of 5 entities... - 02/28/08 23:13

Here is a suggested (untested) code to try. You may have to play with the numbers a bit, but it should get you started.
Code:

function turn_toward_target
{
var original_direction[3];
var new_direction[3];
var pan_difference;
var pan_direction;

vec_set(original_direction,my.pan);
vec_set(temp,your.pos);
vec_sub(temp,my.pos);
vec_to_angle(new_direction,temp);

pan_difference = (360-new_direction.x) - (360-original_direction.x);
if((pan_difference > 0) && (abs(pan_difference) < 180))
{
pan_direction = 1;
}
else
{
pan_direction = -1;
}

while(my.pan != new_direction.x)
{
my.pan += pan_direction; // adjust angle increment by multiplying with 0.1 .. 10
wait(-time_step); // adjust turn speed by multiplying with 0.01 .. 100
wait(1);
}
}


Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/29/08 12:25

Thx, but it isn't run right. The entities shivered very quick and fly 90° to many. And in my version, time_step does'nt exist.
Posted By: tindust

Re: 144655 entities instead of 5 entities... - 02/29/08 16:42

Well, it was just a suggestion to get you started on the code . You will have to adapt it to your version and make it work for your purpose .
cheers,
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 02/29/08 17:43

ok, I will work at your script ^^

EDIT: I'm too stupid for this math. All my experiments failured.
Posted By: tindust

Re: 144655 entities instead of 5 entities... - 03/01/08 07:57

Here are two small adjustments to the code:
1/ use time instead of time_step (which version of Game Studio do you use?)
2/ Change the line

if((pan_difference > 0) && (abs(pan_difference) < 180))
to
if((pan_difference > 1) && (abs(pan_difference) < 180))
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 03/01/08 08:07

1. Time_step I yet writed in time.

2. Ok, I will test it.
EDIT: Now the entities fly always in a circle, how they have only pan += X;

I use A6 Extra.
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 03/02/08 13:23

sry for doubleposting, but I have a new question.

Run you by events only in event-functions or by if(event_type...) in the action, too?

And the "looking slower to another entity" still didn't run, although I tried many experiments...
Posted By: tindust

Re: 144655 entities instead of 5 entities... - 03/02/08 20:33

About the turning entity, I assumed you has assigned an action to it, it would not work without one. Anyway, here is a small action that you need to assign to the entity that is going to turn toward you. You can actually assign it to look at any other entity. The "you" pointer has to be assigned to whatever is going to be looked at. Also, the version of Game Studio is important. Prior to 6.4 "time" was used to correct the time factor for different computers. After that, it was changed to "time_factor". Look it up on a newer manual. (Found in the download area).

Edit: I included a line if(mouse_middle) just to give the option of starting the turn by mouse input. Remove it when it is not needed any more.

This action code works:

Code:
action a_turner
{
var original_direction[3];
var new_direction[3];
var pan_difference;
var pan_direction;
var turnspeed = 4;

while(1) // action goes on forever or entity is removed
{
// Check angles
you = player; // or whatever is going to be turned toward
vec_set(original_direction,my.pan);
vec_set(temp,your.pos);
vec_sub(temp,my.pos);
vec_to_angle(new_direction,temp);

if(mouse_middle)
{
// Turn if needed
if(abs(original_direction.pan - new_direction.pan) > 1) // only turn if not looking toward player (within +/- x degrees)
{
pan_difference = (360-new_direction.x) - (360-original_direction.x);
if(pan_difference < 0)
{
pan_direction = 1;
}
else
{
pan_direction = -1;
}

while(abs(my.pan - new_direction.x) > turnspeed)
{
my.pan += pan_direction * turnspeed; // adjust angle increment by multiplying with turnspeed

if(abs(my.pan - new_direction.pan) < turnspeed)
{
my.pan - new_direction.pan
}

// edited: added to ensure end to panning

wait(-time_step*0.01); // adjust step speed by multiplying with 0.01 .. 100
wait(1);

// (use time instead of time_step in Game Studio prior to 6.8)

}
}
}
wait(1);
}
}



cheers,
tindust
Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 03/03/08 13:02

Now the entities only use pan and do nothing other...

I post my currently action, which controls the enemies. All functions will describe in the comments:

Code:
action enemy_flight
{
wait(1);
var timer;
my.enable_entity = on;
my.enable_block = on;
var block_;
var my_pos[3];
my.moving = 1;
my.enemy_health = 2;
var you_pos[3];
var save_pos[3];
var save_id;
rolling_kind = int(random(3))+1;
if(int(random(2))+1 == 1) //set the rotating kind (pan or tilt)
{
rolling_dir = -1;
}
else
{
rolling_dir = 1;
}
if(enemy_nr[1] == 0) //set the pointer
{
enemy_nr[1] = my;
my.saving = 1;
}
else
{
if(enemy_nr[2] == 0)
{
enemy_nr[2] = my;
my.saving = 2;
}
else
{
if(enemy_nr[3] == 0)
{
enemy_nr[3] = my;
my.saving = 3;
}
else
{
if(enemy_nr[4] == 0)
{
enemy_nr[4] = my;
my.saving = 4;
}
else
{
if(enemy_nr[5] == 0)
{
enemy_nr[5] = my;
my.saving = 5;
}
}
}
}
}
npc_shoot_enemy(); //shooting function (the enemy shoots between 1 and 5 seconds)
while(me)
{
if(my.which_rocket == 1) //scan, which rocket has defeated him (the rocket set the skill)
{
str_cpy(scan_str,sc_8);
scan_.red = 255;
scan_.green = 0;
scan_.blue = 0;
my.which_rocket = 0;
}
while(my.klicked != 1) //random to choose the friend to kill
{
save_id = int(random(5))+1;
if(friend_nr[save_id] == 1)
{
break;
}
my.klicked = 1;
sleeper_();
wait(1);
}
friend1 = null;
friend1 = friend_nr[save_id]; //set the chosed friend in this pointer
if(block_ != 1)
{
if(friend1) //HERE IS THE PROBLEM (looking to the friend to kill him with the random shoots)
{
my.skill40 = 1;
vec_set(you_pos,friend1.x);
vec_set(temp,you_pos);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);
}
else
{
my.skill40 = 0;
my.klicked = 0;
}
}
if(friend1) //if the enemy is too near at the friend, he rotating
{
if(vec_dist(my.x,friend1.x) < 200) || (block_ != 0) || (event_type == event_block) || (event_type == event_entity) //the same, but by objects
{
my.pan += 5 * time;
block_ = 1;
}
if(vec_dist(my.x,friend1.x) > 500) || (event_type == null)
{
block_ = 0;
}
}
my_pos.x = enemy_speed*time; //flying speed
timer += 1;
move_mode = ignore_passable + ignore_passents + glide;
ent_move(my_pos,nullvector); //moving
if(my.enemy_health <= 1) && (timer > 5) //if enemy is short before exploding, a smoke-effect is behind him
{
if(int(random(3)) == 0)
{
effect(effect_splitter,1,my.x,normal);
}
randomize();
if(int(random(3)) == 0)
{
effect(effect_splitter2,1,my.x,normal);
}
randomize();
if(int(random(3)) == 0)
{
effect(effect_splitter3,1,my.x,normal);
}
randomize();
timer = 0;
}
else
{
if(my.enemy_health < 1) //exploding
{
effect(effect_splitter,350,my.x,normal);
effect(effect_splitter2,50,my.x,normal);
effect(effect_splitter3,50,my.x,normal);
effect(effect_explo,1000,my.x,normal);
ent_create("expl2+16.pcx",my.x,explo2);
ent_create("expl2+16.pcx",my.x,explo2);
ent_create("expl2+16.pcx",my.x,explo2);
ent_create("expl2+16.pcx",my.x,explo3);
//ent_create("ring.mdl",my.x,ring2);
wait(1);
str_cpy(scan_str,sc_9);
scan_.red = 255;
scan_.green = 0;
scan_.blue = 0;
enemy_nr[my.saving] = 0;
enemy_count -= 1;
ent_remove(me);
break;
}
}
wait(1);
}
}


Posted By: JokeSpeaker

Re: 144655 entities instead of 5 entities... - 03/07/08 18:54

sry, but I are stupid to write a script with the wished function...
© 2024 lite-C Forums