Page 1 of 1

help with clone actors

PostPosted: Mon Feb 11, 2008 6:40 pm
by mrgame
how would i make this work even if i cloned the actor. so only 1 would follow not all of them

if (player.x <terrorist.x + 200)
if (player.x >terrorist.x - 200)
if (player.y <terrorist.y + 200)
if (player.y >terrorist.y - 200)

{
MoveTo("Event Actor", 0.000000, 0.000000, 3.000000, "player", "map");
}



change terrorist so if there was 10 terrorists and i was close 2 one of them only 1 would follow

eg if (player.x <event actor + 200) but that dosnt work

Re: help with clone actors

PostPosted: Mon Feb 11, 2008 8:08 pm
by edh
You could loop through the terrorists with something like

Code: Select all
    Actor *actor;
    int i;
    int count = ActorCount("terrorist"); // "terrorist" would be replaced with actual actor name
    for(i = 0; i < count; i++)
    {
       sprintf(cloneName, "%s.%d", "terrorist", i); // need to malloc a character buffer called cloneName
       actor = getclone(cloneName); // get a pointer to a clone called "terrorist.1" for example
       if (player.x < actor->x + 200
            && player.x > actor->x - 200
            && player.y < actor->x + 200
            && player.y > actor->x - 200)
       {
           // do something awesome
       }
    }



Note: I'm not near my GE right now so that code is only a sketch

Re: help with clone actors

PostPosted: Mon Feb 11, 2008 8:22 pm
by DilloDude
If the event is on the actor you want to check (in this case the terrorist), you can just use this:
Code: Select all
if (player.x < x  + 200)
Code: Select all
    Actor *actor;
    int i;
    int count = ActorCount("terrorist"); // "terrorist" would be replaced with actual actor name
    for(i = 0; i < count; i++)
    {
       sprintf(cloneName, "%s.%d", "terrorist", i); // need to malloc a character buffer called cloneName
       actor = getclone(cloneName); // get a pointer to a clone called "terrorist.1" for example
       if (player.x < actor->x + 200
            && player.x > actor->x - 200
            && player.y < actor->x + 200
            && player.y > actor->x - 200)
       {
           // do something awesome
       }
    }


Looping through all clones this way can work, but it gets messed up if the actors are destroyed. I prefer to maintain an array, and loop through that.

Re: help with clone actors

PostPosted: Mon Feb 11, 2008 8:37 pm
by edh
I was thinking about it a little more, I think your question was about how to get 1 guy to follow (probably the closest guy).

In that case, you will want a function to calc min distance. Then iterate over each clone and find the one closest. Once you've found the closest, make him move.

your dist function could be something like
Code: Select all
int calc_dist(Actor * obj1, Actor * obj2)
{
   // pythagorean theorem here c = sqrt(a*a + b*b), maybe should return a double
}


then you would find the closest guy and do something with him

Code: Select all
Actor *closest;
int minDist = 0;
int newDist;

for(i = 0; i < count; i++)
{
    sprintf(cloneName, "%s.%d", "terrorist", i); // need to malloc a character buffer called cloneName
    actor = getclone(cloneName); // get a pointer to a clone called "terrorist.1" for example
    theDist = calc_dist(player, actor);
    if (theDist < minDist || minDist == 0)
    {
        minDist = theDist;
        closest = actor;
    }
}


// move closest actor or do whatever

Re: help with clone actors

PostPosted: Fri Feb 15, 2008 10:21 pm
by equinox
Hi at all,

Please: What must she make sprintf(cloneName, "%s.%d", "terrorist", i); // need to malloc a character buffer called cloneName

and as I use it?

Tnk1000 for reply.

P.S.:I have read and reread the script refence doc, but I find it hard to understand the operation of GE, in more' I must translate from the English in Italian...

Re: help with clone actors

PostPosted: Sat Feb 16, 2008 12:21 am
by DilloDude
sprintf writes a formatted string into another string. The first string (cloneName in this example) is the destination. Next is the format string, in this case "%s.%d". %s means print a string. %d (or %i) means print an integer. (for a full list of format types and things, go to http://www.acm.uiuc.edu/webmonkeys/book ... tml#printf ). Next are the variables to fill. First, in this case, is "terrorist", which is the string to put where th "%s" is in the format string. Then, is an int, i, used to replace the "%d". So, the final result depends on i. If i = 3, then cloneName will be set to "terrorist.3".

Re: help with clone actors

PostPosted: Sat Feb 16, 2008 1:53 am
by Bee-Ant
mrgame wrote:how would i make this work even if i cloned the actor. so only 1 would follow not all of them

if (player.x <terrorist.x + 200)
if (player.x >terrorist.x - 200)
if (player.y <terrorist.y + 200)
if (player.y >terrorist.y - 200)

{
MoveTo("Event Actor", 0.000000, 0.000000, 3.000000, "player", "map");
}



change terrorist so if there was 10 terrorists and i was close 2 one of them only 1 would follow

eg if (player.x <event actor + 200) but that dosnt work

Code: Select all
if(terorist.x<player.x+200&&terorist.x>player.x+5)
{
    terorist.x-=3;
    ChangeAnimation("terorist","walkleft",FORWARD);
}
if(terorist.x>player.x-200&&terorist.x<player.x-5)
{
    terorist.x+=3;
    ChangeAnimation("terorist","walkright",FORWARD);
}

Re: help with clone actors

PostPosted: Sat Feb 16, 2008 7:12 am
by equinox
Thanks1000 for the explanation,DilloDude. Perhaps you can still help me,please,, with "Clone INDEX":

In game maker I use,for istance:

ID = CreateActor (Hand, x, y);<---returb id'obj(or Actor in GE)

ID = 123450 <--id of object Hand...then I can do:

1 #ID.x = 10;..ID.FLAG = true..or
2 #(123450).x = 10.... is it used so', perhaps,CLONE INDEX?

Re: help with clone actors

PostPosted: Sat Feb 16, 2008 7:52 am
by Bee-Ant
What's clone Index used for anyway? :roll:

Re: help with clone actors

PostPosted: Sat Feb 16, 2008 9:24 am
by DilloDude
cloneindex is the number of the clone. It is a read-only actor variable. If you want to store a reference to an actor, use either a string or an Actor *(pointer to an actor). The CreateActor function returns an Actor *, so you can use this information for either:
Code: Select all
Actor *a = CreateActor(...
strcpy(string_value, a->clonename);
a->x = 10;

Then, if you want to get the actor using the string:
Code: Select all
Actor *a = getclone(string_value);
a->yvelocity = 18;

Re: help with clone actors

PostPosted: Sat Feb 16, 2008 9:28 am
by Bee-Ant
.... :roll: :roll: :roll:
Btw, when your Super-Human will come???
I never seen your game before

Re: help with clone actors

PostPosted: Sat Feb 16, 2008 11:15 am
by equinox
Hi Dude,
I have tried your code it is it works well, Tnk1000.

Actor* ACT, *ACT1;
ACT = getclone(ENEMY); <-----------------------------------global.code: #define ENEMY "enemy_1"
strcpy(NOME, ACT->clonename);
ACT1 = getclone(NOME);
ACT1->xvelocity = 2;
> work......

but if I write this code:... Where am I wrong?

//ACT1->xvelocity = 2;
DestroyActor("ACT1"); or DestroyActor(ACT1);....no.

Re: help with clone actors

PostPosted: Sat Feb 16, 2008 11:22 am
by DilloDude
DestroyActor uses a string, so you'd use:
Code: Select all
DestroyActor(ACT1->clonename);

Re: help with clone actors

PostPosted: Sat Feb 16, 2008 3:11 pm
by equinox
Yes,Dillo, works, thanks. I have tried:
DestroyActor (Name) == DestroyActor (ACT1 - > CLONENAME) / / Work
========================================
Now another question. This is VERYdifficult, at least for me.

I create a #1 Hero, I create #3 ENEMY. Hero against 3 ENEMY.

The hero shoots a bomb against one any of the 3 enemies. When the bomb collides with one of them, the bomb as it does to find the id of the enemy and therefore to destroy it or to get away HP?

I am reading getAllActorrsInCollision (...),,,but I don't succeed in finding the solution.
----------------------------------
My idea is: create an array of all the enemies and choose one of them, finding his x, y,, to be been able to launch the bomb to those coordinates of enemy.x/enemy.y. Can yuo,please, help me?

==============================================
Reading among the various posts, I have found this --> http://game-editor.com/forum/viewtopic. ... =getclone2
but I don't understand it. : ship.x = getclone2("transporterEnd", collide.cloneindex)->x;

but I believe that it am very useful...I believe...the part collides.cloneindex that seems useful.
=========================================
I am trying the function to collide, but something doesn't go. Are you able, please, can you look the code? PACMAN eats the yellow dots but also the blue sprite......and this must not happen, now.

Re: help with clone actors

PostPosted: Fri Feb 22, 2008 2:04 am
by DilloDude
In pacman->drawActor, check name, rather than clonename, and it should be 0. strcmp returns 1 if the strings are different:
Code: Select all
if(strcmp(actors[i].name, "PUNTO") == 0)

In a collision event, use 'collide' to access the collide actor:
Code: Select all
collide.HP-= 4;