missing kyle 0 Posted May 16, 2017 Hey all, I'm trying to create a mission where the independent faction is treated as captive until they pick up a weapon, and then treated as an enemy until they drop the weapon again. I'm pretty new to the scripting side of the mission editor entirely, but this is the basic line I'm working with (which currently makes the AI not shoot you on sight). But I'm putting the following into the player's init. if (player hasweapon null) then (player setcaptive true); That line actually works when I have the default in-editor setcaptive option off, the problems start when I try to tack anything else onto it. if (player hasweapon null) then (player setcaptive true) else (player setcaptive false); Main example: this line doesn't work, and the AI always shoots on sight, regardless of what the player spawns with. { sleep 5; while {alive player} do { if (player hasweapon null) then (player setcaptive true) else (player setcaptive false); }; }; Ideally, I'd want something like this to continuously check if the player is armed or not, but it has the same effect as the above. Share this post Link to post Share on other sites
Wyqer 305 Posted May 16, 2017 Nothing tested or really confirmed, as I'm in a hurry right now. Maybe think about something like: while (true) do { if (count (weapons player) == 0) then {player setCaptive true} else {player setCaptive false}; sleep 0.5; }; But I would think it would be the best to work with a event handler instead of a loop. player addEventHandler ["InventoryClosed", { if (count (weapons player) == 0) then {player setCaptive true} else {player setCaptive false}; }]; That would run only after the inventory is closed (which is mostly needed to change if someone has a weapon or not). Or additional with Take, which is fired each time the player would take anything from a container (ground, box, vehicle, etc.). This would also catch if someone just use the action menu to take something from the ground. So with both event handlers you should have "everything" possible checked, where a player could get a weapon. player addEventHandler ["Take", { if (count (weapons player) == 0) then {player setCaptive true} else {player setCaptive false}; }]; Bot event handler can be added through initPlayerLocal.sqf or init.sqf. Share this post Link to post Share on other sites
pierremgi 4743 Posted May 16, 2017 [] spawn { waitUntil {sleep 0.5; count (weapons player - ["Rangefinder","Laserdesignator"]) == 0 && {["grenade",_x] call bis_fnc_inString} count magazines player == 0}; player setCaptive true; waitUntil {sleep 0.5; count (weapons player - ["Rangefinder","Laserdesignator"]) != 0 or {["grenade",_x] call bis_fnc_inString} count magazines player != 0}; player setCaptive false; }; Share this post Link to post Share on other sites
Belbo 461 Posted May 16, 2017 I find it kind of interesting, that so many people are asking for basically the same just in a couple of days. Again I recommend my undercover-script, if you're not afraid of making CBA a requirement for your mission: https://github.com/Pergor/ADV_MissionTemplate/tree/master/public/undercover #edit: Or, as of right now: The no cba-version. https://github.com/Pergor/ADV_MissionTemplate/tree/master/public/undercoverNOCBA Share this post Link to post Share on other sites
missing kyle 0 Posted May 16, 2017 Thanks for all the quick replies, got it working perfectly now. Share this post Link to post Share on other sites