Jump to content
Spriterfight

HELP With sleep inside function

Recommended Posts

Here is my code

fnc_spawn =

{
  _selectableunits = ["CUP_B_HIL_GL",
  "CUP_B_HIL_MMG",
  "rhsgref_hidf_marksman",
  "rhsgref_hidf_sniper",
  "rhsgref_hidf_teamleader",
  "rhsgref_ins_g_machinegunner",
  "rhsgref_ins_g_medic",
  "rhsgref_ins_g_rifleman_akm",
  "rhsgref_ins_g_rifleman",
  "rhsgref_ins_g_grenadier",
  "rhsgref_ins_g_rifleman_RPG26",
  "rhsgref_ins_g_rifleman",
  "I_L_Hunter_F",
  "I_L_Looter_SG_F",
  "I_L_Hunter_F",
  "CUP_I_PMC_Sniper",
  "CUP_I_PMC_Soldier_MG_PKM",
  "CUP_I_PMC_Soldier_GL_M16A2",
  "CUP_I_PMC_Pilot",
  "CUP_I_PMC_Sniper_KSVK",
  "CUP_I_PMC_Sniper",
  "CUP_I_PMC_Soldier_AT"];
_c = 5;

_group = creategroup east;
_pos = (trg1 getRelPos [(random ((triggerArea trg1) select 0)), random(360)]);
for "_i" from 1 to _c do

{
  _unit1 = _selectableunits call BIS_fnc_selectRandom;
	_unit = _unit1 createUnit [_pos, _group];
sleep 1; // it gives me generic erro in expression
  _unit addEventHandler ["Killed", {

       _corpse = _unit;
      _corpse spawn BIS_fnc_DeleteCorpseofSoldier;

    }];
};

};

Sleep command gives me generic error in expresion.If i remove it it dosent give me error.

Share this post


Link to post
Share on other sites
3 minutes ago, Spriterfight said:

Here is my code

Sleep command gives me generic error in expresion.If i remove it it dosent give me error.

 

How are you calling the code?

 

you need to use spawn to enable pausing/sleeping

 

like so:

 

[] spawn fnc_spawn;

 

  • Like 2

Share this post


Link to post
Share on other sites
9 minutes ago, gc8 said:

 

How are you calling the code?

 

you need to use spawn to enable pausing/sleeping

 

like so:

 


[] spawn fnc_spawn;

 

Now it says undefined variable in _unit also i dont use spawn because it messes with my character, it teleports somwhere on the edge of the map

 

Share this post


Link to post
Share on other sites
6 minutes ago, Spriterfight said:

Now it says undefined variable in _unit

 

 

That's because _unit is not defined in "Killed" EH

 

Fix using params:

 

  _unit addEventHandler ["Killed", {
params ["_unit"];

       _corpse = _unit;
      _corpse spawn BIS_fnc_DeleteCorpseofSoldier;

    }];

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

@Spriterfight,

Check this out,

Spoiler

you_UnitSelect = ["CUP_B_HIL_GL","CUP_B_HIL_MMG","rhsgref_hidf_marksman","rhsgref_hidf_sniper","rhsgref_hidf_teamleader","rhsgref_ins_g_machinegunner","rhsgref_ins_g_medic","rhsgref_ins_g_rifleman_akm","rhsgref_ins_g_rifleman","rhsgref_ins_g_grenadier","rhsgref_ins_g_rifleman_RPG26","rhsgref_ins_g_rifleman","I_L_Hunter_F","I_L_Looter_SG_F","I_L_Hunter_F","CUP_I_PMC_Sniper","CUP_I_PMC_Soldier_MG_PKM","CUP_I_PMC_Soldier_GL_M16A2","CUP_I_PMC_Pilot","CUP_I_PMC_Sniper_KSVK","CUP_I_PMC_Sniper","CUP_I_PMC_Soldier_AT"];

Define your array in init.sqf to make it available to other scripts/functions.


you_fnc_spawn=
{ params [["_loc", objNull], ["_num", 1], ["_arr", you_unitSelect]];

_pos = (_loc getRelPos [(random ((triggerArea _loc) select 0)), random(360)]);
_type = selectRandom _arr;

private	_grp =[ _pos, EAST, _type, [],[],[],[],[_num, 0],0] call BIS_fnc_spawnGroup;
	{
 	 _x addEventHandler ["Killed", {
		params ["_unit", "_killer", "_instigator", "_useEffects"];
		_unit spawn BIS_fnc_DeleteCorpseofSoldier;
		}];
	} forEach units _grp;

};

Use a configurable, repeatable function to accomplish your script (can paste along with the array above).


[trg1, 5, you_unitSelect] call you_fnc_spawn;

Call the function any time you need to with the parameters defined and no spawn/sleep is even required!


Have fun!

  • Confused 1

Share this post


Link to post
Share on other sites
55 minutes ago, wogz187 said:

@Spriterfight,

Check this out,

  Hide contents


you_UnitSelect = ["CUP_B_HIL_GL","CUP_B_HIL_MMG","rhsgref_hidf_marksman","rhsgref_hidf_sniper","rhsgref_hidf_teamleader","rhsgref_ins_g_machinegunner","rhsgref_ins_g_medic","rhsgref_ins_g_rifleman_akm","rhsgref_ins_g_rifleman","rhsgref_ins_g_grenadier","rhsgref_ins_g_rifleman_RPG26","rhsgref_ins_g_rifleman","I_L_Hunter_F","I_L_Looter_SG_F","I_L_Hunter_F","CUP_I_PMC_Sniper","CUP_I_PMC_Soldier_MG_PKM","CUP_I_PMC_Soldier_GL_M16A2","CUP_I_PMC_Pilot","CUP_I_PMC_Sniper_KSVK","CUP_I_PMC_Sniper","CUP_I_PMC_Soldier_AT"];

 Define your array in init.sqf to make it available to other scripts/functions.



you_fnc_spawn=
{ params [["_loc", objNull], ["_num", 1], ["_arr"], you_unitSelect];

_pos = (_loc getRelPos [(random ((triggerArea _loc) select 0)), random(360)]);
_type = selectRandom _arr;

private	_grp =[ _pos, EAST, _type, [],[],[],[],[_num, 0],0] call BIS_fnc_spawnGroup;
	{
 	 _x addEventHandler ["Killed", {
		params ["_unit", "_killer", "_instigator", "_useEffects"];
		_this select 0 spawn BIS_fnc_DeleteCorpseofSoldier;
		}];
	} forEach units _grp;

};

Use a configurable, repeatable function to accomplish your script (can paste along with the array above).



[trg1, 5, you_unitSelect] call you_fnc_unitSelect;

Call the function any time you need to with the parameters defined and no spawn/sleep is even required!


Have fun!

invaild number in expression

 

Share this post


Link to post
Share on other sites
2 minutes ago, Spriterfight said:

invaild number in expression

 

i made another script so it works but yours gives me error in line 36 between the function and the arrays

 

Share this post


Link to post
Share on other sites

@Spriterfight,

All fixed,

Spoiler

you_UnitSelect = ["CUP_B_HIL_GL","CUP_B_HIL_MMG","rhsgref_hidf_marksman","rhsgref_hidf_sniper","rhsgref_hidf_teamleader","rhsgref_ins_g_machinegunner","rhsgref_ins_g_medic","rhsgref_ins_g_rifleman_akm","rhsgref_ins_g_rifleman","rhsgref_ins_g_grenadier","rhsgref_ins_g_rifleman_RPG26","rhsgref_ins_g_rifleman","I_L_Hunter_F","I_L_Looter_SG_F","I_L_Hunter_F","CUP_I_PMC_Sniper","CUP_I_PMC_Soldier_MG_PKM","CUP_I_PMC_Soldier_GL_M16A2","CUP_I_PMC_Pilot","CUP_I_PMC_Sniper_KSVK","CUP_I_PMC_Sniper","CUP_I_PMC_Soldier_AT"];

you_fnc_spawn= 
{ params [["_loc", objNull], ["_side", EAST], ["_num", 1], ["_type", ["I_G_soldier_lite_f"]], ["_area", 100]];
private	_pos = [_loc, _area /2, _area, 3, 0, 20, 0] call BIS_fnc_findSafePos;
private _grp =[_pos, _side, _type, [],[],[],[],[_num, 0],0] call BIS_fnc_spawnGroup;
	{ 
	_x addEventHandler ["Killed", {
		params ["_unit", "_killer", "_instigator", "_useEffects"];
		[_unit] spawn {sleep 1; deleteVehicle (_this select 0);};
		}];
	} forEach units _grp;
};

[trg1, EAST, 5, you_unitSelect, 100] call you_fnc_spawn;

Watch out for the dreaded invisible character bug!

The "sleep" is back!

Have fun!

  • Like 1

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

×