Jump to content
Sign in to follow this  
VonNexus

Hints and sideChat in a loop

Recommended Posts

Basically I made up a script that prevents normal soldiers from using sniper rifles , I called the file sniperCheck.sqf and I execute it in the init of soldiers. It works fine in the part where it checks if the unit has a sniper rifle and kills him after 10 seconds but it won't display the sidechat that warns the soldier that he cannot use the sniper rifle.

This is the code:

_soldier=_this select 0;


while {alive _soldier} do {
if (  (_soldier hasWeapon "M24")) then {_soldier sideChat  "Non sei un cecchino e non puoi usare questo fucile.Gettalo subito o sarai ucciso entro 10 secondi!"};  
sleep  10;
if (  (_soldier hasWeapon "M24")) then {_soldier setDamage 1};  
};



So how do I fix this?

Share this post


Link to post
Share on other sites

the sleep command is independent of the M24 checks, and the while loop runs independetly of it.

How it really works:

check->chat

10 sec wait

check->kill

check->chat

10 sec wait

...

It is almost sure that solider will take his gun while the 10 sec wait, and the next step is to kill him.

What you need is:


_soldier=_this select 0;   
while {alive _soldier} do 
{ 
  sleep 1; //to avoid too intensive looping
   if (_soldier hasWeapon "M24") then 
   {
       _soldier sideChat  "Non sei un cecchino e non puoi usare questo fucile.Gettalo subito o sarai ucciso entro 10 secondi!";
       sleep  10;       
       if (_soldier hasWeapon "M24") then 
       {
           _soldier setDamage 1
       };  
   };
};

Share this post


Link to post
Share on other sites

That sleep 1 will actually end up with far more intensive looping actually. You'll start the loop, wait a second, if the soldier has the weapon start the 10 second wait. If not you wait 1 more second and loop again.

The original code checked if they had the weapon, waits 10 seconds, then checks again and kills if they do. Then loops. So originally you loop every 10 seconds regardless. Rewritten you loop every second if they don't have the weapon.

That said the original code does work, but could use a sleep before the first check happens. If you start the game with the weapon the loop kicks off the and text is displayed before you're actually in game and you miss it. If you put a sleep 1 after the while it'll work how you expect and you'll see the text.

There's more problems with this anyway. A) it's flawed because if you pick up the weapon during the sleep you'll die once the sleep is done without any warning. B) it's a silly idea, if you don't want snipers don't put in sniper weapons. C) killing someone for having a certain weapon (which you gave them in the first place by making it available) is doubly silly. :)

What you'd want to do is keep track of if the player's been warned or not and only kill them if you'd warned them. Or make the check only kick off if they switch to/pickup the M24. All more complicated for an idea that's probably already been written. I'm sure a search for "weapon restriction" or something similar will result in a script to use.

Share this post


Link to post
Share on other sites

kylania: I guessed that he only wants to wait IF the solider has the weapon, to give 10 secs to let him put it away. And wants continous checking.

But otherwise sure, you are right. :)

Share this post


Link to post
Share on other sites

I'd done a "switched to weapon" thing before, but can't find it. :( My suggested check for "weapon restriction" did find a nice script from Pelham that removes restricted weapons though. Personally if you're gonna kill someone at least do it in style, like after the 10 seconds have a hint count down saying "drop it, for the love of all that's holy DROP IT!" and if they don't spawn and LGB on their face. heh

Share this post


Link to post
Share on other sites

He could just check if they have the weapon and if so remove it.


_soldier=_this select 0;

while {alive _soldier} do 
{

     sleep 1; //to avoid too intensive looping

     if (_soldier hasWeapon "M24") then     
     { 

           _soldier removeWeapon "M24"; 
          Hint "Your not allowed to carry that weapon."; 

     };
};

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
Sign in to follow this  

×