Controlled entities with script

O Ilusionista

Captain 100K
I am using Bloodbane's "keymove" to control an Entity which Black Widow spawns on her hyper move (the sniper aim) and it works for the player 1.

But if the player 2 uses Black Widow and uses that move, the aim won't move and can't be controlled by player 2 - but player 1 can controls it, even if he is not Black Widow.

Here is the code.

Code:
void keymove(float V)
{// Move hero if direction button is pressed
      void self = getlocalvar("self");
      int iPIndex = getentityproperty(self,"playerindex"); //Get player index
	float xdir = 0;
	float zdir = 0;

      if (playerkeys(iPIndex, 0, "moveleft")){// Left is pressed?
	  xdir = -V;
	} else if(playerkeys(iPIndex, 0, "moveright")){// Right is pressed?
	  xdir = V;
      }

	if(playerkeys(iPIndex, 0, "moveup")){// Up is pressed?
	  zdir = -V/2;
	} else if(playerkeys(iPIndex, 0, "movedown")){// Down is pressed?
	  zdir = V/2;
      }

	changeentityproperty(self, "velocity", xdir, zdir);
}

This also happens with the shoot. I am using BB's "keyint" function to tell the sniper aim entity to go to another animation once I press "A":
@cmd keyint "ANI_FREESPECIAL2" 0 "A" 0 0

And it works only with the first player too, and prevents P2 of shooting.
Here is the original function:
Code:
void keyint(void Ani, int Frame, void Key, int Hflag, int Limit)
{// Change current animation if proper key is pressed or released provided HP is more than limit
    void self = getlocalvar("self");
    void Health = getentityproperty(self,"health");    
    int iPIndex = getentityproperty(self,"playerindex"); //Get player index
    void iRKey;

      if (Key=="U"){ //Up Required?
       iRKey = playerkeys(iPIndex, 0, "moveup"); // "Up"
	}

      if (Key=="D"){ //Down Required?
        iRKey = playerkeys(iPIndex, 0, "movedown"); // "Down"
	}

      if (Key=="J"){ //Jump Required?
        iRKey = playerkeys(iPIndex, 0, "jump"); // "Jump"
	}

      if (Key=="A"){ //Attack Required?
        iRKey = playerkeys(iPIndex, 0, "attack"); // "Attack"
	}

      if (Key=="S"){ //Special Required?
        iRKey = playerkeys(iPIndex, 0, "special"); // "Special"
	}

      if (Key=="A2"){ //Attack2 Required?
        iRKey = playerkeys(iPIndex, 0, "attack2"); // "Attack2"
	}

      if (Key=="UJ"){ //Up and Jump Required?
        iRKey = playerkeys(iPIndex, 0, "moveup", "jump"); // "Up" + "Jump"
	}

      if (Hflag==1){ //Not holding the button case?
        iRKey = !iRKey; //Take the opposite condition
	}

      if ((Health > Limit)&&iRKey){
        changeentityproperty(self, "animation", openborconstant(Ani)); //Change the animation
        changeentityproperty(self, "animpos", Frame);

        if (Key=="UJ"){ 
          // This is copy of dethrown
          changeentityproperty(self, "attacking", 0);
          changeentityproperty(self, "damage_on_landing", 0);
          changeentityproperty(self, "projectile", 0);
        }
      }
}

From what I see, it gets the playerindex to determine who will gonna control it. But since the entity isn't a player, I think the engine doesn't knows who should controls it. Should the code be changed to get the Parent, instead of the playerindex?

Thanks.
 
keymove, keyint and other key related functions only work in player's text. It doesn't work in other entity's text
To make controllable entities, you need to make system which captures key press or release event and store in global variable
Since it's kinda complex, you should see an example in Map Demo. Paladin can spawn a disc whose movement can be controlled by player. Currently, it can't accept other orders yet but it can be expanded to that :)

BTW there's also system to kill the disc if Paladin is attacked while controlling the disc
 
I tried, but I had no luck.
Paldisc uses "animationscript hand.c", Paladin uses "keyscript palkey.c". Both are on my script folders.

I've added the code to the anim
@cmd ParMove 1
frame data/chars/enemies/sniper/aim.gif
But the aim doesn't moves.

Is there any other depedencie?
 
Yes, there's another script you're missing, it's keyall.c

As I posted above, the key press or release event is stored in global variable. keyall.c is the one doing that process

That reminds me, you'd need to update your endlevel.c to clear those variables
 
Oh, I see. But isn't keyall.c fired in every single key press or release from every players? Won't this affect the performance?
 
I don't know how much this will affect performance

Now I remember that this system was from shop system of Rise of Warduke. In that mod, all players have access to shop, therefore it will be better to use keyall.c
OTOH for Avengers, if you want, you could code personal keyscript just for Black Widow
 
Back
Top Bottom