Jump to content
Sakuie

Implementation of scripts doesn't seem to work out

Recommended Posts

Hello everyone,

 

it's me again, asking some silly questions. Well, let's jump right ahead, shall we?

 

For some hours I've been researching on how to get scripts to start on themselves upon initialization. Nothing seem's to suit my problem well enough.

 

To be clear: the scripts are stored in this folder structure:

-@devAddon_sak

- -Addons

- - -dev

- - - -AnoGearAddition_scripts

- - - - -exec.sqf

- - - - -a_h_useVisor.sqf

 

Basically I tried running 2 if-statements, that'd determine, whether action1 or 2 is to be used. Initially it looked like this: (before anyone asks: since I started coding in gLua, I started to love if-statements for some reason...)

// a_h_useVisor \\
if (headgear player isEqualTo "anoHelmet_opened") exitWith {player addAction ["Close Visor", {player addHeadgear "anoHelmet_closed"}]};
if (headgear player isEqualTo "anoHelmet_closed") exitWith {player addAction ["Open Visor", {player addHeadgear "anoHelmet_opened"}]};

After a bit testing I came to the conclusion:"Well, maybe we need something to trigger it, how about that?"

 

So I created another script file, in which I wrote:

// exec \\
_handle = [] execVM "\dev\AnoGearAddition_scripts\a_h_useVisor.sqf"; //note, that \dev\ is the .pbo file in which everything is stored, obviously

Also didn't seem to work.

 

So I kinda reviewed the code a bit and that happened:

// a_h_useVisor \\
while (alive player) do
{
	if (headgear player isEqualTo "anoHelmet_opened") exitWith {player addAction ["Close Visor", {player addHeadgear "anoHelmet_closed"}]};
	if (headgear player isEqualTo "anoHelmet_closed") exitWith {player addAction ["Open Visor", {player addHeadgear "anoHelmet_opened"}]};
};

and

// exec \\
//_handle = [] execVM "\dev\SpectergearAddition_scripts\a_h_useVisor.sqf";

_triggerExec = createTrigger ["EmptyDetector", getPos player];
_triggerExec setTriggerText "Activate Script";
_triggerExec setTriggerArea [0,0,0, false];
_triggerExec setTriggerActivation ["ALPHA", "PRESENT", false];
_triggerExec setTriggerStatements ["this", "_handle = [] execVM ""\dev\AnoGearAddition_scripts\a_h_useVisor.sqf"""];

Also didn't work out (in the sense, that the given command couldn't be found. Either I looked up the wrong radio thingy, or i screwed up).

 

Now, what I also tried, was using an EvenHandler INIT on the 2 items in the CfgWeapons section themselves, but obviously it didn't work out, b/c according to what I've read so far: the INIT EventHandler only works in CfgVehicles. 

 

I've also tried calling a_h_useVisor through my dev console in the Editor, it didn't give me an error, but it did effectively nothing. :D

 

So there I am, not really knowing what to implement in which way. I am also "a bit" tired of looking everything up, though I still have to, I know, but some help from over here would boost me, obviously.

 

 

*BTW: yes I know: it could've also been done via animation on the model itself, yet then I would need to know how to properly implement the code for triggering the animation, but as of right now there's none given, and I got 2 models, one w/ the closed and one w/ opened visor.*

 

I can bet my soul for sure I did a silly mistake, so feel free to give me the teach-slap/spank.  :wub:

 

Much greets,

-Sakuie

 

 

 

/*

Edits:

first: grammatical correction of the title

second: grammatical correction of a phrase

*/

Share this post


Link to post
Share on other sites

Unless the "dev" folder is packed into a PBO (e.g. dev.pbo) none of this will work.

You're on the right track but your best bet is to add the Init Eventhandler to the class 'CAManBase' which pretty much every other unit class in the game inherits from.

However, simply adding the closed helmet wont work as all it'll do is go into the unit's inventory. You need to remove the open helmet, add the closed helmet and assign it correctly (all with as little delay as possible AND in that order).

Share this post


Link to post
Share on other sites

@Jackal326

 

Thank you, later tonight I will go ahead and try your suggestion out. Will report on it, when information has been gathered. ^^

 

Greets,

-Sakuie

Share this post


Link to post
Share on other sites

@Jackal326

 

So, I only had some time left on my schedule to work on my code.I feelvery dumb and on the wrong track. Anyways, here's the code.

//this is what CAManBase looks like in config.cpp/CgVehicles

class CAManBase: Man
    {
        class HitPoints
        {
            class HitHead;
            class HitBody;
            class HitHands;
            class HitLegs;
        };
        class Eventhandler
        {
            init="_handle = execVM ""h_titan_useVisor.sqf""";
        };
    };

and

//and is what it looks like in h_titan_useVisor.sqf, yes i did some renaming now again.
//and yes, i didnt follow your instruction to correct the "addHeadgear" part, since it seemingly does assign the headgear automatically,even if there's one alrdy assigned to a unit


while (alive player) do
    {
        if (headgear player isEqualTo "H_Titan_Helmet_O") exitWith {player addAction ["Close Visor", {player addHeadgear "H_Titan_Helmet"}]};
        if (headgear player isEqualTo "H_Titan_Helmet") exitWith {player addAction ["Open Visor", {player addHeadgear "H_Titan_Helmet_O"}]};
    };
hint "Success!";

I have to say: I feel like the two if-statements look fishy, but I don't have a way to avoid those just yet, especially b/c my in-depth understanding of SQF still need's to grow.

 

Greets,

-Sakuie

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

×