Jump to content
Liberty Bull

Key activated bullettime script

Recommended Posts

*** Edit, working script for anyone interested. I am still very new so this is probably dirty and inefficient, but it works for what it is. This makes it so when you press T the player enters into a 1/10th speed "bullettime" that uses the player's stamina and applies a chromatic abberation postprocess effect while bullettime is active.

In "initplayerlocal.sqf"

Spoiler

moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 20 && var_vatsstop) then {var_vatson = [] execVM 'vats.sqf'};"];
moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 20 && !var_vatsstop) then {var_vatsoff = [] execVM 'vatsstop.sqf'};"];

 

In "vats.sqf"

Spoiler

private _timeLeft = getStamina player;
playSound "vatsenter";
var_vatsstop = false; 
  
  while {_timeLeft >= 0 && !var_vatsstop} do  
   
  {  
  
  
  ["ChromAberration", 200, [0.015, 0.015, true]] spawn { 
 params ["_name", "_priority", "_effect", "_handle"]; 
 while { 
  _handle = ppEffectCreate [_name, _priority]; 
  _handle < 0 
 } do { 
  _priority = _priority + 1; 
 }; 
 _handle ppEffectEnable true; 
 _handle ppEffectAdjust _effect; 
 _handle ppEffectCommit .1;
 waitUntil {var_vatsstop};  
 _handle ppEffectEnable false; 
 ppEffectDestroy _handle; 
};
  

    setAcctime .1;
  
    sleep .1;
    
    _timeLeft = _timeLeft - 3; 
setAccTime 1; 
player setStamina _timeleft;

  
 };
 
 setAccTime 1;
var_vatsstop = true;
playsound "vatsexit";

 

In "vatsstop.sqf"

Spoiler

setAccTime 1;
var_vatsstop = true;

 

And finally, either in "init.sqf" somewhere or in a trigger "on activation" with condition as "true"

Spoiler

var_vatsstop = true;

 

 

I'm trying to have a looping script end when a key is pressed. The script itself is called by a different keypress. The script works until I try and put in code to enable it to end midway through the loop. It is a simple bullettime script that drains your stamina during use, and it successfully ends when stamina runs out. I just cant figure out what I'm doing wrong to properly implement a breakout, or if that is even the best way to handle this.

 

private _timeLeft = getStamina player; 
playSound "vatsenter"; 
scopeName "main"; 

  while {_timeLeft >= 0} do   
    
  {   
  scopeName "vatsloop"; 
 
setAcctime .1;   
    hint str _timeLeft;   
   
moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 36) then   
  { 
   
  breakOut "vatsloop" 
   
   
   
  };" 
  ];


    sleep .1; 
  
    _timeLeft = _timeLeft - 1;  
setAccTime 1;  
player setStamina _timeleft; 
 
   
 };

 

Edited by Liberty Bull
Updated code and changed title for archiving purposes

Share this post


Link to post
Share on other sites

the breakout wont work because its inside another scope (in the EH)

 

also you have quotes inside quotes, that wont work. use ' instead of other quotes

  • Thanks 1

Share this post


Link to post
Share on other sites
2 minutes ago, gc8 said:

I cant see anything wrong with your breakOut but there's this line: ];

should be };

Changing the ]; that is just above the sleep .1 doesn't seem to work either, I took the whole displayAddEventHandler section from the code that I have in the initplayerlocal.sqf to run the script in the first place.

 

moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 35) then {var_vatson = [] execVM 'vats.sqf'};"];

 

Share this post


Link to post
Share on other sites
Just now, Liberty Bull said:

Changing the ];

 

nvm that  I misread your code. I have new stuff you to check out in my post

  • Thanks 1

Share this post


Link to post
Share on other sites
10 minutes ago, gc8 said:

the breakout wont work because its inside another scope (in the EH)

 

also you have quotes inside quotes, that wont work. use ' instead of other quotes

 

Ah, so I'm suffering the problems of learning by trial and error; I am trying to learn as I go and how to do things properly and all. If the breakout wont work I wonder what another solution would be. Maybe making the "while" have the _timeleft >= 0 && a variable that I set in a different script from the ending keypress so it sets it true?

 

All I need to do is make the script stop and then setAccTime back to 1, but I've never had to end a loop in such way before, and I seemed to have alot of trouble trying to incorporate multiple conditions for the while condition.

Share this post


Link to post
Share on other sites
5 minutes ago, Liberty Bull said:

Maybe making the "while" have the _timeleft >= 0 && a variable that I set in a different script from the ending keypress so it sets it true?

 

sounds like a good way imo

you can do that in the KeyDown EH

  • Thanks 1

Share this post


Link to post
Share on other sites

So, excuse my ignorance, but how do you call the variable in this case? The below doesnt work,

while {_timeLeft >= 0 && vatsstop = true} do

However, if I do 

while {_timeLeft >= 0 && alive docmitchell} do

It works and ends when I shoot the unit, so again this is where I am having trouble with the syntax. I'm reading through some of the beginner tutorials but I seem to miss this part.

Share this post


Link to post
Share on other sites

first set the variable and the loop condition:

vatsstop = true

while {_timeLeft >= 0 && vatsstop } do

 

then in your keydown EH  you set the variable to false:

 

vatsstop = false

 

that's it

  • Thanks 1

Share this post


Link to post
Share on other sites
6 minutes ago, gc8 said:

first set the variable and the loop condition:


vatsstop = true

while {_timeLeft >= 0 && vatsstop } do

 

then in your keydown EH  you set the variable to false:

 


vatsstop = false

 

that's it

 

Awesome, my issue was I was coming at it from the opposite way of thinking, trying to check if a variable was false, instead of true. Still don't know how to check if a variable is false as a condition but this way works. Is it !variable like !alive is?'

 

Edit, okay I found my answer, my google fu breaks down when there are multiple issues at once and its already mind frying  to learn as it is haha

if (typename _a != typename true) then { _a = false };
if (typename _b != typename 0) then { _b = 10 };

Share this post


Link to post
Share on other sites
Just now, Liberty Bull said:

Is it !variable like !alive is?

 

yep

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks for all your help. I try and learn as much as I can on my own before asking, but sometimes I get so stuck trying to make a function work that the whole mission  gets  put on hold while I try and get it to work. 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×