Jump to content

Recommended Posts

Hello I'm trying to create a battle royal zone type thing. I've been trying to use the sleep command and it does not seem to be working, Any pointers?  the error is 

'...= [1,2,3,4] call BIS_fnc_selectRandom; sleep 1; if (_random == 1) then {...' Error Generic error in expression.

Thanks

 

Share this post


Link to post
Share on other sites

Can't know if I will be able to help but writing the whole code will help solve the issue much better. Then scripters will be able to come in and be able to assist 👍

Share this post


Link to post
Share on other sites
25 minutes ago, JohnKalo said:

Can't know if I will be able to help but writing the whole code will help solve the issue much better. Then scripters will be able to come in and be able to assist 👍

Aye I'll send a picture soon

 

Share this post


Link to post
Share on other sites

Most likely the sleep is being called in an unscheduled environment. Post your code. 

  • Like 2

Share this post


Link to post
Share on other sites

Since I have issues with sleep as well... here is my piece of code 🙂

private "_this";
_this = _this select 0;

{

if (typeof _this == "LOP_ISTS_Infantry_SL") then { [_this, 1] call grad_moneymenu_fnc_addFunds;};

}    forEach allUnits;

{

if (typeof _this == "LOP_ISTS_Infantry_GL") then { [_this, 1] call grad_moneymenu_fnc_addFunds;};

}    forEach allUnits;

and so on...

This one is running non stop, how can I make it run only once or after certain amount of time? Both option would be great to know.

Share this post


Link to post
Share on other sites

Piece of code without environment (scope) is useless.There is no link with your previous post?? What is your aim??  We don't have crystal ball.

Where are you running that?

 

_this is a magic variable. Choose another local variable name.

 

 

 

  • Like 2

Share this post


Link to post
Share on other sites
14 hours ago, pierremgi said:

Piece of code without environment (scope) is useless.There is no link with your previous post?? What is your aim??  We don't have crystal ball.

Where are you running that?

 

_this is a magic variable. Choose another local variable name.

 

 

 

Sorry for that.
The purpose is to add an init to all newly spawned (certain types of) AI. The init will add some money to the AI using Grad's money framework, hence calling grad_moneymenu_fnc_setFunds.

description.ext part:

class Extended_Init_EventHandlers {
class Man {
init = "_this call (compile preprocessFileLineNumbers 'money.sqf')";
};
};

money.sqf part:

private "_this";
_this = _this select 0;

{

if (typeof _this == "LOP_ISTS_Infantry_SL") then { [_this, 100] call grad_moneymenu_fnc_setFunds;};

}	forEach allUnits;

{

if (typeof _this == "LOP_ISTS_Infantry_GL") then { [_this, 25] call grad_moneymenu_fnc_setFunds;};

}	forEach allUnits;

//and so on...

The issue:

money.sqf runs quite a few times (over a 100) before it stops, which results in too much money added to the AI and presumably not the best performance. I have tried to play around with sleep command, but can't get it to work, surely doing something wrong.

 

I didn't want to spam and create another topic about "help with sleep command", thus, the indirect relation to the initial post in this thread.

Share this post


Link to post
Share on other sites

OK, as Harzach wrote, sleep must run under scheduled scope. If this command is inside of money.sqf  script, just spawn it instead of calling it!

init = "_this spawn (compile preprocessFileLineNumbers 'money.sqf')";

same as:

init = "_this execVM 'money.sqf' ";

Not tested.

Spoiler

If any problem, keep in mind you can spawn instead call the part of code with sleep command (i.e. [_this, 25] spawn grad_moneymenu_fnc_setFunds;  if the sleep command is inside grad_moneymenu_fnc_setFunds

 

If too many occurrence for money, try to find a tighter condition for running the code. You can use the waitUntil command also (in scheduled scope also).

But I guess your problem is the use of allUnits which add money (as required by type of units) but multiplied by nbr of units, which is weird.

Example: you have a hundred of units, no matter their side, players or not, allunits will count them in forEach loop and a 25 pts of money will result in 2500 pts.

 

So, are you sure with your forEach allUnits loop? What is your final goal?

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks, I will try with the spawn option and waituntil.

I was thinking about the multiplying factor because of allUnits and earlier tried foreach unit group _this instead, but then it excluded all "server side spawned" AI and included only what was spawned by the Zeus.

Share this post


Link to post
Share on other sites


@FenixDK based on your code, you might do it like this:
Version without sleep:
Advantage of this is that you don´t have to create another file and just call it directly from description.ext . i assume grad_moneymenu_fnc_setFunds is already declared. And there is no need to compare type of unit. XEH does it for you.

//description.ext

class Extended_InitPost_EventHandlers {
    class LOP_ISTS_Infantry_SL {
                     class Money_init_eh {
                                          init = "[(_this select 0),100] call grad_moneymenu_fnc_setFunds";
                                         };
                    };
    class LOP_ISTS_Infantry_GL {
                     class Money_init_eh {
                                          init = "[(_this select 0),25] call grad_moneymenu_fnc_setFunds";
                                         };
                    };
};

Version with sleep:
There is a little more you have to do. Instead of compiling the same file over and over again i would declare it as global variable and spawn it like this. But i´m not sure why you would add money to unit after some time (it just doesn´t make sence to me). But you might use similar aproach in some other code.

//money.sqf

params ["_unit","_amount"];
sleep 5;
[_unit,_amount] call grad_moneymenu_fnc_setFunds;
//init.sqf or initPlayerLocal.sqf

TAG_fnc_Money = (compile preprocessFileLineNumbers "money.sqf");
//description.ext

class Extended_InitPost_EventHandlers {
    class LOP_ISTS_Infantry_SL {
                     class Money_init_eh {
                                          init = "[(_this select 0),100] spawn TAG_fnc_Money";
                                         };
                    };
    class LOP_ISTS_Infantry_GL {
                     class Money_init_eh {
                                          init = "[(_this select 0),25] spawn TAG_fnc_Money";
                                         };
                    };
};

Hope this helps 🙂 .

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites
On 11/9/2021 at 9:58 AM, soldierXXXX said:


@FenixDK based on your code, you might do it like this:
Version without sleep:
Advantage of this is that you don´t have to create another file and just call it directly from description.ext . i assume grad_moneymenu_fnc_setFunds is already declared. And there is no need to compare type of unit. XEH does it for you.


//description.ext

class Extended_InitPost_EventHandlers {
    class LOP_ISTS_Infantry_SL {
                     class Money_init_eh {
                                          init = "[(_this select 0),100] call grad_moneymenu_fnc_setFunds";
                                         };
                    };
    class LOP_ISTS_Infantry_GL {
                     class Money_init_eh {
                                          init = "[(_this select 0),25] call grad_moneymenu_fnc_setFunds";
                                         };
                    };
};

Version with sleep:
There is a little more you have to do. Instead of compiling the same file over and over again i would declare it as global variable and spawn it like this. But i´m not sure why you would add money to unit after some time (it just doesn´t make sence to me). But you might use similar aproach in some other code.


//money.sqf

params ["_unit","_amount"];
sleep 5;
[_unit,_amount] call grad_moneymenu_fnc_setFunds;

//init.sqf or initPlayerLocal.sqf

TAG_fnc_Money = (compile preprocessFileLineNumbers "money.sqf");

//description.ext

class Extended_InitPost_EventHandlers {
    class LOP_ISTS_Infantry_SL {
                     class Money_init_eh {
                                          init = "[(_this select 0),100] spawn TAG_fnc_Money";
                                         };
                    };
    class LOP_ISTS_Infantry_GL {
                     class Money_init_eh {
                                          init = "[(_this select 0),25] spawn TAG_fnc_Money";
                                         };
                    };
};

Hope this helps 🙂 .

Thanks a lot for the contribution. I also hope it will help someone else.

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

×