Create Entity pointers dinamicly (runtime)

Posted By: amadeu

Create Entity pointers dinamicly (runtime) - 05/23/07 20:30

Hallo,

In my game the player can create some entity in runtime.
I would like to know how I could create one pointer dinamic for this entity.
I have this code:
Entity* name;

But this code I have to write it before the action. I would like to create this code into one fuction like:
Function CreateEntityDim()
{
...
Entity* name;
...
}
I tried to do this, but it is not possible.
Someone knows how I could program this code into the function?

Thanks
Posted By: Slin

Re: Create Entity pointers dinamicly (runtime) - 05/23/07 20:50

What do you need this for?
you´ve got the my and you pointer. You can use my.parent as well.
If you need more then these pointer, use skills or vars:

my.skill30 = you; //skill30 is set to the handle
wait(1); //you is set to null every frame
you = my.skill30; //you points at the same entity as it did before the wait(1);
Posted By: amadeu

Re: Create Entity pointers dinamicly (runtime) - 05/23/07 21:09

In my game I could create many object dinamicly (one, two, three,...) and this object have one function in the game. To create these objects my game read one xml file and I can insert more object in xml. one example (I have 1 player and 1 arrow that follow the player):
Entity* Arrow1;
Entity* player1;

action CPlayer
{
player1 = me;
my.invisible = on;
}

action ArrowAvatar1
{
ArrowAv1 = me;
my.invisible = on;
}

function ArrAv1Pos()
{
while(1)
{
if(player1 !=null)
{
ArrowAv1.x = player1.x ;
ArrowAv1.y = player1.y - 250;
}
wait(1);
}
}

If I create in xml other player and arrow I muss programming before the pointers for these two new object but I want that the function create this entity pointers automatically into the function.

How could I do?
Posted By: tompo

Re: Create Entity pointers dinamicly (runtime) - 05/23/07 21:20

maybe I do not understand... but can't You do this with simple you pointer?
create next player and inside his action write:

you = ent_create("arrow.mdl",my.x,arrow_fun);
and then in arrow_fun in loop
my.x = you.x;
my.y = you.y - 250;

or in player action
my.skill70 = ent_create("arrow.mdl,my.x,null)
and in the same player action in loop
you = my.skill70;
you.x = my.x;
you.y = my.y -250;

Or I missed something
Posted By: amadeu

Re: Create Entity pointers dinamicly (runtime) - 05/23/07 21:28

thanks.

I have another question.
In my game I have 10 player (entity or avatars) and somewhere in the game I want to know where is the player5. How I could get the position (x,y,z) of player5 with yours solution? How would be the code?

thanks.
Posted By: Scorpion

Re: Create Entity pointers dinamicly (runtime) - 05/23/07 21:44

every player go at the begin of his action through a loop and put his pointer into an array, if u want to have the number 5 u just ahve to pcik the 5th array-element

Code:
action player
{
var i;
while(i<10&&i!=0)
{
i+=1;
}
player_ptr[i]=me;
}



if u want to get the position just write:
Code:
my=player_ptr[4];



edit: if you player 5 is a special entity u have to say it the engine per skill

so the action would be that way:

Code:
action player
{
player_ptr[my.skill1-1];//-1 becasueif he's player number 5he get the index 4
}


Posted By: amadeu

Re: Create Entity pointers dinamicly (runtime) - 05/23/07 21:54

Thanks again.
I did not understand the array:
player_ptr=me;
I need to define the array player_ptr?
What kind of object will be the array Player_ptr (variable, string, entity, etc)? and how I will define this array?

thanks
Posted By: tompo

Re: Create Entity pointers dinamicly (runtime) - 05/23/07 22:29

you may create a var and define
f.e.
var number_var;
define number,skill1;

then each time you create entity (player) add +1 to number_var;
something like:

number_var +=1;
you = ent_create(bla,bla,bla)
you.number = number_var;
so every player will have his own number skill

then if(you.number == 5){show me your position;}
like:
var avatar_pos[3];
if(you.number == 5){vec_set(avatar_pos,you.pos);}
it means...
avatar_pos.x = you.x;
avatar_pos.y = you.y;
avatar_pos.z = you.z;
Posted By: testDummy

Re: Create Entity pointers dinamicly (runtime) - 05/24/07 05:54

I think very few if any use it but...
Using entity linked lists / entity arrays plugin (eLL) I might find pos of player 5 like this:
Code:

entity* ent0;
define _id, skill38;

// create players
function plfCreate() {
var i = 0;
eLLsDelete();
eLLsNew(1);
while(i < 10) {
ent0 = ent_create(<player.mdl>, pos, function);
ent0._id = i + 1;
eLLPush(0, ent0);
i += 1;
}
}

// find player pos
function plfPosFind(id, &_pos) {
eLLNextReset(0);
ent0 = eLLNext(0);
while(ent0 != NULL) {
if (ent0._id == id) {
vec_set(_pos, ent0.x);
return(1);
}
ent0 = eLLNext(0);
}
return(0);
}

// plfPosFind(5, temp);


get eLL here (ver. 6.5 will be uploaded later)
© 2023 lite-C Forums