Jump to content
Sign in to follow this  
Orion987

Spawning Working Mortars

Recommended Posts

Hello. I am trying to spawn a single mortar and fire it at a position. I am using the following code...

_artyMan = _grp createUnit [(_allMen select 0), _spawnpos, [], 10, "FORM"];	
_artyVehicle = (_allUnits select 0) createVehicle (_spawnpos);
[_artyVehicle] call BIS_ARTY_F_initVehicle;
_artyMan moveInGunner _artyVehicle;

_heTemplate = ["IMMEDIATE", "HE", ((round (random 1))+0), ((round (random 2))+6)]; 

BIS_ARTY_Logic_INS = _grp createUnit ["BIS_ARTY_Logic", [0, 0, 0], [], 0, ""];
BIS_ARTY_Logic_INS synchronizeObjectsAdd [leader _grp];

To be clear, this is not the entire script. _grp is already defined. I am assuming my logic is wrong on what I need to synchronize? Thanks.


[bIS_ARTY_Logic_INS, ((round (random 150))+100)] call BIS_ARTY_F_SetDispersion;  
[bIS_ARTY_Logic_INS, getPos westBase, _heTemplate] call BIS_ARTY_F_ExecuteTemplateMission; 

I apologize if my code is unfriendly, I am kinda sloppy... anyway,

I am not getting errors, the man is spawning and moving into the vehicle (_allUnits is an array with a mortar and _allMen is an array with a soldier). westBase is about 2000 meters away, within the mortars range (100 to 3700 meters).

The man does nothing though, he does not fire any rounds. If I use the same fire template on an artillery battery I set up on the map, it works fine, but my spawned units will not work. Does anyone have any ideas? Thanks! Please tell me if I left something important out.

Edited by Orion987

Share this post


Link to post
Share on other sites

I am stumped on this. synchronizeObjectsAdd does not seem to work properly with artillery once the mission has started. As an example, I put a D-30 on the map and sync'd it with an artillery logic (on the map), then I put another D-30 on the map and sync'd it from the init script, and that worked fine. But... if I put a "sleep 1" before the synchronizeObjectsAdd command, it will not add the 2nd D-30 to the battery. So I think that correlates with the spawned units not syncing.

I found this old post, maybe it'll help, maybe not.

http://forums.bistudio.com/showthread.php?t=87724

Share this post


Link to post
Share on other sites

you need to spawn art module same time as arty and imediatly sync using synchronizeObjectsAdd, else it wont work.

you can have several art modules in same mission.

Share this post


Link to post
Share on other sites
you need to spawn art module same time as arty and imediatly sync using synchronizeObjectsAdd, else it wont work.

you can have several art modules in same mission.

I have the artillery module created a little bit after the actual artillery is created. I will try creating them right after each other and see if that works. Thanks.

Share this post


Link to post
Share on other sites
you need to spawn art module same time as arty and imediatly sync using synchronizeObjectsAdd, else it wont work.

you can have several art modules in same mission.

When you say arty, are you talking about the actual artillery vehicle or the gunner/leader of the artillery battery?

Share this post


Link to post
Share on other sites
_grp = createGroup EAST;

_center = createCenter sideLogic;

_group = createGroup _center;

_artyMan = _grp createUnit [(_allMen select 0), _spawnpos, [], 10, "FORM"];

_artyVehicle = (_allUnits select 0) createVehicle (_spawnpos);

[_artyVehicle] call BIS_ARTY_F_initVehicle;

_mortarLogic = _group createUnit ["BIS_ARTY_Logic", getPos player, [], 0, "NONE"];

_mortarLogic synchronizeObjectsAdd [_artyVehicle];

_artyMan moveInGunner _artyVehicle;

I have the code looking like this now, still the same thing, the man will not fire at anything. The same fire template works on artillery I make in the editor. If I use synchronizedObjects on _mortarLogic, it does return the _artyVehicle, so I guess they're synching. Anyone have any more ideas?

If anyone wants I can post the entire script but it doesn't really add anything. Let me know if anyone thinks it'll help though.

Share this post


Link to post
Share on other sites

If there's anymore information I should give let me know. Tell me if my problem is not clear as well. I am still unable to get it working.

Share this post


Link to post
Share on other sites

Try this way,

The syncing is only important with reference to the artillery module you create, as the code within the artillery module only looks for synced units at the start of it's execution. So create anything you want to sync with it prior to creating the module, then ensure you syncronise everything immediately after creating the artillery module.

You also need to ensure you have waited until the module has initialised fully before sending a fire mission. I have placed a waituntil where the function inside returns true when the artillery is available.

Try this, spawn only used for quick testing, _this refers to the player character I placed this code into for testing. Replace with your variables as required. Remove the spawn aspects, it is just used to execute the code without having to create any script files. Left in for quick testing of the code.

To test this as is, place an opfor player unit in editor, place the code in it's init line. Place another unit called westbase and preview. Sleep 20 at the start is to show nothing is occurring at mission start.

sh = this spawn
{
private ["_art1"];
_spawnpos = getpos _this;

sleep 20;

_artyVehicle = "2b14_82mm" createVehicle (_spawnpos);

_HQ = createCenter EAST;				
_grp = createGroup EAST;	
_artyMan = _grp createUnit [typeof _this, _spawnpos, [], 10, "FORM"];
_artyMan moveInGunner _artyVehicle;

sleep 0.1;

_LogicCenter = createCenter sideLogic;
_LogicGroup = createGroup _LogicCenter;
_art1 = _grp createUnit ["BIS_ARTY_Logic", [0, 0, 0], [], 0, ""];
_art1 synchronizeObjectsAdd [leader _grp];
[leader _grp] call BIS_ARTY_F_initVehicle;

_heTemplate = ["IMMEDIATE", "HE", ((round (random 1))+0), ((round (random 2))+6)]; 

waituntil {[_art1,_heTemplate] CALL BIS_ARTY_F_Available};

[_art1, ((round (random 150))+100)] call BIS_ARTY_F_SetDispersion;  
[_art1, getPosASL westBase, _heTemplate] call BIS_ARTY_F_ExecuteTemplateMission;

};

Hope this helps

Blake

Share this post


Link to post
Share on other sites

Two things to do/check:

1. Check the status. If the battery won't fire, there is a status code to check telling you why it cannot fire. For example:

_group = grpAlpha;
_batteryScope = [_group] call BIS_ARTY_F_GetScope;

if (isNull _batteryScope) then 
{ player globalchat "NO battery available"; }
else
{
if (!([_batteryScope, _mission] call BIS_ARTY_F_StillViable)) then 
{ player globalchat "Battery NOT VIABLE"; }
else
{
	if (!([_batteryScope, _target, _ammo] call BIS_ARTY_F_PosInRange)) then { player globalchat "TARGET NOT IN RANGE"; };		
};
};

2. is whether the artillery gun is the leader in the group? Might make a difference when the BI module attempts to figure out the battery scope.

Share this post


Link to post
Share on other sites

I use this for -=BattleZone=-

- Its simple and only works fron 180 to 480 meters-

Maybe someone can improve on it

_building = _itemclass createvehicle _buildspot;
_itemcrewclass createUnit [_buildspotmen, _group,"_crewbuilding = this", Aiskill];
_crewbuilding moveingunner _building;

_firecode = { 
_crewbuilding = _this select 0;
_veh = (vehicle _crewbuilding);
_ss = _veh weaponsTurret [0];
_wep = (_ss select 0);
_side = side _crewbuilding;
_enemy = [];
_sides = [];
_fired = 0;


if (_side == west) then {_sides = ["EAST","GUER"]};
if (_side == east) then {_sides = ["WEST","GUER"]};
if (_side == resistance) then {_sides = ["WEST","EAST"]};


while {(alive _crewbuilding)} do 
{

waituntil {(!isnull (assignedTarget _crewbuilding))}; 

if (count _enemy == 0) then {
{if (((_x select 0) distance _crewbuilding > 180) && !((_x select 1) iskindof "AIR") && !(isnull (_x select 4)) && (str(_x select 2) in _sides)) then {_enemy = _enemy + [(_x select 4)]}} foreach (_crewbuilding nearTargets 480);
};

_mytarget = if (count _enemy > 0) then {(_enemy select 0)}else{(assignedTarget _crewbuilding)};

	 if ((_mytarget distance _crewbuilding < 480) && (alive _mytarget) &&  (_mytarget distance _crewbuilding > 180)) then 
	{
	_tarpos = position _mytarget;
	_range = (1350 - (_mytarget distance _crewbuilding));
	_tarpos set[2,_range];
	_veh doWatch _tarpos;
	_fire = 0;
	_timeout = (time + 10);

			while {((_mytarget distance _crewbuilding < 480) && (alive _mytarget) &&  (_mytarget distance _crewbuilding > 180))} do 
			{
			_steady = 0;
			while {(_steady == 0)} do 
			{
			_tarpos = position _mytarget;
			_range = (1350 - (_mytarget distance _crewbuilding));
			_tarpos set[2,_range];
			_veh doWatch _tarpos;
			_state = _veh weaponDirection _wep; 
			_gx = _state select 0;
			_gy = _state select 1; 
			_gz = _state select 2; 
			sleep 0.2;
			_state = _veh weaponDirection _wep;
			if (((_gx == _state select 0) && (_gy == _state select 1) && (_gz == _state select 2)) or (time > _timeout)) then {_fire = 1;_steady = 1}; 
			};

				if ((_fire == 1) && (alive _mytarget)) then 
				{	
				_sidearray = (nearestObjects [_tarpos, ["Building","Camp_base","AllVehicles"],30]);
				_myside = [];
				{if (side _x == side _crewbuilding) then {_myside = _myside + [_x]}} foreach _sidearray;

					if ((alive _mytarget) && (count _myside == 0)) then 
					{
					_veh fire _wep;
					_fired = _fired + 1;
					if (_fired > 5) then {_fire = 0;_enemy = _enemy - [_mytarget];_mytarget = if (count _enemy > 0) then {(_enemy select 0)}else{(assignedTarget _crewbuilding)};_fired = 0};
					sleep 5;
					};
				};
			};
	}else{_enemy = _enemy - [_mytarget]};
sleep 5;
};
};

if (_building iskindof "StaticMortar") then {[_crewbuilding] spawn _firecode};

Edited by Zonekiller

Share this post


Link to post
Share on other sites
Try this way,

The syncing is only important with reference to the artillery module you create, as the code within the artillery module only looks for synced units at the start of it's execution. So create anything you want to sync with it prior to creating the module, then ensure you syncronise everything immediately after creating the artillery module.

You also need to ensure you have waited until the module has initialised fully before sending a fire mission. I have placed a waituntil where the function inside returns true when the artillery is available.

Try this, spawn only used for quick testing, _this refers to the player character I placed this code into for testing. Replace with your variables as required. Remove the spawn aspects, it is just used to execute the code without having to create any script files. Left in for quick testing of the code.

To test this as is, place an opfor player unit in editor, place the code in it's init line. Place another unit called westbase and preview. Sleep 20 at the start is to show nothing is occurring at mission start.

sh = this spawn
{
private ["_art1"];
_spawnpos = getpos _this;

sleep 20;

_artyVehicle = "2b14_82mm" createVehicle (_spawnpos);

_HQ = createCenter EAST;				
_grp = createGroup EAST;	
_artyMan = _grp createUnit [typeof _this, _spawnpos, [], 10, "FORM"];
_artyMan moveInGunner _artyVehicle;

sleep 0.1;

_LogicCenter = createCenter sideLogic;
_LogicGroup = createGroup _LogicCenter;
_art1 = _grp createUnit ["BIS_ARTY_Logic", [0, 0, 0], [], 0, ""];
_art1 synchronizeObjectsAdd [leader _grp];
[leader _grp] call BIS_ARTY_F_initVehicle;

_heTemplate = ["IMMEDIATE", "HE", ((round (random 1))+0), ((round (random 2))+6)]; 

waituntil {[_art1,_heTemplate] CALL BIS_ARTY_F_Available};

[_art1, ((round (random 150))+100)] call BIS_ARTY_F_SetDispersion;  
[_art1, getPosASL westBase, _heTemplate] call BIS_ARTY_F_ExecuteTemplateMission;

};

Hope this helps

Blake

It helps very much! Thank you very much. I'm not sure if it wasn't working because I wasn't using the right side (logic or east) or if it wasn't waiting for it to be fully initialized but it is working now. Thanks too everyone that responded.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×