Jump to content

Recommended Posts

Posted (edited)

Hey all,

 

I am (still :D) trying to create a medical training framework for a unit playing a persistent mission. All is going (quite) good so far and now I am stuck with an issue. The unit uses players to practice medical and some of them die in the process. They have a respawn time (I think is somewhere around to 1 minute, but this is irrelevant) to discourage ramboing.

 

So, the goal is to find a way to respawn instantly (override the normal respawn time) those who didn't make it through the medical practice of their fellow aspirant medics and then move them back to the medical training facility where they died.

 

I believe the second part to be quite easy. Probably with just a setPos (although this may not be the case if I don't have access to the unit object). So, at the moment I am stuck as to how I can instantly repsawn units (but not all units, just specific ones). I have looked at the BI's respawn functions, but there are no examples and the wiki/docs seem to be completely deserted. I did try to use BIS_fnc_respawnInstant but seems that it does NOT do what I want it to do. After quite some time searching I was unable to find something (or was unable to recognize it) that would help me accomplish my task.

 

Any insight, ideas or suggestions would be most welcome.

 

Thanks in advance,

 

Achilles.

Edited by ZaellixA
Change the title to resolved

Share this post


Link to post
Share on other sites
7 minutes ago, pierremgi said:

setPlayerRespawnTime 0

Hey pierremgi, thanks for the quick response.

 

Correct me if I am wrong but, I believe that this command changes the respawn time for all the players and not for the specific one called from. This means that every time I want to respawn someone possibly more people will benefit from it. This is not intended behavior.

 

I do understand that this may be handled with a bit more extra effort (set the respawn time back to the "default" for the mission after the player is respawn), but at the moment I am looking for something more generic.

 

I will keep that in mind though, in case I won't manage to find something else.

 

Thanks again,

 

Achilles.

Share this post


Link to post
Share on other sites

Hhhhmmmm..., damn me for not noticing earlier!!!

 

Thanks for that. So, this means that I do have a solution at hand to set the counter to zero.

 

I could definitely check for the timer value at onPlayerRespawn.sqf and if it is not the "default" change it back to the default, but as far more experienced, do you have any other suggestion which could render the script a bit more portable (so it won't depend on other scripts to undo what it did)?

 

A great thanks once more. Really appreciate all the help.

 

Best,

 

Achilles.

Share this post


Link to post
Share on other sites

Hhhmmm, if killzone_kid is right, then probably this won't be to any use, but I will give it a try nevertheless.

 

Thank you both.

Share this post


Link to post
Share on other sites
Posted (edited)

Well, finally I found a solution to this.

 

I am not sure it is what I really wanted, but I will look more for one that suites my needs better.

 

For the sake of completeness I will quote solution so someone else may benefit from it in the future.

 

I will place the whole script here which is supposed to be run via an addAction. I do have some comments at the beginning and throughout the script (I tend to be over-commenting code, apologies if this creates a cluttered script :|)

 

So the script is:

/* ----------------------------------------------------------------------------------------------------
 * Script to apply wounds to a player.
 * Applies random wounds to player and sets the respawn timer to zero. If the script is called to self,
 * it is guaranteed that while the player is close to a marker (5 meters radius circle) won't go unconscious,
 * to make sur he/she will be able to heal themself. If the unit dies or leaves the area the reset timer
 * is set back to its previous value.
 * ----------------------------------------------------------------------------------------------------
 * Author: Achilles
 * ----------------------------------------------------------------------------------------------------
 * How-To
 * ----------
 * - Place following addAction where you want to apply the script:
 *     unit addAction ["Apply wounds","Scripts\MedicalTraining\applyWounds.sqf"];
 * - unit: The unit you want to add the action on.
 * ----------------------------------------------------------------------------------------------------
 * Prerequisites
 * ----------
 * You have to create a marker called medicalTraining (no spaces), or change the script/code.
 * ----------------------------------------------------------------------------------------------------
 */

// Get variables
private _unit = _this select 0; // The unit suffering the wounds
private _caller = _this select 1; // The unit called the script

// Take care of the respawn timer
_respawnTime = playerRespawnTime; // Get the current respawn time
setPlayerRespawnTime 0; // Set respawn time to zero

// Inflict the wounds
// Initialize variables necessary for "inflicting wounds"
_bodyParts = ["head", "body", "hand_l", "hand_r", "leg_l", "leg_r"]; // All the possible body parts
_woundTypes = ["bullet", "grenade", "explosive", "shell", "vehiclecrash", "backblast", "stab", "punch", "falling", "unknown"]; // All the possible wound types

_numOfIters = random 8; // Inflict maximum 8 wounds
_maxDamage = 0.45; // Maximum damage is set to this value + 0.05

for[{private _i = 0}, {_i < _numOfIters}, {_i = _i + 1}] do {
  _damage = random _maxDamage; // Max damage is _maxDamage + 0.05
  _damage = _damage + 0.05; // Add a small number to make sure damage is inflicted
  _bodyPart = selectRandom _bodyParts; // Select random body part
  _woundType = selectRandom _woundTypes; // Select random wound type

  [_unit, _damage, _bodyPart, _woundType] call ace_medical_fnc_addDamageToUnit; // Inflict the wound
};

// Check the unit is still in the area
while{(_unit inArea[getMarkerPos "medicalTraining", 5, 5, 0, false, -1]) && (alive _unit)} do {
  // Check if script is called on self
  if(_unit isEqualTo _caller) then {
    // Check if unit is unconscious
    if(_unit getVariable["ace_isUnconscious", false] isEqualTo true) then {
      [_unit, false] call ace_medical_fnc_setUnconscious; // Wake the unit up
    };
  };

  sleep 5; // Wait for 5 seconds before checking again
};

// Not in the area anymore
setPlayerRespawnTime _respawnTime; // Reset respawn timer
[_unit] call compile preprocessFileLineNumbers "Scripts\MedicalTraining\fullHeal.sqf"; // Call script to heal the unit completely

Well, now my problem is that I don't have access to the respawned unit to "teleport" it back to the position of death, but I'll for a solution to that too. If you guys have any idea of a solution please feel free to enlighten me further :).

 

Nevertheless, I do appreciate all your help. Thanks again.

 

Have fun, take care and ArmA a lot,

 

Achilles.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

EDIT:  I quote the healing script in case someone may want to use it.

 

/* ----------------------------------------------------------------------------------------------------
 * Script to fully heal a unit.
 * Heals all wounds of a unit. Adapted from ACE 3
 * link: https://github.com/Pergor/ADV_MissionTemplate/blob/master/adv_missiontemplate.altis/functions/client/fn_fullHeal.sqf
 * ----------------------------------------------------------------------------------------------------
 * Author: Achilles
 * ----------------------------------------------------------------------------------------------------
 * How-To
 * ----------
 * - Place following addAction where you want to apply the script:
 *     unit addAction ["Fully heal","Scripts\MedicalTraining\fullHeal.sqf"];
 * - unit: The unit you want to add the action on.
 * ----------------------------------------------------------------------------------------------------
 */

// Get variables
_unit = _this select 0; // The unit to be healed

// Perform healing
[objNull, _unit] call ace_medical_fnc_treatmentAdvanced_fullHealLocal; // Fully heal unit

 

Edited by ZaellixA
Add the healing script

Share this post


Link to post
Share on other sites

Finally, I have managed to find a generic solution to my problem.

 

Just for the sake of completeness I will say that I used a "Respawn" Event Handler to handle the teleportation of the new units back to their last position.

 

Thanks again pierremgi and killzone_kidd.

 

Best,

 

Achilles.

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

×