Messiah 2 Posted February 26, 2009 (edited) Writing a top cover script that relies on using the hide animation to make personal weapons appear and disappear for a gunner to shoot with when he gets in. I originally wrote the script for OFP, but thanks to shoddy mp effects with setobjecttexture it couldn't work. Now with the hide animation it can, but now because of multi turrets I have more issues that before. The script is called like so: id="CODE">ukf_snatch_getin="[(_this select 0)] exec ""\ukf_landrovers\scripts\snatch_getin.sqs"""; in the getin script it would then check if the person who got into the vehicle got into the gunner slot, and then it would check his personal weapon and make the appropriate one appear for him to fire with. That bits fine. The that problem arises is that I now have two top cover positions (two turrets in effect) and what I need to know is after the script comfirms that the person who got in, got into a gunner position, but also WHICH TURRET he got into (so I can make the correct weapon appear on the correct turret) So, is it possible to check what turret someone got into, or failing that to see if a turret is occupied or not? Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
UNN 0 Posted February 26, 2009 (edited) The method I use is the AssignedVehicleRole command. If it returns a count of 2 i.e ["Turret", [turret path]] - Assigned to a turretHe got into turret. You can then use the turret path to determine which turret he got into. Something like this:_AssignedRole=AssignedVehicleRole _Unit; If ((Count _AssignedRole)>1) Then * * * *{ * * * *Switch (Str (_AssignedRole Select 1)) Do * * * * * * *{ * * * * * * *Case "[0,1]" : {Hint "Show Turret 1"}; * * * * * * *Case "[0,2]" : {Hint "Show Turret 2"}; * * * * * * }; * * * *}; Not exactly sure about the turret paths, you may have to check which path your gunners are returning. Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
Messiah 2 Posted February 26, 2009 (edited) ok, my sqf ability is 0, so I'm trying to work this into a script, so from what I can gather off the top of my head for sqs: _vehicle = _this select 0 ?!alive _vehicle:exit _assignedrole = AssignedVehicleRole (_this select 1) ?(_assignedrole select 1) = 1: goto "primarygunner" ?(_assignedrole select 1) = 2: goto "secondarygunner" exit #primarygunner _vehicle animate ["top_hatch", 1] _vehicle addweapon "ukf_sa80_topcover_one" _vehicle animate ["hide_sa80_primary", 0] exit #secondarygunner _vehicle animate ["top_hatch", 1] _vehicle addweapon "ukf_sa80_topcover_two" _vehicle animate ["hide_sa80_secondary", 0] exit I'm sure there's an error in there somewhere, but nothing that can't be found with testing. now, two other problems I can think of (now I have your attention, kind of) when a unit gets out, I want to undo the process above, but of course that requires the script to know which turret was left, but if thats not possible, then perhaps a script that checks everyone in the vehicle and queries their role and then only animates the hide weapon of the one that doesn't have a gunner? aaaaand, slightly related I suspect, but when the vehicle initialises at the start, and has gunners in, then a similar sweep would have to be done to in order to check if the hatch should be open, and if any weapons should be showing. ok, I know I may have suddenly come up with a hundred extra problems here, and I appologise. It would be so much more simple if I had kept it to one gunner and just do the old hasgunner stuff, but it seems a shame to not use multiturrets. Thank you for the help so far UNN, and yet again I had a funny feeling you'd be the first to reply. Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
UNN 0 Posted February 27, 2009 (edited) ok, my sqf ability is 0, so I'm trying to work this into a scriptAs much as I hate doing it Here's an sqs version, but I'm not sure if the syntax is 100% correct.snatch_getinout.sqs: _vehicle=_This Select 0 _hatch=_This Select 1 _gun=_This Select 2 ?!(Local _vehicle) : exit _AssignedRole=AssignedVehicleRole (_this select 1) ? ((Count _AssignedRole)==1) : exit _GunIndex=(_AssignedRole Select 1) Select 1 ? (_GunIndex==1) : goto "primarygunner" ? (_GunIndex==2) : goto "secondarygunner" exit #primarygunner _vehicle animate ["top_hatch",_hatch] _vehicle addweapon "ukf_sa80_topcover_one" _vehicle animate ["hide_sa80_primary",_gun] exit #secondarygunner _vehicle animate ["top_hatch",_hatch] _vehicle addweapon "ukf_sa80_topcover_two" _vehicle animate ["hide_sa80_secondary",_gun] exit The code should work for both get in and out events if I remember correctly. The get out event is called before the gunner actually leaves the vehicle. ukf_snatch_getin="[(_this select 0),1,0] exec ""\ukf_landrovers\scripts\snatch_getinout.sqs"""; ukf_snatch_getout="[(_this select 0),0,1] exec ""\ukf_landrovers\scripts\snatch_getinout.sqs"""; aaaaand, slightly related I suspect, but when the vehicle initialises at the start, and has gunners in, then a similar sweep would have to be done to in order to check if the hatch should be open, and if any weapons should be showing. Your init event would look something like this: id="CODE">init="{[_x,1,0] exec ""\ukf_landrovers\scripts\snatch_getinout.sqs""} ForEach (Crew (_This Select 0))"; ok, I know I may have suddenly come up with a hundred extra problems here, and I appologise. It would be so much more simple if I had kept it to one gunner and just do the old hasgunner stuff, but it seems a shame to not use multiturrets. Thank you for the help so far UNN, and yet again I had a funny feeling you'd be the first to reply. No worries mate, but there are a couple of other potential problems I can think of: 1) The MoveToBack\driver user action, if it's available? 2) MoveInGunner and setpos (for removing units) don't fire off any events. Although it would probably be a rare occurrence. You could cover all the above with say a single looping script that checks the gunner positions every second or so. But*the script runs on all the clients for each vehicle, alive in a mission. Nothing to processor hungry though, as it only has to check for a change in the assigned roles. Cheers Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
Messiah 2 Posted February 27, 2009 wow, thank you fella, the help is greatly appreciated its useful that the event is called before leaving, so that saves a lot of hastle. from my workings with a previous script in OFP, I found that on death a unit is still technically 'in' a vehicle, and I assume its the same for this. I'm not sure if extended eventhandlers can now detect a death of a unit in cargo like the normal eventhandlers ca detect the death of the vehicle itself, but the work around I used in that case was 'ejectdeadcargo' - looked a bit gash, but got the job done and didn't require looping death checks in the background. good point on the move to position, I don't want to lock this option because of the nature of the snatch (well it would be odd for anyone in cargo to have to get out and in again to take over top cover if someone dies) so a slow loop may have to suffice. I shall give these a bash today and see how it fares. I really do need to learn sqf it seems, but sqs was enough of a headache for me Share this post Link to post Share on other sites
UNN 0 Posted February 27, 2009 (edited) I really do need to learn sqf it seems, but sqs was enough of a headache for me I find the sqf format easier and quicker to write. So if you don't mind it in sfq, send us a pm and I'll do a continuous looping version if you’re stuck, won't take long to do. Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
Messiah 2 Posted February 27, 2009 (edited) well I'm stuck, but very much at the first hurdle, and with extended eventhandlers as always. Currently mine looks like this: class Extended_Init_EventHandlers { class ukf_snatch { ukf_snatch_init="_this exec ""\ukf_landrovers\scripts\snatch_startup.sqs"""; * }; }; so in my way of thinking, to add the other two eventhandlers would look something like: class Extended_Init_EventHandlers { class ukf_snatch { ukf_snatch_init="_this exec ""\ukf_landrovers\scripts\snatch_startup.sqs"""; ukf_snatch_getin="[(_this select 0),1,0] exec ""\ukf_landrovers\scripts\snatch_getin.sqs"""; ukf_snatch_getout="[(_this select 0),0,1] exec ""\ukf_landrovers\scripts\snatch_getout.sqs"""; }; }; but it flings up an error about a ; as ever Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
UNN 0 Posted February 28, 2009 (edited) Sorry mate, I just realized I hadn't accounted for the additional parameters in the example I posted: It should have been: id="CODE">_vehicle=_This Select 0 _unit=_This Select 1 _hatch=_This Select 2 _gun=_This Select 3 ?!(Local _vehicle) : exit _AssignedRole=AssignedVehicleRole _unit ? ((Count _AssignedRole)==1) : exit _GunIndex=(_AssignedRole Select 1) Select 0 Hint Format ["Here %1",AssignedVehicleRole _unit] ? (_GunIndex==0) : goto "primarygunner" ? (_GunIndex==1) : goto "secondarygunner" exit #primarygunner _vehicle animate ["top_hatch",_hatch] _vehicle addweapon "ukf_sa80_topcover_one" _vehicle animate ["hide_sa80_primary",_gun] exit #secondarygunner _vehicle animate ["top_hatch",_hatch] _vehicle addweapon "ukf_sa80_topcover_two" _vehicle animate ["hide_sa80_secondary",_gun] exit Then call it like this: id="CODE">ukf_snatch_getin="[_this select 0,_this Select 2,1,0] exec ""\ukf_landrovers\scripts\snatch_getinout.sqs"""; id="CODE">ukf_snatch_getout="[_this select 0,_this Select 2,0,1] exec ""\ukf_landrovers\scripts\snatch_getinout.sqs"""; Best to make sure the code I posted works as expected before trying it with the event handler. I've added a hint ot the script above so you can work out the turret paths. I tried the script with a 4x4 which returns a turret path of ["Turret",[0]]. So I had to change these lines accordingly: id="CODE">_GunIndex=(_AssignedRole Select 1) Select 0 Hint Format ["Here %1",AssignedVehicleRole _unit] ? (_GunIndex==0) : goto "primarygunner" ? (_GunIndex==1) : goto "secondarygunner" Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
Messiah 2 Posted February 28, 2009 (edited) no need to say sorry fella, you're helping me remember *:biggrin_o: One thing I'm not hugely sure about is how to do a init sweep with that script? As I said I need to do an initial sweep of the vehicle to ascertain if any gunners are in the vehicle to begin with, and then either leave the vehicle as it starts if it has people in (but open the hatch) or remove weapons if a turret is empty (or if both are empty) Is it a case of seeing if the vehicle contains units, and then pass those units through that script to check if they are in a turret position? (forgive me, but with scripts I either understand it fully, or I'm totally confused, never much of a middle ground) I also modified it slightly to be able to use just the one script, assuming my thinking is correct: _vehicle=_This Select 0 _unit=_This Select 1 _hatch=_This Select 2 _gun=_This Select 3 _status= _this select 4 ?!(Local _vehicle) : exit _AssignedRole=AssignedVehicleRole _unit ? ((Count _AssignedRole)==1) : exit _GunIndex=(_AssignedRole Select 1) Select 0 Hint Format ["Here %1",AssignedVehicleRole _unit] ? (_GunIndex==0) : goto "primarygunner" ? (_GunIndex==1) : goto "secondarygunner" exit #primarygunner _vehicle animate ["top_hatch",_hatch] _vehicle _status "ukf_sa80_topcover_one" _vehicle animate ["hide_sa80_primary",_gun] exit #secondarygunner _vehicle animate ["top_hatch",_hatch] _vehicle _status "ukf_sa80_topcover_two" _vehicle animate ["hide_sa80_secondary",_gun] exit and depending on wether its for the get in or get out, then the 5th string of the boolean would be "addweapon" or "removeweapon" - or I hope that will work. Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
Messiah 2 Posted February 28, 2009 (edited) ok, using a basic init that hid all the stuff that needed to be hid (and removed all the weapons, and having the 5th string as 0 or 1) I've got the following: id="CODE">_vehicle=_This Select 0 _unit=_This Select 1 _hatch=_This Select 2 _gun=_This Select 3 _status= _this select 4 ?!(Local _vehicle) : exit _AssignedRole=AssignedVehicleRole _unit ? ((Count _AssignedRole)==1) : exit _GunIndex=(_AssignedRole Select 1) Select 0 ? (_GunIndex==0) : goto "primarygunner" ? (_GunIndex==1) : goto "secondarygunner" exit #primarygunner _vehicle animate ["top_hatch",_hatch] ?(_status==1) : _vehicle addweapon "ukf_sa80_topcover_one" ?(_status==0) : _vehicle removeweapon "ukf_sa80_topcover_one" _vehicle animate ["hide_sa80_primary",_gun] exit #secondarygunner _vehicle animate ["top_hatch",_hatch] ?(_status==1) : _vehicle addweapon "ukf_sa80_topcover_two" ?(_status==0) : _vehicle removeweapon "ukf_sa80_topcover_two" _vehicle animate ["hide_sa80_secondary",_gun] exit works a treat visually, you get in, it makes the right stuff appear, and when you get out the right stuff vanishes. Blinding stuff. things that don't work: Switching positions, we know about this of course/ Addweapon - whatever I do, it always wants to add the secondary weapon, even if I get into the first turret slot, can't see where I've gone wrong here? Init, as mentioned before, for the initial sweep. Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
kremator 1065 Posted March 1, 2009 Wow - I have been following this thread with great interest. Sounds like a brilliant concept ! Here's hoping that you can sort it out Messiah. Will be great to see if for real in a mission ! Keep up the good work, and thanks for helping him UNN. [TAO] Kremator PS wish I was as talented as you guys ! Share this post Link to post Share on other sites
UNN 0 Posted March 2, 2009 (edited) no need to say sorry fella, you're helping me remember True, but I should have tested it first. It can be frustrating if you’re given an example that doesn't work. 2. Addweapon - *whatever I do, it always wants to add the secondary weapon, even if I get into the first turret slot, can't see where I've gone wrong here? Ahh..You have hit a limitation. They never updated all the commands when they added multiple turrets. You can only add and remove weapons from the first turret you define (I think). Unless you can find a better way, the only alternative I can think of is to define three turrets. The first turret you can add and remove your weapons as you already mentioned. For the second turret you hardcode the ukf_sa80_topcover_two and the third turret holds a dummy invisible weapon or no weapon and is automatically locked using a game logic. If a guy gets into the second turret when carrying the ukf_sa80_topcover_two, then you don't have to do anything. If he isn't carrying the specific weapon when he gets in, you move him to the third (empty) turret and place the gamelogic in the second turret to lock that. Not ideal and you will need some extra scripting to handle disabled vehicles and set the config to prevent the move to turret action menu options e.t.c 3. Init, as mentioned before, for the initial sweep. Perhaps it's not relevant given the above problem. But from an addons init you can make two assumptions. If the vehicle is empty there is no crew in any turret so hide everything, if it's crewed then all the turrets are occupied, so show everything. Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
Messiah 2 Posted March 2, 2009 (edited) I was afraid that would be the case a damn shame. Perhaps it's not relevant given the above problem. But from an addons init you can make two assumptions. If the vehicle is empty there is no crew in any turret so hide everything, if it's crewed then all the turrets are occupied, so show everything. It was more if someone where to crew the vehicle using movein commands and only added one top cover bod. Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
UNN 0 Posted March 2, 2009 (edited) It was more if someone where to crew the vehicle using movein commands and only added one top cover bod. I see, it will take me a little time to work it all out. But are you sure you want to go down this route given the problems with AddWeapon? It's not impossible to do, only it requires increasingly complex scripting and work rounds. Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
Messiah 2 Posted March 2, 2009 Been thinking about it, and assuming the add/remove weapon works fine on the primary station, then what I'll end up doing is making the primary station have the carried weapon detection, and the secondary always use an LMG. I really want to avoid as much scripting as possible, as thats what really sunk the snatch in OFP (well besides the loop check to see if anyone switched positions) Share this post Link to post Share on other sites
UNN 0 Posted March 4, 2009 (edited) Been thinking about it, and assuming the add/remove weapon works fine on the primary station, then what I'll end up doing is making the primary station have the carried weapon detection, and the secondary always use an LMG.Then you won't really need any of the turret path stuff for you looping script. You can use the Gunner command to find out who is in the primary turret. Something like this launched from the init for every client should be ok, hard to say without being able to test it with the target addons, but it's a start: _Vehicle=_This Select 0; _OldGunner=Gunner _Vehicle #Loop ? !(Alive _Vehicle) : goto "Exit" ? IsNull (Gunner _Vehicle) : _OldGunner=ObjNull; goto "Skip" ? !(Local _Vehicle) : _OldGunner=Gunner _Vehicle; goto "Skip" ? IsNull (_OldGunner) : _OldGunner=ObjNull; goto "Check" ? ((Gunner _Vehicle)!=_OldGunner) : goto "Check" #Skip ~0.1 goto "Loop" #Check _OldGunner=Gunner _vehicle ? !("ukf_sa80" In (Weapons _OldGunner)) : goto "Hide" ? ("ukf_sa80" In (Weapons _Vehicle)) : goto "Loop" _vehicle addweapon "ukf_sa80_topcover_one" _vehicle animate ["hide_sa80_primary",0] goto "Loop" #Hide _vehicle removeweapon "ukf_sa80_topcover_one" _vehicle animate ["hide_sa80_primary",1] goto "Loop" #Exit Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
Messiah 2 Posted March 5, 2009 (edited) Hadn't seen you'd replied here, so appologies. If having access to the addon would help you, then you know you're always more than welcome to take a gander. On the subject of the looping script above, if there are two turrets and only one guy switches seats, then you're going to need to turret path stuff? Been making the init sweep stuff, and I didn't think I was doing anything particularly wrong: in the init: ?(count (crew _unit) > 0) : ([_x, _unit] exec "\ukf_landrovers\scripts\initialsweep.sqs") foreach (crew _unit) so, checks if there's crew, if so then it passes each one into the init sweep script. _unit = _this select 0 _vehicle = _this select 1 ?!(Local _unit) : exit _AssignedRole=AssignedVehicleRole _unit _GunIndex=(_AssignedRole Select 1) Select 0 ? (_GunIndex==0) : goto "primarygunner" ? (_GunIndex==1) : goto "secondarygunner" exit #primarygunner _vehicle animate ["top_hatch",1] _vehicle animate ["hide_sa80_primary",0] exit #secondarygunner _vehicle animate ["top_hatch",1] _vehicle animate ["hide_sa80_secondary",0] exit And then that should check if anyone in that list of people starting in the vehicle are in a turret path and to then make the SA80's appear (SA80's are set to an initphase of 1 in the config, so we need to revert them to 0 to make them appear of course) Unfortunately it doesn't seem to work in that the sa80's never appear if there's a crew starting off in the vehicle. It seems to pass over to the sweep script ok, but somewhere after that I've mucked up the turret path stuff I suspect (even though its very much the same as the getinout script (and yes, I can see it could all be in one script, but for the way I map things out in my mind, I prefer seperate scripts so I know whats going on) [edit] doing some debugging, it seems everything is being passed correctly, but it seems that units that start off in a vehicle aren't assigned a role :confused_o: Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites
UNN 0 Posted March 6, 2009 (edited) doing some debugging, it seems everything is being passed correctly, but it seems that units that start off in a vehicle aren't assigned a role Not being sure what weapons you give to your default crew, I’m assuming it works the same as OFP. In that you can only define a single crew type for the entire vehicle? If so, then at startup you know that all the crew have the same weapon so you can just make all the mounted weapons visible for a crewed vehicle, without having to check each crewmember. Failing that, you can probably add a loop, that waits for the assigned roles to be allocated before running the rest of your script. I will PM you about the rest. Edited April 13, 2009 by W0lle Share this post Link to post Share on other sites