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
5 registered members (Dico, AndrewAMD, TipmyPip, NewbieZorro, Grant), 15,791 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
Page 2 of 4 1 2 3 4
Re: 144655 entities instead of 5 entities... [Re: zwecklos] #185573
02/26/08 07:40
02/26/08 07:40
Joined: Mar 2007
Posts: 151
JokeSpeaker Offline OP
Member
JokeSpeaker  Offline OP
Member

Joined: Mar 2007
Posts: 151
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;

Re: 144655 entities instead of 5 entities... [Re: JokeSpeaker] #185574
02/26/08 08:50
02/26/08 08:50
Joined: Aug 2005
Posts: 312
Sweden
tindust Offline
Senior Member
tindust  Offline
Senior Member

Joined: Aug 2005
Posts: 312
Sweden
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

Re: 144655 entities instead of 5 entities... [Re: tindust] #185575
02/26/08 17:07
02/26/08 17:07
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
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
}



Re: 144655 entities instead of 5 entities... [Re: Xarthor] #185576
02/26/08 18:03
02/26/08 18:03
Joined: Mar 2007
Posts: 151
JokeSpeaker Offline OP
Member
JokeSpeaker  Offline OP
Member

Joined: Mar 2007
Posts: 151
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.

Re: 144655 entities instead of 5 entities... [Re: JokeSpeaker] #185577
02/27/08 02:07
02/27/08 02:07
Joined: Aug 2005
Posts: 312
Sweden
tindust Offline
Senior Member
tindust  Offline
Senior Member

Joined: Aug 2005
Posts: 312
Sweden
@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,

Re: 144655 entities instead of 5 entities... [Re: tindust] #185578
02/27/08 03:38
02/27/08 03:38
Joined: Sep 2005
Posts: 274
Switzerland - Zurich
zwecklos Offline
Member
zwecklos  Offline
Member

Joined: Sep 2005
Posts: 274
Switzerland - Zurich
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

Last edited by zwecklos; 02/27/08 03:47.
Re: 144655 entities instead of 5 entities... [Re: zwecklos] #185579
02/27/08 07:51
02/27/08 07:51
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
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.

Re: 144655 entities instead of 5 entities... [Re: testDummy] #185580
02/27/08 11:47
02/27/08 11:47
Joined: Mar 2007
Posts: 151
JokeSpeaker Offline OP
Member
JokeSpeaker  Offline OP
Member

Joined: Mar 2007
Posts: 151
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.

Last edited by JokeSpeaker; 02/27/08 11:50.
Re: 144655 entities instead of 5 entities... [Re: JokeSpeaker] #185581
02/27/08 12:00
02/27/08 12:00
Joined: Aug 2005
Posts: 312
Sweden
tindust Offline
Senior Member
tindust  Offline
Senior Member

Joined: Aug 2005
Posts: 312
Sweden
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;

Re: 144655 entities instead of 5 entities... [Re: tindust] #185582
02/27/08 17:29
02/27/08 17:29
Joined: Mar 2007
Posts: 151
JokeSpeaker Offline OP
Member
JokeSpeaker  Offline OP
Member

Joined: Mar 2007
Posts: 151
Thank you, your array helped me. I thank also all who helped me.
I hope the friends accept the pointers. ^^

Page 2 of 4 1 2 3 4

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

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