Temporarily disabling controls

mtrain

New member
How to temporarily disable controls in the middle of the level, saying for 10 seconds, to prevent player from performing attacks or movement, and to prevent 2nd player to enter game in this moment. Adding text entity with noskip is not a solution because i need another entity play an animation during this 10 seconds.
Thank you)
 
Using script, you toggle a flag called AI Control. This also works on player control. Not it also disables gravity and pretty much all movement checks, so while it's off you need to do any movement manually.

Look at Golden Axe Remake to see an example. After final boss goes down player control is disabled; the characters then walk up to the king and queen.

DC
 
You can use this script to disable players control

void DeControl(int P, int Flag)
{// Activates or deactivates control for defined player
// P : Player index starting from 0
// Flag : Control flag
    int Player = getplayerproperty(P, "entity");

    if (Player != NULL()){
      changeentityproperty(Player,"noaicontrol",Flag);
    }
}

Ex:
@cmd Decontrol 0 1

this will disable player 1's control

because i need another entity play an animation during this 10 seconds.

Ah that means that entity will run that function above
 
Thank you, guys for replies. The script is work, but still one thing is not solved. When player reach a some point of the stage there is entity appears play an animation and with script disable players movement, but still the second player can press enter and join the game during this animation. So 1st player stands while 2nd can walk. So how to disable start button as well?
 
Oh, i forgot to say that i already have set:
@cmd Decontrol 0 1
@cmd Decontrol 1 1
for first and second player, but it is not disabling a start button.
 
There doesn't seem to be scripted way to disable player's ability to join in game
However, the workaround I suggested is to spawn invisible entity which disables player control repeatedly. If player 2 joins, that entity will disable his/her control and prevent him/her from moving and disrupt whatever is going on

The entity which should spawn that is the entity which needs to do special animation. After animation ends, he/she/it will remove that invisible entity and give back control ability to players.
 
Ok, i solve the problem and it is working fine. My solving is next.
So, player have a spawn animation with next params:

anim Spawn
loop 1
offset 280 297
delay 1
frame data/chars/axel/q/x1.gif
frame data/chars/axel/q/x2.gif
frame data/chars/axel/q/x3.gif
frame      data/chars/axel/q/x4.gif
bbox  230  -400  100  100
frame data/chars/axel/q/x4.gif

It have a high placed invisible (from screen) bbox, and loop until it will be attacked.
In same time level starts with next trigger:

name trigreg
health 900
type panel
speed 10
shadow 0
facing 1

icon data/chars/misc/trigreg/trigreg.gif

candamage player

anim idle
#attack4 - 4 for regular
loop 1
delay 2
offset 0 0
#-----Remove at position-----------------
@script
    void self = getlocalvar("self");
    int XPos = openborvariant("xpos");

    if(XPos >= 1000){
      killentity(self);
    }
@end_script
#-----Remove at position-----------------
attack4  -50  -700  100  100  0  0  1  1  0  200
frame data/chars/misc/trigreg/trigreg.gif
frame data/chars/misc/trigreg/trigreg.gif
frame  data/chars/misc/trigreg/trigreg.gif
frame  data/chars/misc/trigreg/trigreg.gif


anim spawn
loop 0
delay 2
offset 0 0
frame data/chars/misc/trigreg/trigreg.gif
frame data/chars/misc/trigreg/trigreg.gif

It have attack box that placed same place as players spawn bbox, so it is instantly hits the last with attack4, forcing playing pain4 animation, which look next:

anim pain4
#regular spawn
  weaponframe 5 3
loop 0
jumpframe 2 7 2
landframe 5
loop 0
offset 280 297
delay 1
frame data/chars/axel/q/xr.gif
#------------jump at spawn
offset 280 285
frame data/chars/misc/empty.gif
delay 6
offset  300  285
frame data/chars/axel/q/1017.gif
delay  60
offset  280  285
frame data/chars/axel/q/1018.gif
delay 200
frame data/chars/axel/q/1019.gif
delay 6
sound data/sounds/land.wav
offset  300  285
frame data/chars/axel/q/1017.gif

So, player jumps from the edge of screen and on the 5th frame get a specified "weapon model". This "weapon model" is regular player. This method of spawning allows us within 1 level, force player to respawn with type of "weapon model" we need by using different triggers with specified attack# that force pain# anim. In my case, for example, player starts on the bike, then on the middle of the level he jumps from bike and continue to walk like a regular level. So, finally i reach, in what problem was. During this animation we need to change our trigger, because if player will death after bike riding, he must respawn as regular player, not on the bike. But if the second player press start and enter game, during this transforming (bike - jump - walk) animation, it will look really weird. So we need to disable controls, next way. Player jump from bike on scrollpos 1000, so i spawn next entities at 1000:

#Trigger that stops players movement and force playing SafeZone animation
name sftrigger
health 10
type enemy
nomove 1
shadow 0
facing 1
icon data/chars/misc/sftrigger/sftrigger.gif

nolife 1

lifespan 10

animationscript data/scripts/scenefx.c

anim idle
loop 0
offset 0 0
delay 1
frame data/chars/misc/sftrigger/sftrigger.gif
delay 850
frame data/chars/misc/sftrigger/sftrigger.gif
# @cmd DeControl 0 0
# @cmd DeControl 1 0
delay 1
frame data/chars/misc/sftrigger/sftrigger.gif

anim spawn
loop 0
offset 0 0
delay 1
# @cmd DeControl 0 1
# @cmd DeControl 1 1
@cmd    MovePlayer 0 0 0 0
@cmd    MovePlayer 1 0 0 0
@cmd    AnimPlayer 0 "ANI_IDLE"
@cmd    AnimPlayer 1 "ANI_IDLE"
frame data/chars/misc/sftrigger/sftrigger.gif
delay 100
frame data/chars/misc/sftrigger/sftrigger.gif
delay 1
@cmd    AnimPlayer 0 "ANI_FOLLOW10"
@cmd    AnimPlayer 1 "ANI_FOLLOW10"
frame data/chars/misc/sftrigger/sftrigger.gif

where the follow10 is jumping from bike.

#Trigger that decontrols player
name decontrol
health 10
type enemy
nomove 1
shadow 0
facing 1

nodieblink 2
falldie 1

icon data/chars/misc/sftrigger/sftrigger.gif

nolife 1

lifespan 9

animationscript data/scripts/scenefx.c

anim idle
loop 1
offset 0 0
delay 1
frame data/chars/misc/sftrigger/decontrol.gif
@cmd DeControl 0 1
@cmd DeControl 1 1
frame data/chars/misc/sftrigger/decontrol.gif

anim spawn
loop 0
offset 0 0
delay 1
@cmd DeControl 0 1
@cmd DeControl 1 1
frame data/chars/misc/sftrigger/decontrol.gif
frame data/chars/misc/sftrigger/decontrol.gif

anim death
loop 0
offset 0 0
delay 1
@cmd DeControl 0 0
@cmd DeControl 1 0
frame data/chars/misc/sftrigger/decontrol.gif
frame data/chars/misc/sftrigger/decontrol.gif

this entity decontrols player.

#Trigreg - trigger that checks player to respawn as regular
name trigreg2
health 900
type panel
speed 10
shadow 0
facing 1

icon data/chars/misc/trigreg/trigreg.gif

candamage player

anim idle
loop 1
delay 2
offset 0 0
attack5  -50  -700  100  100  0  0  1  1  0  200
frame data/chars/misc/trigreg/trigreg2.gif
frame data/chars/misc/trigreg/trigreg2.gif
frame  data/chars/misc/trigreg/trigreg2.gif
frame  data/chars/misc/trigreg/trigreg2.gif


anim spawn
loop 0
delay 900
offset 0 0
frame data/chars/misc/trigreg/trigreg21.gif
delay 2
frame data/chars/misc/trigreg/trigreg21.gif

And this trigger checks player respawn as regular.

What we have: level starts with trigreg that attacks player spawn bbox with attack4, forcing him to play pain4, in which player becomes a weapon model "on the bike". Trigreg will follow him as panel, and if he will die until scroll position 1000 he will respawn as on the bike. When we reach scrollpos 1000, players movement will stop with sftrigger, and controls will be disabled with decontrol, player will play follow10 anim (jump from bike ~ 9 seconds lenght) at the same time trigreg removes and appears trigreg2 (with delay in that 9 seconds), that allow player from this moment respawn as regular. This method not disable start button, but if player 2 press start during players 1 follow10 animation he will not appear on screen, because player 2 spawn anim is looped, because trigreg is already removed, trigreg2 have not appear until 9 seconds pass. As 9 seconds pass trigreg2 will instantly reach player 2 spawn bbox with attack5, plays pain5 anim, in which player becomes a weapon model - regular player, and he will appear on screen.

Hope this will help someone)
 
I try to use this scripts and works ok, but I have some problem to reactivate the control of the players.

Here my entity and the problem comes when using the Follow2:
Code:
name      cutscenes
type      none
offscreenkill   3000
subject_to_gravity 0
animationscript   data/scripts/sceneFX.c



anim spawn
   delay   10
   offset   1 1
   frame   data/chars/misc/empty.png


anim follow1
   delay   1
   offset   1 1
   @cmd noplayerJoin 1
   frame   data/chars/misc/empty.png
   @cmd   DeControl 0 1
   @cmd   MovePlayer 0 0 0 0
   frame   data/chars/misc/empty.png
   @cmd   DirPlayer 0 1
   @cmd   AnimPlayer 0 "ANI_IDLE"
   frame   data/chars/misc/empty.png
   @cmd   DeControl 1 1
   @cmd   MovePlayer 1 0 0 0
   frame   data/chars/misc/empty.png
   @cmd   DirPlayer 1 1
   @cmd   AnimPlayer 1 "ANI_IDLE"
   frame   data/chars/misc/empty.png
   @cmd   DeControl 2 1
   @cmd   MovePlayer 2 0 0 0
   frame   data/chars/misc/empty.png
   @cmd   DirPlayer 2 1
   @cmd   AnimPlayer 2 "ANI_IDLE"
   frame   data/chars/misc/empty.png
   delay   300
   frame   data/chars/misc/empty.png
   delay   1
   @cmd noplayerJoin 0
   frame   data/chars/misc/empty.png
   @cmd	   finishlevel 
   frame   data/chars/misc/empty.png



anim follow2
   delay   1
   offset   1 1
   @cmd noplayerJoin 1
   frame   data/chars/misc/empty.png
   @cmd   DeControl 0 1
   @cmd   MovePlayer 0 0 0 0
   frame   data/chars/misc/empty.png
   @cmd   DirPlayer 0 1
   @cmd   AnimPlayer 0 "ANI_IDLE"
   frame   data/chars/misc/empty.png
   @cmd   DeControl 1 1
   @cmd   MovePlayer 1 0 0 0
   frame   data/chars/misc/empty.png
   @cmd   DirPlayer 1 1
   @cmd   AnimPlayer 1 "ANI_IDLE"
   frame   data/chars/misc/empty.png
   @cmd   DeControl 2 1
   @cmd   MovePlayer 2 0 0 0
   frame   data/chars/misc/empty.png
   @cmd   DirPlayer 2 1
   @cmd   AnimPlayer 2 "ANI_IDLE"
   frame   data/chars/misc/empty.png
   delay   150
   frame   data/chars/misc/empty.png
   delay   1
   @cmd   DeControl 0 0
   @cmd   DeControl 1 0
   @cmd   DeControl 2 0
   frame   data/chars/misc/empty.png
   @cmd noplayerJoin 0
   frame   data/chars/misc/empty.png
   @cmd    killentity getlocalvar("self")
   frame   data/chars/misc/empty.png

As you see, in the end of follow2, I use Decontrol for reactivate the control in the 3 players. but I can not move until the player receives an attack from an enemy.
 
O Ilusionista said:
dantedevil whenever you post a function which is not native from the engine, please provide the said function on the topic :)

Ups! Sorry my friend, you're right.

Here the scripts of the entity:
Code:
void suicide()
{ // Suicide!!
    void self = getlocalvar("self");

    killentity(self); //Suicide!
}

void looper(int Frame, int Limit)
{// Loops current animation
    void self = getlocalvar("self");
    void loop = getlocalvar("Loop" + self);

    if(loop==NULL()){ // Localvar empty?
      setlocalvar("Loop" + self, 0);
      loop = 0;
    }
   
    if(loop < Limit){ // loops reach limit?
      updateframe(self, Frame); //Change frame
      setlocalvar("Loop" + self, loop+1); // Increment number of loops
    } else if(loop==Limit){ // loops reach limit?
      setlocalvar("Loop" + self, NULL());
    }
}

void DeControl(int P, int Flag)
{// Activates or deactivates control for defined player
// P : Player index starting from 0
// Flag : Control flag
    int Player = getplayerproperty(P, "entity");

    if (Player != NULL()){
      changeentityproperty(Player,"noaicontrol",Flag);
    }
}

void AnimPlayer(int P, void Ani)
{// Forces defined player to play certain animation
// P : Player index starting from 0
// Ani : Animation to play to
    int Player = getplayerproperty(P, "entity");

    if (Player != NULL()){
      performattack(Player, openborconstant(Ani));
    }
}

void IdlPlayer(int P)
{// Forces defined player to go to IDLE
// P : Player index starting from 0
    int Player = getplayerproperty(P, "entity");

    if (Player != NULL()){
      setidle(Player, openborconstant("ANI_IDLE"));
    }
}

void MovePlayer(int P, float Vx, float Vy, float Vz)
{// Forces defined player to move with defined speed
// P : Player index starting from 0
    int Player = getplayerproperty(P, "entity");

    if (Player != NULL()){
      changeentityproperty(Player, "velocity", Vx, Vz, Vy);
    }
}

void DirPlayer(int P, int Dir)
{// Changes defined player's direction
// P : Player index starting from 0
// Dir : Direction
    int Player = getplayerproperty(P, "entity");

    if (Player != NULL()){
      changeentityproperty(Player, "direction", Dir);
    }
}

void noplayerJoin (int iG)
{
// controls if other players can join the game or not
// 1 - players CAN NOT join, 0 play CAN join
// remember to set it 0 when you are done, or you will have a 1P only game.
// Douglas Baldan/O Ilusionista - 20/09/14
changeopenborvariant("nojoin", iG);
}
 
I've tested this and managed to reproduce the problem and also figured out a solution
First, this is the cause of the problem:
Code:
   @cmd   AnimPlayer 0 "ANI_IDLE"

This function despite stating IDLE in its parameter, forces player 1 in attack state. Because of that, after control is returned to player 1, player is not in IDLE
You should be using this instead:
Code:
   @cmd   IdlPlayer 0

Do the same for other players
 
Bloodbane said:
I've tested this and managed to reproduce the problem and also figured out a solution
First, this is the cause of the problem:
Code:
   @cmd   AnimPlayer 0 "ANI_IDLE"

This function despite stating IDLE in its parameter, forces player 1 in attack state. Because of that, after control is returned to player 1, player is not in IDLE
You should be using this instead:
Code:
   @cmd   IdlPlayer 0

Do the same for other players

Works perfect my friend!

Thanks! :D
 
Back
Top Bottom