king_richard 10 Posted March 10, 2015 (edited) An AI controlled UAV script that is mostly working. But there's a few issues I have at the moment. 1. addEventHandler and the MP version both are not working for sidechat on dedicated server. The alternative is to create another block of code to check weapons #'s and then fire off a side chat when number decreases. ( That's what I've done for the time being ) 2. Bombing runs seem to be done around 250m - 350m, and if I increase the "flyInHeight" then the UAV will still descend to that altitude. Is there a simple way to force the AI to release bombs at a given altitude? I'd like for them to remain above 1000m at a minimum. 3. Setting the group ID is not syncing on a dedicated server, how may I do this within the script? -Thanks JShock for the tips, all gtg except for the dive bombing. RELEASE NOTES: I've included the original editing folder along with a pbo if you want to test it out. Forgot to include a read me so here it is: - Radio trigger is created in the description, I've just tweaked the example from the wiki. - init.sqf contains the code to add the radio trigger to the player ( eventually I'll add in restricting to player "x" ) - UAV_Master is the core of the script - UAV_radioPOS is a simple script solely to get players marker position when radio is triggered and feed that into the UAV_Master I'd suggest plopping this into the editor to check it out for a minute before adding it into your mission. Released as v0.8 ;) not that it matters but I call it about 80% done. There's some more checks I'll add down the road to get rid of messages when UAV first spawns in and when they return to previously called CAS position. Will also add in a RTB radio option to send the UAV home. It's now down to playing with it and seeing what else needs to be done besides the already mentioned. But, I'm a busy man so a final composition will take some time! Download >> https://docs.google.com/file/d/0B5jK56pciK37RXh6a05GNjhUa00/edit --Original Remainder of Original post in-case your curios--- _grp = group ((crew _vehicle) select 0); _wp1 = _grp addWaypoint [_vehiclepos, 100, 1, ""]; [_grp,1] setWaypointCombatMode "BLUE"; [_grp,1] setWaypointType "MOVE"; _grp setCurrentWaypoint [_grp, 1]; _goHOME = [_vehiclepos select 0, _vehiclepos select 1]; _grp setGroupId [_vehName]; I've spent too much time searching and experimenting so I'm now reaching out for help. Oh, and feel free to use the script if you'd like just don't be mad if it don't work how ya want! _frequency = 2; // Frequency to check vehicle status _spawnDelay = 5; // Respawn timer _combatRange = 500; // Range to go weapons free /**************************************************************************/ fnc_sideChat = { //_chatID = _this select 0; _chatID = [WEST,"HQ"]; _var = _this select 1; _state = _this select 2; _txt = 0; if (_state == 1) then { _txt = format ["%1 recieved coordinates, Enroute",_var]; }; if (_state == 2) then { _txt = format ["%1 is on site and awaiting target designation",_var]; }; if (_state == 3) then { _txt = format ["%1 is Dakota LGB's: RTB",_var]; }; if (_state == 4) then { _txt = format ["%1 is Bingo Fuel: RTB",_var]; }; if (_state == 5) then { _txt = format ["%1 has Rearmed",_var]; }; if (_state == 6) then { _txt = format ["%1 is back Online",_var]; }; _chatID sidechat _txt; publicVariable "fnc_sideChat"; }; if (isServer) then { /************************************************************************** The Rest of the Script - Edit at your own risk ***************************************************************************/ _vehicle = _this select 0; _NameCached = _this select 1; _oNL = objNull; // Loop until vehicle is valid if (_vehicle == _oNL)then { while {_vehicle == _oNL} do { sleep 0.5; _vehicle = _this select 0;}; }; // Get vehicle name and position _vehName = vehicleVarName _vehicle; _vehiclepos = getPos _vehicle; _vehicledir = getDir _vehicle; _classname = typeOf _vehicle; _flyHeight = _vehiclepos select 2; // Assign Home wp used to rearm/refuel and Loiter until called upon _grp = group ((crew _vehicle) select 0); _wp1 = _grp addWaypoint [_vehiclepos, 100, 1, ""]; [_grp,1] setWaypointCombatMode "BLUE"; [_grp,1] setWaypointType "MOVE"; _grp setCurrentWaypoint [_grp, 1]; _goHOME = [_vehiclepos select 0, _vehiclepos select 1]; _grp setGroupId [_vehName]; UAV_WP1 = _vehiclepos; _wp1POS = UAV_WP1; // Loop variables _run = true; _vehKilled = false; _combatREADY = true; _notified = false; sleep 1; _vehicle addMPEventHandler ["Fired", { (_this select 0) sideChat 'Bombs Away' }]; while {_run} do { sleep _frequency; if (!(alive _vehicle)) then { _vehKilled = true; sleep 1; }; if ((_vehicle ammo "GBU12BombLauncher" == 0) or (fuel _vehicle < 0.5)) then { _combatREADY = false; [_grp,1] setWPPos _goHOME; [_grp,1] setWaypointCombatMode "BLUE"; [_grp,1] setWaypointType "MOVE"; _grp setCurrentWaypoint [_grp, 1]; _vehicle flyInHeight _flyHeight; _wp1POS = _goHOME; }; if ((!(_vehKilled)) && _combatREADY) then { if (!(count UAV_WP1 == 0)) then { _distance = UAV_WP1 distance _wp1POS; if (_distance > 5) then { _grp = group ((crew _vehicle) select 0); [_grp,1] setWPPos UAV_WP1; [_grp,1] setWaypointCombatMode "BLUE"; [_grp,1] setWaypointType "MOVE"; _grp setCurrentWaypoint [_grp, 1]; _vehicle flyInHeight _flyHeight; _wp1POS = UAV_WP1; // Coordinates recieved message _vehChat = [[_vehicle,_vehName,1],"fnc_sideChat",nil,false] spawn BIS_fnc_MP; }; }; IF (combatMode _grp == "BLUE") then { _vehLocation = getPosATL _vehicle; _vehLocation = [_vehLocation select 0, _vehLocation select 1]; _distance = UAV_WP1 distance _vehLocation; if (_distance < _combatRange) then { [_grp,1] setWaypointCombatMode "YELLOW"; [_grp,1] setWaypointType "DESTROY"; _vehicle flyInHeight _flyHeight; // Ready to engage message _vehChat = [[_vehicle,_vehName,2],"fnc_sideChat",nil,false] spawn BIS_fnc_MP; }; }; }; if (!(_combatREADY)) then { if (!(_notified)) then { if (_vehicle ammo "GBU12BombLauncher" == 0) then { // Out of Ammo message _vehChat = [[_vehicle,_vehName,3],"fnc_sideChat",nil,false] spawn BIS_fnc_MP; }; if (fuel _vehicle < 0.5) then { // Bingo Fuel message _vehChat = [[_vehicle,_vehName,4],"fnc_sideChat",nil,false] spawn BIS_fnc_MP; }; _notified = true; }; _vehLocation = getPosATL _vehicle; _vehLocation = [_vehLocation select 0, _vehLocation select 1]; _distance = _goHOME distance _vehLocation; if (_distance < _combatRange) then { _vehicle setVehicleAmmo 1; _vehicle setFuel 1; _combatREADY = true; // Refueled/Rearmed message _vehChat = [[_vehicle,_vehName,5],"fnc_sideChat",nil,false] spawn BIS_fnc_MP; _notified = false; }; }; if (_vehKilled) then { sleep _spawnDelay; deleteVehicle _vehicle; sleep 4; // set vehicle position and name _vehicle = [_vehiclepos, _vehicledir, _classname, WEST] call BIS_fnc_spawnVehicle; createVehicleCrew (_vehicle select 0); sleep 0.1; _vehicle = _vehicle select 0; sleep 0.1; // name vehicle globally _vehicle SetVehicleVarName _vehName; missionNameSpace setVariable [_vehName, _vehicle]; publicVariable _vehName; _vehicle addMPEventHandler ["Fired", { (_this select 0) sideChat 'Bombs Away' }]; _grp = group ((crew _vehicle) select 0); _wp1 = _grp addWaypoint [_wp1POS, 100, 1, ""]; [_grp,1] setWaypointCombatMode "BLUE"; [_grp,1] setWaypointType "MOVE"; _grp setCurrentWaypoint [_grp, 1]; _vehicle flyInHeight _flyHeight; _vehChat = [[_vehicle,_vehName,6],"fnc_sideChat",nil,false] spawn BIS_fnc_MP; _notified = false; _grp setGroupId [_vehName]; // Respawn and init done! _vehKilled = false; _combatREADY = true; _notified = false; }; }; }; forgot to add, UAV_WP1 is updated via radio UAV_WP1 = _this select 0; publicVariableServer "UAV_WP1"; Edited March 11, 2015 by King_Richard Share this post Link to post Share on other sites
jshock 512 Posted March 10, 2015 (edited) sideChat is local to the machine that it runs on, use BIS_fnc_MP to broadcast it to everyone. And extra note for your fnc_sideChat I would use a switch instead of all the if statements. Example BIS_fnc_MP with sideChat: [[_unit,"Text to say here"],"sideChat",true,false,false] call BIS_fnc_MP; EDIT: Same thing for setGroupID, it is local to the machine it is ran on and needs to be broadcasted to all clients: [[_grp,[_vehName]],"setGroupID",true,false,false] call BIS_fnc_MP; Edited March 10, 2015 by JShock Share this post Link to post Share on other sites
king_richard 10 Posted March 10, 2015 (edited) JShock, I saw some examples using the Bis_fnc_MP however when called within my script I kept getting "error undefined variable" using ...."[_vehicle,"Side Text"]..... which is why I resorted to the function method that I've had success with tricky dedicated server issues as I'm not well versed in how to handle locality issues despite reading multiple multiplayer scripting guides! And a switch would clean it up nicely, got carried away with copy/paste ;) Thanks, Richard EDIT: I see where your headed now; Very much appreciated and I'll withhold further comments until I review your critique. Edited March 10, 2015 by King_Richard Share this post Link to post Share on other sites
jshock 512 Posted March 10, 2015 Well then, I would say you have an undefined variable going into it then, where/how were you using it when that occurred? Share this post Link to post Share on other sites
king_richard 10 Posted March 10, 2015 The script for the time being is named "UAV_Master.sqf" called by UAV placed in the editor the following code in it's init: null = [this] execVM "UAV_Master.sqf"; There's a check in the script to loop until _vehicle is valid as well. Only caught it on the dedicated server with -showScriptErrors. Perhaps my syntax was wrong, idk, but I'll test what you've posted tomorrow if time permits. Share this post Link to post Share on other sites
king_richard 10 Posted March 11, 2015 Updated first post with the current version. Once again thanks JShock, the groupID is now working on a dedicated server! Calling this v0.8 but don't be alarmed, it works, just missing some polish is all. Share this post Link to post Share on other sites