Jump to content
Sign in to follow this  
Festa_PWR

EventHandler "Take"?

Recommended Posts

Hi.

I wouldn't normally start a thread like this but i`ve been searching for some time now and i can't find anybody that has done anything with the "take" EventHandler.

I found references to the Biki, but taking that and putting it in-game is proving difficult for me, as i`m no scripting genius (as you`ll probably guess from laughing so hard at my attempt below).

What i have is a task (task1) that asks you to get explosives from a Zamak ("Zam1") and use them to destroy two empty T-100's (task2).

I would like the trigger from task1 to detect when 'DemoCharge_Remote' has been removed from the truck. This would then set task to complete and create the next task of destroying the tanks.

So far, i have thrown together the following in the trigger;

this addeventHandler ["Take", {vehicle player in thislist, Zam1, Democharge_remote;}]

but it throws up "Type Number, Nothing, expected Bool", but all that means to me is i made a hash of it and it doesn`t work. lol

If your wondering why i used "vehicle player in thislist", it's because the respawn script i`m using seems to render the 'presence of BlueFor' inoperable and it works for other triggers.

The mission can be played single and multiplayer, so do i understand correctly that i may have to use two different handlers for each type of gameplay?

However, for now, i would just like to get it working and worry about it working online later.

Share this post


Link to post
Share on other sites

Instead of using eventhandlers you could try something like counting the magazines (demo / satchel charges) left in the vehicle. When it has none left, then complete the task. Or combine it with the EH and make a check.

waitUntil {{_x == "satchelCharge_remote_ammo"} count magazineCargo theVehicle == 0 && {vehicle player in list triggerName}};

// complete the task here
// create new task here

---------- Post added at 15:16 ---------- Previous post was at 15:09 ----------

Or better yet, count the amount of charges the player has. Assuming you want the player to have multiple explosives (charges) before the objective is completed.

waitUntil {{_x == "satchelCharge_remote_ammo"} count magazines player == 2 && {vehicle player in list triggerName}};
// complete the task here
// create new task here

OR

combined with EH

takeEH = player addEventHandler ["Take", {_this execVM "whatHeTook.sqf"}];

whatHeTook.sqf

if ({_x == "satchelCharge_remote_ammo"} count magazines player == 2 && {vehicle player in list triggerName}) then {
   player removeEventHandler takeEH; 
   // complete the task here
   // create new task here
};

If you want to simply check and see if the player has taken only one explosive, then see what Mattar has done below.

Edited by Iceman77

Share this post


Link to post
Share on other sites

Bit of a muddle there :)

You need to add the EH to the player not the trigger.

I would have used it like this

_EHtakeIdx = player addEventHandler ["Take", {_this execVM "whatHeTook.sqf"}];

whatHeTook.sqf EH passes [unit, container, item]

_unit = _this select 0;
_container = _this select 1;
_item = _this select 2;

if ((_item == "satchelCharge_remote_mag") && vehicle player in list triggerName) then {hint "By jove, he's got it!";};

(untested)

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

Thanks chaps.

I figured i`d have all 4rse about face as it wasn`t working lol

What i had was a mashup of Biki stuff, forum posts and my interpretation of what i thought would work. Ah well, live and learn.

I like the simplicity of Iceman's suggestion, as i would like to steer away from even more SQF files. I would just change as follows;

waitUntil {{_x == "satchelCharge_remote_ammo"} count magazineCargo theVehicle [b][u]< 20[/u][/b] && {vehicle player in list triggerName}};

The idea being that the truck starts with 20 charges, so as soon as 1 is taken, it would kickoff the trigger and pass the task. I`m assuming that will work, but will test shortly. I`m also guessing this would go in the triggers INIT, but again, will test it out shortly.

I was actually using the DemoCharge, not SatchelCharge too, but may give it a go and see which i prefer.

Thanks again :)

EDIT:

Well, i`m officially crap at this. I`ve tried putting that code in the trigger and it gives me a Type number, Bool expected error and i`ve tried it in the truck and cant get it to trigger. I`ve changed 'theVehicle' to Zam1 and changed 'triggerName' to ZamTrig and still nothing.

Sorry for asking you to hold my hand on this one, but where do i put that code?

Edited by Festa_PWR

Share this post


Link to post
Share on other sites

Iceman'scode was for a script - to use in the trigger directly:

truckname: truck01

truck init

this addMagazineCargo ["SatchelCharge_Remote_Mag",20];

trigger:

activation: anybody

condition:

{_x == "satchelCharge_remote_mag"} count magazineCargo truck01 < 20 && vehicle player in thisList

(note: you had the classname wrong - ammo is what you place - you need the mag from cfgMagazines)

Share this post


Link to post
Share on other sites

Just another input...

As far as optimisation and smart scripting goes, use EH's as much as you can and avoid loops or waitUntil (basicly just a loop that checks its condition ever 0.5 second).

So you can use for your first task the "Take" EH and for your second the "Killed" EH and your mission will have no unnccesary cyles.

For your "Take" EH use this structire:

Init of your Unit

this addeventHandler ["Take", {_this execVM "takeFunction.sqf"}]

takeFunction.sqf

//_unit = _this select 0;
//_cargo = _this select 1;
_item = _this select 2;

if(_item == "myItemClassname") then {
//set task to true
};

For the Killed EH:

Init of the T-100

this addeventHandler ["Killed", {/*set your task to true*/}]

Share this post


Link to post
Share on other sites

Pretty much my 3rd suggestion uptop and mattar's first suggestion. I agree though. Use EH whenever possible.

Share this post


Link to post
Share on other sites

woops. ^^

I just floated over the thread and saw loop and waitUntil serval times after OP wantet to do it with a EH, so i thought i need to step in...

I need another coffee, i bearly see to my monitor ;)

Share this post


Link to post
Share on other sites

Thanks once again to all.

This is frustrating me so much that nothing seems to be making sense! I normally pick things up pretty quick i`ve always steered pretty clear of coding and such as it just doesn`t sink in.

I was sat looking at the Killed EH and wondering why TF would i need that, then it sunk in. lol

I current have a '!alive T1 && !alive T2' in the trigger for the task of destroying them and it works. So even though this doesn`t designate a waituntil or anything, is it still essentially looping until the conditions are met?

Either way, EventHandlers are better all round is the general consensus?

Thanks for your patience with me on this. I have had a read through the Biki, on various commands and techniques, but my eyes kind of glaze over and i just cant seem to retain any info on scripting. As i said before, it's very frustrating.

EDIT:

Just occurred to me that the Killed EH in the T-100's Init field is great, only the task asks to destroy two of them, so this would set task to complete if just one of them was destroyed.

I`m not too fussed about that though. Currently, i have a trigger that can complete that task so i`m happy. Just need to get my head around the DemoCharge bit :/

Edited by Festa_PWR

Share this post


Link to post
Share on other sites

Wow, did i make a meal of this.

Finally i have it working, but i`m almost sure, in fact pretty certain, it's not optimized.

Player Init;

takeEH = player addeventHandler ["Take", {_this execVM "VehInvTake.sqf"}] 

VehInvTake.sqf;

if({_x == "DemoCharge_Remote_mag"} count magazineCargo Zam1 == 19) then {
Trig1 setTriggerActivation ["ANY", "PRESENT", false];
}; 

While i was testing, i added 'hint's in there to check each stage, and if i add the 'Player removeEventHandler takeEH' it stops there and doesn`t actually remove the EH, as if i take another charge, it starts the script again.

I`ve kind of counteracted that by having it only activate when the Trucks inventory reaches 19, so it will only ever fire off once.

Trig1 currently sits in a state of activation = None, Present. So i had the script change that to Any, present when you take the charge to kick off the setTask = Succeeded. I just have to make sure its fire zone covers the truck you take the charges from.

Things made abit more sense tonight and i managed to get this hash-job working pretty quick.

Question though. The takeEH even handler will still be running right, as nothing has ended it? If i was to guess, and that's all i`m ever doing with this scripting at the moment, is the removeEventHandler isn`t working for me due to the nature of the variable?

Anyway, thanks again to you guys for giving me the direction for this. Without your help i would still be staring blankly at my screen and probably swearing at it too.

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  

×