=Odin= 0 Posted November 27, 2007 G’day I’m having trouble to remove an action from an action menu, What I want to do is have an object to offer a menu to perform a certain action when within a certain distance. I am using a trigger to enable this script which works, Quote[/b] ]_plr = _this;_newAction = _plr addAction ["scratch", "scratch3.sqs", [],-1, false, false, ""]; _newAction = _plr addAction ["sniff", "sniff4.sqs", [],-1, false, false, ""]; but as soon as I add the removeAction line in the script I get an error. Quote[/b] ]_newAction = _plr removeAction ["scratch", "sniff",]; How can I get the object to stop running the script when I am not near it? full script Quote[/b] ]_plr = _this;_newAction = _plr addAction ["scratch", "scratch3.sqs", [],-1, false, false, ""]; _newAction = _plr addAction ["sniff", "sniff4.sqs", [],-1, false, false, ""]; _newAction = _plr removeAction ["scratch", "sniff",]; I,m new i've yet to learn strings Share this post Link to post Share on other sites
loyalguard 15 Posted November 27, 2007 I see two potential problems in the code. 1) You are using _newAction to store the action ID of both the actions you are using, so, once the second one is created it overwrites the first one. Â So, instead of this... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_newAction = _plr addAction ["scratch", "scratch3.sqs", [],-1, false, false, ""]; _newAction = _plr addAction ["sniff", "sniff4.sqs", [],-1, false, false, ""]; ...Try this... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_newAction1 = _plr addAction ["scratch", "scratch3.sqs", [],-1, false, false, ""]; _newAction2 = _plr addAction ["sniff", "sniff4.sqs", [],-1, false, false, ""]; ...or some other way of uniquely identify each variable (_actionScratch, _actionSniff, etc.) 2) The syntax for removeAction also needs adjustment. Â All you need to do is format it like this: unit removeAction index. Try this (assuming you structure AddAction as I exampled above): <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plr removeAction _newAction1; _plr removeAction _newAction2; Good luck! Share this post Link to post Share on other sites
=Odin= 0 Posted November 28, 2007 Thx LG. that works without out the error and fixed my 1st problem:) but now it wont let me use the action menu at all   What effect I am after is that when you are within the objects trigger zone it works but when your out of it, the action menu stops appearing for that object's action. I have read the wiki about this and thought it was a bit vauge on the removeAction topic  I am using this in the init Quote[/b] ]addAction = compile preProcessFile "addAction.sqf";exit and this in the trigger On Act; Quote[/b] ]myAction = player call addAction; On Dea Quote[/b] ]player removeAction myAction;  Revised SQF Quote[/b] ]_plr = _this;_newAction1 = _plr addAction ["scratch", "scratch3.sqs", [],-1, false, false, ""]; _newAction2 = _plr addAction ["sniff", "sniff4.sqs", [],-1, false, false, ""]; _newaction1; _newaction2; //wait _plr removeAction _newAction1; _plr removeAction _newAction2; Any ideas? Cheers Odin Share this post Link to post Share on other sites
nullsystems 0 Posted November 28, 2007 Anyone got any thoughts as to how to counteract a player addAction (personal one on you at all times ) disapearing after you die in MP? Share this post Link to post Share on other sites
loyalguard 15 Posted November 28, 2007 Thx LG. that works without out the error and fixed my 1st problem:) but now it wont let me use the action menu at all   What effect I am after is that when you are within the objects trigger zone it works but when your out of it, the action menu stops appearing for that object's action. I have read the wiki about this and thought it was a bit vauge on the removeAction topic If you are trying to add the action to an object, it is much easier to add it to the object itself and not to the player when in proximity to it.  This way you can avoid the use of a trigger as well if its only purpose is to trigger the addAction. if you add it to the object itself it will automatically appear in your action menu when you get close to it (5-10m). Here is some example code.  I don't know if you are using an object from the island, one you placed with the editor, or one you have created in a script so I will use an item placed in the editor named "Thing".  This is in sqf since I don't know sqs well.  It also expands on the example in the Biki.  I am only showing "scratch3.sqf" but "sniff4.sqf" would be similar of course. init.sqf <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_newAction1 = Thing addAction ["scratch", "scratch3.sqs", [],-1, false, false, ""]; _newAction2 = Thing addAction ["sniff", "sniff4.sqs", [],-1, false, false, ""]; scratch3.sqf <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_thing = _this select 0; //  The target of the action as designated in the init.sqf ( the bject named "Thing"). _id = _this select 2; // The index number of the action id so it can be referenced and removed after use. // Enter Code here that you want to happen when player selects "scratch" from the action menu _thing removeAction _id; / Remove the action from object after use. I hope this helps! Share this post Link to post Share on other sites
tj72 0 Posted November 28, 2007 So its not working at all now? If you add the action with the trigger and your getting the action (not sure if you are now) then the action can be removed to be sure, but I wouldnt use trigger on deactivate. You could have a second trigger that waits for the unit to be not present and removes the action upon activation. You could have a script start that loops and checks the units distance to centerpoint or a reference object /game logic. If the unit is over the distance to center point then run the remove action code. The on deactivate usage of the trigger seems problematic here. Im not sure if you want to remove the action based on distance from trigger or if action should remain untill used no matter how far from trigger. solutions exist for both cases but Im assuming the first method is what you want. If a killed event handler is added to the unit along with the action then a script can be started from that EH to wait for that unit to be alive again or standing/moving and the action can be added back from that script. So: unit dies > EH killed script starts and waits for the killed unit name to return a TRUE on a check if alive (this can be done other ways like check if unit canstand or canmove) > Unit respawns > Script detects alive unit == TRUE (or whatever condition is set) Â adds action back and exits. Airlift has a script called AL_Respawn to do this. Share this post Link to post Share on other sites
=Odin= 0 Posted November 30, 2007 Thank-you Loyalguard, That did the trick hehe maybe I can get some sleep tonight. Have'nt tried the trigger way yet TJ72, but have downloaded the airlift script for a Gandah, thanx mate <S> Odin Share this post Link to post Share on other sites