Jump to content
Sign in to follow this  
carlostex

Editing BIS_fnc_SpawnEnemy made it not work in Dedicated

Recommended Posts

I edited BIS_fnv_SpawnEnemy to my needs:

scriptName "TEX_fnc_spawnEnemy.sqf";
/*
Author: Karel Moricky edited by CarlosTex

Description:
Spawns enemies around players

Parameter(s):
_this select 0: OBJECT - player
_this select 1: OBJECT - refence object (enemies will be spawned on opposite direction)
_this select 2: SIDE - side of enemies
       _this select 3: trigger name
       _this select 4: variable with boolean value for loop 
_this select 5: ARRAY - list of enemy classes (this indicated as optional but in reality was mandatory)
       _this select 6: (Optional) NUMBER - Amount of spawned units at a time
       _this select 7: (Optional) NUMBER - Limit of spawned units. Loop exits after reached
_this select 8: (Optional): NUMBER - delay between spawning
_this select 9: (Optional): CODE - code executed on every soldier. Unit is passed as _this

Returns:
ARRAY - list of all spawned crows
*/

if (!isServer) exitWith {};

_player = _this select 0;
_target = _this select 1;
_side = _this select 2;
_triggerName = _this select 3;
_trig = _this select 4;
_classList = _this select 5;
_maxCount = if (count _this > 6) then {_this select 6} else {10};
_limitWave = if (count _this > 7) then {_this select 7} else {-1};
_delay = if (count _this > 8) then {_this select 8} else {30};
_code = if (count _this > 9) then {_this select 9} else {{}};

if (typename _target == typename objnull) then {_target = [_target,_target];};

//_chance = [false,true] call BIS_fnc_selectrandom;

_otherPlayer = (_players - [_player]) select 0;
_grp = creategroup _side;
_wp = _grp addwaypoint [getPos _triggerName,10];
_wp setwaypointstatements ["false",""];
_wp setwaypointtype "guard";
_player setvariable ["BIS_spawnedEnemies",[]];

while {_trig} do {
waituntil {sleep 1; isplayer _player};
if (count (_player getvariable "BIS_spawnedEnemies") >= _limitWave) exitWith {hint "No more spawning"};
waituntil {sleep 1; {alive _x} count (_player getvariable "BIS_spawnedEnemies") < _maxCount};

_class = _classList call BIS_fnc_selectrandom;
_dirToTarget = if (isMultiplayer) then {
	_targetTemp = _target select 1;
	([_player,_targetTemp] call bis_fnc_dirTo)
} else {
	_targetTemp = _target select isMultiplayer;
	([_player,_targetTemp] call bis_fnc_dirTo) + 180
};
_pos = [position _player, 180 + random 40, _dirToTarget + 90 + random 180] call BIS_fnc_relPos;
_unit = _grp createunit [_class,_pos,[],1,""];
[nil,nil,"per",rHINT,"loop is running"] call RE;
_unit setskill (0.7 + random 0.3);
_unit allowfleeing (random 0.5);
_unit setvehicleammo (0.5 + random 0.5);
[_player,"BIS_spawnedEnemies",[_unit]] call bis_fnc_variablespaceadd;
if (!_trig) exitWith {};
//_wp setwaypointposition [position _player,0];

_unit call _code;

sleep _delay;
};

I don't see any reason why wouldn't this work on Dedicated. BIS_fnc_SpawnEnemy certainly does.

I'm calling it via execVM.

I know i'm using !isserver there but that is because i think this script only needs to runon server. It creates AI and it is always server side so why would i create in my machine as well? So i'm missing something and/or doing something wrong.

Any help tips and hints would be appreciated!

Edited by CarlosTex

Share this post


Link to post
Share on other sites

How do you call it? Where? And "player" it's always local...

If you call it from the client you can't run it on the server...

Give us more details...

Share this post


Link to post
Share on other sites

I call it from a trigger:

Name: trig1

Activation: BLUFOR,Present,Repeatedly

Condition: this

onAct:act1 = true; hint "inside trigger"; handle1 = [player, enemy1, EAST, trig1, act1, ["Ins_Soldier_1","Ins_Soldier_2","Ins_Soldier_GL","Ins_Soldier_CO","Ins_Commander","Ins_Soldier_AT"],10,10,5] execVM "TEX_fnc_SpawnEnemy.sqf"

onDeact: hint "outside trigger"; act1 = false; 

that's it

BTW: enemy1 is a opfor unit that i have to place on map to serve as reference

Share this post


Link to post
Share on other sites

@carlostex

Looks like a nice neat spawn script. I am going to try it out. Do you know if you put ,say 20 different units in the unit array and then use the paramater to limit the number of units per group to 10, will it pull the first 10 in the array or will it select 10 randomly from the array?

I will test the script, but thought you might know. I would like it to pull them randomly.

Nomadd

Share this post


Link to post
Share on other sites
@carlostex

Looks like a nice neat spawn script. I am going to try it out. Do you know if you put ,say 20 different units in the unit array and then use the paramater to limit the number of units per group to 10, will it pull the first 10 in the array or will it select 10 randomly from the array?

I will test the script, but thought you might know. I would like it to pull them randomly.

Nomadd

It selects randomly from the array. you might want to do this:

_wp setwaypointposition [position _triggerName,20];

just replace the commented line in the script by this one. Instead of them going to the player directly they search within the defined trigger radius, which feels more natural.

Anyway it does not work on a dedicated. That's why i need help.

Edited by CarlosTex

Share this post


Link to post
Share on other sites

I've not time to test it but player's command is local and can't be execute on a dedi.

Where's "_players" defined?

How about a check with nearestObjects instead player?

Share this post


Link to post
Share on other sites
I've not time to test it but player's command is local and can't be execute on a dedi.

Where's "_players" defined?

How about a check with nearestObjects instead player?

That's not the problem because BIS_fnc_SpawnEnemy uses the same player code and it works perfectly.

I have a feeling that it's might be i'm execVM, and BIS_fncSpawnEnemy is spawn command.

---------- Post added at 22:10 ---------- Previous post was at 21:56 ----------

Looks like i'm screwed.... I can't extract the modules_pmc because probably the PBO file is now different.

---------- Post added at 23:09 ---------- Previous post was at 22:10 ----------

I might be also wrong about it working for BIS_fnc_SpawnEnemy, it is probably creating units for every client.

I don't understand, there's gotta be a way to create the units on the dedicated server only.

Damn it this is frustrating. :mad:

Share this post


Link to post
Share on other sites

I have thought that maybe _pos variable is giving a problem because like Galliusto said player is == objnull in a dedicated.

I will test and report back.

Share this post


Link to post
Share on other sites

just place a rpt print of the passed array to check values.

diag_log "start_test";
diag_log format["%1",_this];
diag_log "end_test";

now just search through your .rpt file on dedi for start_test and youll find the results.

Share this post


Link to post
Share on other sites

Thanks Demonized, i've fixed the script took me 5 min actually. There's no doubt that a good night sleep makes a total difference when trying to fix scripts. Yesterday when i made my last post i was already 24 hours staright without any sleep. :)

Galliusto was actually right the problem was always on the fact that player == objNull on Dedicated. So what i did was adapt the script, got rid of the unnecessary code, changed the player request for a normal object and most important got rid of an waitUntil that had the condition isplayer _player so it was quite obvious that the script wouldn't go past that moment.

So here's the script:

scriptName "fn_spawnEnemy.sqf";
/*
Author: Karel Moricky edited by CarlosTex

Description:
Spawns enemies around players

Parameter(s):
_this select 0: OBJECT - use a game logic
_this select 1: SIDE - (side of enemies)
_this select 2: NUMBER - distance from the trigger for the units to spawn
       _this select 3: trigger name
       _this select 4: variable with boolean value for loop 
_this select 5: ARRAY - list of enemy classes (this was indicated as optional but in reality was mandatory)
       _this select 6: (Optional) NUMBER - Amount of spawned units at a time
       _this select 7: (Optional) NUMBER - Limit of spawned units. Loop exits after reached
_this select 8: (Optional): NUMBER - delay between spawning
_this select 9: (Optional): CODE - code executed on every soldier. Unit is passed as _this

Returns:
ARRAY - list of all spawned crows
*/

if (!isServer) exitwith {};

_obj = _this select 0;
_side = _this select 1;
_distanceToTrigger = _this select 2;
_triggerName = _this select 3;
_trig = _this select 4;
_classList = _this select 5;
_maxCount = if (count _this > 6) then {_this select 6} else {10};
_limitWave = if (count _this > 7) then {_this select 7} else {-1};
_delay = if (count _this > 8) then {_this select 8} else {30};
_code = if (count _this > 9) then {_this select 9} else {{}};

_chance = [false,true] call BIS_fnc_selectrandom;

_grp = creategroup _side;
_wp = _grp addwaypoint [getPos _triggerName,10];
_wp setwaypointstatements ["false",""];
_wp setwaypointtype "guard";
_obj setvariable ["BIS_spawnedEnemies",[]];

while {_trig && _chance} do {
//waituntil {sleep 1; isplayer _player};
if (count (_obj getvariable "BIS_spawnedEnemies") >= _limitWave) exitWith {hint "No more spawning"};
waituntil {sleep 1; {alive _x} count (_obj getvariable "BIS_spawnedEnemies") < _maxCount};

_class = _classList call BIS_fnc_selectrandom;

_pos = [getpos _triggerName, _distanceToTrigger,  random 360] call BIS_fnc_relPos;
_unit = _grp createunit [_class,_pos,[],1,""];
_unit setskill (0.7 + random 0.3);
_unit allowfleeing (random 0.5);
_unit setvehicleammo (0.5 + random 0.5);
[_obj,"BIS_spawnedEnemies",[_unit]] call bis_fnc_variablespaceadd;
if (!_trig) exitWith {};
_wp setwaypointposition [getpos _triggerName,20];

_unit call _code;

sleep _delay;
};

BTW there's some code i added that will randomize chance of units not being created on the variable _chance

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  

×