Danskkat 2 Posted March 23, 2017 Eden baby here, still learning syntax and wondering what I am doing wrong with this: this setCaptive true;this addEventHandler ["FiredMan","this setCaptive false"]; I have ^ that ^ in the unit init in the hopes that the unit will remain captive (undercover, in this case) until they fire. Googling has revealed a few ways to make it so that everyone in a group is revealed (http://www.kylania.com/ex/?p=98 for example) but for this instance and future scripting how do you set it so that even if one person does the event only they are affected by the repercussions? (In the instance I'm working on currently, I want the rest of the "undercover" team to remain incognito even if one of them has to fire) Share this post Link to post Share on other sites
HallyG 239 Posted March 23, 2017 this is a special variable which, when in the init line of an object, has a value assigned to it. However, in the quotation marks after the "FiredMan" portion, the "this setCaptive false" is the datatype string- which is then compiled as a code. This can be seen in the parameters section of addEventHandler. The event handler has its own values assigned to the special variable, _this (see the section above the 'this' part in the first link I provided). _this variable stores the arguments provided, from the event handler, in an array. In the case of the "FiredMan" event handler, the provided arguments can be found HERE. Each element of an array can be accessed using the select or param(s) commands. The captive command takes an object as its first argument which, in this case, is the person who just shot. Therefore, to toggle the shooter's captive status, you need to pass their object to the captive command. This can be done by accessing the first element of the _this array. This is done by using '_this select 0'. Therefore change your code to: this setCaptive true;this addEventHandler ["FiredMan","(_this select 0) setCaptive false"]; 1 Share this post Link to post Share on other sites
killzone_kid 1330 Posted March 23, 2017 if (local this) then {this setCaptive true; this addEventHandler ["FiredMan", {_this select 0 setCaptive false; _this select 0 removeEventHandler ["FiredMan", _thisEventHandler]"}]}; Share this post Link to post Share on other sites
Danskkat 2 Posted March 23, 2017 hallyg - Good links, thank you. I have a lot of difficulty parsing that information but it's good to have a direct link to a page. Your third link is where I found the FiredMan and how I was trying to use it. So, excuse me if this sounds incredibly dumb but trying to figure out the logic -- The array for _this select 0 always applies to the unit which the init has the eventhandler in? So for example, a different unit with the eventhandler in its init's _this array would be a different set of numbers entirely? (Or to layman it because just typing that confused me. If Bob shoots, _this select 0 relates only to Bob because the eventhandler was written in Bob's init. So Greg shoots later, and his _this select 0 only relates to Greg because of HIS init eventhandler?) I ask because I saw that you can do eventhandlers through triggers and it seems to me that each time a person fires synched to that trigger, the _this select X is each person in order who fired. Side question, should I be adding a "remove eventhandler" at the end so that it doesn't keep watching for shots and repeatedly trying to establish a "setcaptive false?" Edit: Killzone_kid - What's the benefit of "if (local this)" at the beginning, and does that still go into the individual unit init? I do see that you added the remove eventhandler. You replied while I was typing this response :D Edit 2: Put this setCaptive true; this addEventHandler ["FiredMan", {_this select 0 setCaptive false; _this select 0 removeEventHandler ["FiredMan", _thisEventHandler]}] into the unit init as a mix of hallyg and Killzone_kid's input. Seemed to work, so thank you for that! 1 Share this post Link to post Share on other sites
killzone_kid 1330 Posted March 23, 2017 19 minutes ago, Danskkat said: Seemed to work The local needed so that JIP players will not trigger the init line again. This is not mix and match code, I gave you complete solution, if you want to break it be my guest but do not thank me for that then. Share this post Link to post Share on other sites
Danskkat 2 Posted March 23, 2017 killzone_kid - Easy, there. I didn't want to run the whole thing until I knew where it needed to go and what the benefit was. I recognized one section as something I could add and so I did. Try explaining what you post instead of just dropping a line of code, it'll help us newbies figure out what you're offering. I am glad to know that JIP bit of logic, however. So thanks regardless. Share this post Link to post Share on other sites