PCanas 5 Posted August 20, 2022 Hello there! I'm making a shooting range and I have some moving soldiers (FIA Rifleman) as targets. They're setup individually (not in groups), and their behaviour is careless and to never fire, so they don't react in any way when being shot at. Now, the point is, obviously, to kill them. But it wouldn't be much fun if you could it only once. So I need to respawn them... That part I've managed to do (I think). What I can't do, is respawning each one of them with their respective waypoints and their behaviour. The idea is to have an object from which I can call the script. So... How do I do it? (btw, this is kinda "urgent"...) Thanks for the help! :) Share this post Link to post Share on other sites
Janez 530 Posted August 20, 2022 You could use Jebus: Share this post Link to post Share on other sites
PCanas 5 Posted August 20, 2022 Looks interesting... I'll take a look. Thanks! 🙂 Share this post Link to post Share on other sites
Larrow 2820 Posted August 22, 2022 Spoiler TAG_fnc_addUnitRespawn = { params[ "_unit" ]; _unit addEventHandler[ "Killed", { params[ "_killed" ]; _newUnit = group _killed createUnit[ typeOf _killed, waypointPosition ( waypoints group _killed select 0 ), [], 0, "NONE" ]; _newUnit setUnitLoadout getUnitLoadout _killed; _newUnit setBehaviour behaviour _killed; group _newUnit setCurrentWaypoint ( waypoints group _newUnit select 1 ); deleteVehicle _killed; _newUnit call TAG_fnc_addUnitRespawn; }]; }; this call TAG_fnc_addUnitRespawn; When the unit is killed, create a new one of the same type at the killed's original starting position (waypoint 0), copy the killed units loadout to the new unit, copy the behaviour of the killed unit (combat mode is related to the group and as the new unit is being spawned in the same group this will carry over), reset current waypoint to the first, delete the killed unit and add the same event to the new unit. The code can just be placed in the units init, although if used on multiple units the function should probably be placed somewhere else like initServer.sqf ( preferably it should be setup using CfgFunctions ). Although this immediately respawns them it should give you an idea of what is needed to be saved from the killed unit for whenever you want to respawn them. On 8/20/2022 at 12:21 PM, PCanas said: They're setup individually (not in groups), Even individual units have a group, you cannot have a unit without one. 1 Share this post Link to post Share on other sites
PCanas 5 Posted August 27, 2022 On 8/22/2022 at 3:26 AM, Larrow said: Hide contents TAG_fnc_addUnitRespawn = { params[ "_unit" ]; _unit addEventHandler[ "Killed", { params[ "_killed" ]; _newUnit = group _killed createUnit[ typeOf _killed, waypointPosition ( waypoints group _killed select 0 ), [], 0, "NONE" ]; _newUnit setUnitLoadout getUnitLoadout _killed; _newUnit setBehaviour behaviour _killed; group _newUnit setCurrentWaypoint ( waypoints group _newUnit select 1 ); deleteVehicle _killed; _newUnit call TAG_fnc_addUnitRespawn; }]; }; this call TAG_fnc_addUnitRespawn; When the unit is killed, create a new one of the same type at the killed's original starting position (waypoint 0), copy the killed units loadout to the new unit, copy the behaviour of the killed unit (combat mode is related to the group and as the new unit is being spawned in the same group this will carry over), reset current waypoint to the first, delete the killed unit and add the same event to the new unit. The code can just be placed in the units init, although if used on multiple units the function should probably be placed somewhere else like initServer.sqf ( preferably it should be setup using CfgFunctions ). Although this immediately respawns them it should give you an idea of what is needed to be saved from the killed unit for whenever you want to respawn them. Even individual units have a group, you cannot have a unit without one. And how exactly should I place that code on the initServer.sqf and use CfgFunctions? That's all chinese for me 😅 Share this post Link to post Share on other sites
Larrow 2820 Posted August 27, 2022 4 hours ago, PCanas said: And how exactly should I place that code on the initServer.sqf and use CfgFunctions? That's why I provided you with a link explaining what CfgFunctions is and how to set it up. Spoiler //In Unit init this call PCAN_fnc_addUnitRespawn; //Description.ext class CfgFunctions { class PCAN_UnitRespawn { tag = "PCAN"; class Respawn { file = "PCAN\functions"; class addUnitRespawn {}; }; }; }; //PCAN\functions\fn_addUnitRespawn.sqf if !( isServer ) exitWith {}; params[ "_unit" ]; _unit addEventHandler[ "Killed", { params[ "_killed" ]; _newUnit = group _killed createUnit[ typeOf _killed, waypointPosition ( waypoints group _killed select 0 ), [], 0, "NONE" ]; _newUnit setUnitLoadout getUnitLoadout _killed; _newUnit setBehaviour behaviour _killed; group _newUnit setCurrentWaypoint ( waypoints group _newUnit select 1 ); deleteVehicle _killed; _newUnit call PCAN_fnc_addUnitRespawn; }]; Share this post Link to post Share on other sites
PCanas 5 Posted August 27, 2022 Oh, I didn't notice it was a link, sorry. Share this post Link to post Share on other sites
PCanas 5 Posted August 27, 2022 Ok, so it works perfectly, thanks 😉 But... is there a way to a delay on it? Like, the unit respawns only after x seconds... Share this post Link to post Share on other sites
imlay 11 Posted September 12, 2022 Super easy, man. BIS_fnc_spawnGroup function is able to spawn a new group, with the number and type of units inside designated by you manually. This function will return a reference to the new group, assign this reference to a variable(to get group name). Then use a while loop (how to terminate this loop, whether by specifying conditions, or using break command, is up to you) to do the following check. Give a if statement in the while loop. If the number goes 0: { use that function to spawn a new group with exactly the same unit type. Then assign the reference of this respawned group to that variable. } Share this post Link to post Share on other sites