Jump to content
Sign in to follow this  
KTM_Calle

Delay between useraction?

Recommended Posts

Hey

I have a few useractions coded into my config.cpp, how do i do to insert a delay of 10 seconds before you can use an action again, after the first time?

Quote[/b] ]

Code Snippet

class digin

{

displayName="Dig-in";

position="proxy:bmpcommander.01";

radius=2;

condition="this animationPhase ""skyffel"" >= 0.5 and player in this and speed this <= 10";

statement="[this, 1] exec ""\own_103\scripts\jordhog.sqs""";

};

Share this post


Link to post
Share on other sites

I would do it something like this:

Create a function called RegisterAddon.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_MyAddon=_This Select 0;

_REGISTER_ADDON={(Format["%1",_AddonArray]=="scalar bool array string 0xfcffffef")};

If !(Format["%1",AddonArray]=="scalar bool array string 0xfcffffef") Then

{

_Found=False;

"If !(_Found) Then {If ((_x Select 0)==_MyAddon) Then {_Found=True}}" ForEach AddonArray;

If !(_Found) Then {AddonArray=AddonArray+[[_MyAddon,True]]};

}

Else

{

AddonArray=[[_MyAddon,True]];

GetAddonIndex=loadfile ("\MyAddon\GetAddonIndex.sqf");

};

And add this to your cpp:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init="RegisterAddon=loadfile ""\MyAddon\RegisterAddon.sqf""; [(_This Select 0)] Call RegisterAddon";

Create another function called GetAddonIndex.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_x","_MyAddon","_index","_result"];

_MyAddon=_This select 0;

_Index=0;

_Result=-1;

{If ((_x Select 0)==_MyAddon) Then {_Result=_Index} Else {_Index=_Index+1}} ForEach AddonArray;

_Result

For your actions condition, include something like this in your cpp:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">condition="((AddonArray Select ([This] Call GetAddonIndex)) Select 1)";

Create a script called SetAddonStatus.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_MyAddon=_This Select 0

_Index=[_MyAddon] Call GetAddonIndex

(AddonArray Select _Index) Set [1,False]

~10

(AddonArray Select _Index) Set [1,True]

And in the Actions statement include this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">statement="[This] Exec ""\MyAddon\SetAddonStatus.sqs""";

This is cobbled together from my own Addon so dont be suprised if it contains syntax errors. There are a few things you have to bear in mind, but this is the bear bones of what your after.

Share this post


Link to post
Share on other sites

Woah, that was a lot of code for a 10 second-delay biggrin_o.gif

Thank you for the help, i'll try it out  smile_o.gif

Edit: Incredible, it works! Thank you again very much Sgt_Wilson!

Share this post


Link to post
Share on other sites

Yes it is a bit long winded, but once its done it can use for just about anything.

I forgot to update this bit:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">If !(Format["%1",AddonArray]=="scalar bool array string 0xfcffffef") Then

Using Format on an array can be a bit dodgy, if it gets to big and you try and format it, it can cause a CTD. I did mean to change it so it checks a boolean instead.

If you did not notice, you can get rid of this bit:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_REGISTER_ADDON={(Format["%1",_AddonArray]=="scalar bool array string 0xfcffffef")};

But glad it does the job smile_o.gif

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  

×