Jump to content
Sign in to follow this  
HateDread

Replacing Death with Forced Teleport?

Recommended Posts

Howdy all,

How would one force a unit, upon reaching a critical status, to teleport elsewhere? I know how to select the location, with a set/random distance and random direction;

_dist = DISTANCE;

_dir = random 360;

_pos = [(Getpos UNIT select 0) + (sin _dir) * _dist, (Getpos UNIT select 1) + (cos _dir) * _dist, 0];

But how do I avoid the death? I.e. a condition, checking for the unit's critical status, leading to teleporting to a distant location?

Cheers,

- HateDread.

Share this post


Link to post
Share on other sites

This probaly wont work, but maybe something like

_unit damage <0.9

or something. I'm no good at writing scripts so you can try and reword that if you want but I'd wait for some of the experiences scripters.

Good luck though!

Share this post


Link to post
Share on other sites

It would actually be greater than 0.9, as I want it to kick in then, as a condition, but thank for your suggestion :p

I am open to ideas... guys? :)

Share this post


Link to post
Share on other sites

Thank you, Gusta.

But how would I utilise it to select only when unit is damaged a certain amount, overall, and not specific to a body-part? And, in that event, executing a script/command?

Share this post


Link to post
Share on other sites

This pretty interesting thing, it would allow to bypass problems with SOM and ACM synchronization.

So so I understand that this:

targetunit addEventHandler ["HandleDamage",{_this execVM "script.sqf"}];

Works this way: every time unit receives damage script runs. So in that script there should be lines like:

player get veraible damage

if

player damage >0.9

then

(teleports player)

(heals player)

Problem here is that you need to find a way to prevent player from being actually killed. I think there would be lag between getting hurt and running the script, so in this window player could be killed. Another thing is that lots of stuff can insta kill player as well (bombs, tanks etc.).

So there need to be script that works always and decreases damage dealt to player so he can only go to that 0.99 and then invincibility kicks in:

player addEventHandler [""handleDamage"", { false }]

BTW: you will need to remove invincibilty after player is teleported and healed.

I have no idea about coding just posing some random thoughts.

Share this post


Link to post
Share on other sites

Thank you, Taro8! Definitely helped me out, there. Okay, so far, I have:

In SOLDIER1's Init:

this addEventHandler ["HandleDamage",{[sOLDIER1] execVM "Checkhealth.sqf"}];

In Checkhealth.sqf (ignore the debug 'hint's):

_unit = _this select 0;

hint "Running";

if (damage _unit > 0.9) then

{

_unit addEventHandler ["handleDamage", { false }];

hint "PRE-TELE";

_dir = random 360;

_dist = 500;

_unit setpos [(Getpos _unit select 0) + (sin _dir) * _dist, (Getpos _unit select 1) + (cos _dir) * _dist, 0];

hint "TELE";

_unit setdamage 0;

_unit addEventHandler ["handleDamage", { true }];

};

This works against low-intensity fire, but anything higher, it usually teleports the unit away, where it dies (the damage is 'carried-on'... I.e. lagged?)

Any suggestions?

Edited by HateDread

Share this post


Link to post
Share on other sites

I was afraid this would happen.

Maybe make player invincible from start, then make script that counts damage dealt to player using this:

this addeventhandler ["hit", {(_this select 0) setdamage 0;}];

Instead of 'setdamage 0" make it add stuff to your custom variable that will count player damage. Problem here is that you somehow need to get how much damage was dealt to player per one hit.

If not then you can still make use of this, if you use simple values like +1 per hit so at 10 player gets teleported. You would get same damage from tank as from rifle man, creating something like hearts or hit-points system like in old arcade games :p. However this is still pretty interesting concept.

BTW: Even low intesity fire proof player is very nice thing, nice job on that one.

EDIT: To make that first script a bit more fancy you can do something like this: once you are nearly dead and crawl on the ground bleeding the screen fades out, some time skips, you are teleported to some first aid station and screen fades in. Maybe you can add some radio chatter like: "Fist Alpha, this is Tiger Den, report status! Come in Fist Alpha. (pause) Fist Alpha is down organise MEDEVAC (goes on).....". It would be nice if dialogs could use callsigns you can set in SOM.

Edited by Taro8

Share this post


Link to post
Share on other sites

The problem is, it's being used in a mission to avoid death to Predators, from this mod: http://forums.bistudio.com/showthread.php?t=110440, as predators 'dying' isn't too realistic. The idea is that instead of them being killed, they are teleported away. It needs to withstand high-intensity strikes (i.e. a squad of soldiers focus-firing).

I noticed the lower the value set in if (damage _unit > 0.9) then, the more it can resist, as the script kicks in faster. Might be worth tinkering with, I think...

EDIT: It seems even using '0.4' won't allow it to kick in soon enough to save the unit. Also, if the damage threshold is set too low, a simple grenade strike nearby can set off the script, and lower the unit's overall fighting ability/ability to withstand fire.

Edited by HateDread

Share this post


Link to post
Share on other sites

Predator or not, I just see this script as a nice way to lower difficulty quite a bit for n00bs like me without making player invincible.

If its for Predator then my idea idea with arcade-like "hit-points" (Aliens vs Predator hurrrr) is pretty sound. However I would advice you to continue working on this so it can be used for normal humans as well.

Share this post


Link to post
Share on other sites

Oh, I know - I'm testing using humans, not Predators. And so it will work for them BEFORE I try and use it for the predators.

Now I am looking for a way to execute an immunity or hold-back the damage as fast as possible. It seems it kicks in far too late to prevent death. Does anyone have any ideas, with the following script?

_unit = _this select 0;

hint "Running";

if (damage _unit > 0.9) then

{

_unit addEventHandler ["handleDamage", { false }];

hint "PRE-TELE";

_dir = random 360;

_dist = 500;

_unit setpos [(Getpos _unit select 0) + (sin _dir) * _dist, (Getpos _unit select 1) + (cos _dir) * _dist, 0];

hint "TELE";

_unit setdamage 0;

_unit addEventHandler ["handleDamage", { true }];

};

Share this post


Link to post
Share on other sites

As I said before you need script that will NEVER allow player to go over that 0.99 damage, and that script should be always in effect, then first script will work perfectly.

Or you can do more aracade stuff like this:

add this to player init:

player addEventHandler [""handleDamage"", { false }]

then:

this addeventhandler ["hit", setvalue playerdamagecount +1, ,{[sOLDIER1] execVM "Checkhealth.sqf"}];

In script:

if playerdamage =10

then

(teleports player)

setvalue playerdamage =0

VERY crude, but I thnk it will work.

EDIT: If you somehow manage to get how much player was hit for then you can do something like this:

getvalue hitdamage

if

hitdamage <=0.99

then

setvalue player damage =hitdamage

if

hitdamage >0.99

then

setvalue player damage =0.99

(then rest of the first script, minus invinciblity)

if (damage _unit > 0.9) then

{

hint "PRE-TELE";

_dir = random 360;

_dist = 500;

_unit setpos [(Getpos _unit select 0) + (sin _dir) * _dist, (Getpos _unit select 1) + (cos _dir) * _dist, 0];

hint "TELE";

_unit setdamage 0;

};

This way you can get hurt and player is still invincible all the time so heavy stuff cant kill him.

Edited by Taro8

Share this post


Link to post
Share on other sites

I've got, in a trigger set to 'always', the following:

Condition:

(damage SOLDIER1 > 0.9) && isserver

On Act.:

SOLDIER1 addEventHandler ["handleDamage", { false }]; player sidechat "DAMAGE OFF"; SOLDIER1 setdamage 0;

On Deact.:

SOLDIER1 addEventHandler ["handleDamage", { true }]; player sidechat "DAMAGE ON";

Then SOLDIER1's init:

this addEventHandler ["HandleDamage",{[sOLDIER1] execVM "Checkhealth.sqf"}];

And Checkhealth.sqf:

_unit = _this select 0;

hint "Running";

if (damage _unit > 0.8) then

{

_unit setdamage 0;

hint "PRE-TELE";

_dir = random 360;

_dist = 500;

_unit setpos [(Getpos _unit select 0) + (sin _dir) * _dist, (Getpos _unit select 1) + (cos _dir) * _dist, 0];

hint "TELE";

_unit setdamage 0;

};

(The multiple 'setdamage's are an attempt to stop the over-flow of damage).

Still only works against low-intensity. Next I will begin trying your idea.

Share this post


Link to post
Share on other sites

Rather important thing: I found out that "addEventHandler ["handleDamage", { false }]" dosent work all that good. In ACE it dosent work for me, but "objectName allowDamage false" does work, you can try first script with this one.

Share this post


Link to post
Share on other sites

Hmm, same deal. Not sure if it offers any other improvements. Your suggestion regarding setting damage immunity, then using custom variable(s) to handle damage, seems to be an effective idea, but I am unsure how to measure the damage of an incoming round 'without' comparing the received damage with the health, i.e. 1 - healthleft = damage dealt, which could then be used to change a custom variable, also starting at 1, whilst setting the player's damage back to 0.

Again, this requires the player to physically take damage, which is hard to 'hold back' when in full-force.

Using a trigger running constantly when the player's damage is greater than say, 0.9, again doesn't activate fast enough to prevent death, even if after setpos-ing to somewhere else.

This is a rather frustrating script >:C

Share this post


Link to post
Share on other sites

Oh, Ive got great idea!

How about creating some other, invisible, silent and defenseless NPC that is attached ("attachto" command) directly to player? If he dies player is teleported out, then he is revived by the same script. Also his damage can be transmited to player, who is invincible all the time.

Edited by Taro8

Share this post


Link to post
Share on other sites

Sadly, I do not think that would work - it would create many scripting problems and obstacles. It would become a nightmare moreso than now. I can't see any other ways :/ I need to figure out how to implement the immunity directly after the damage has been dealt sufficiently.

As you mentioned earlier, this would be a problem against insta-kill weapons such as bombs, artillery, tank guns, and even headshots, it seems.

So your earlier idea of initial immunity sounds like it could counter those. I just need to figure out how to correctly gather the hit information - particularly how much damage a round carries WITHOUT actually damaging the target.

Continue with your ideas! We might be on to something!

EDIT:

Make sure you use "CALL" for your EH, as spawns or execVMs are too slow.

Charon Productions gave me that hint. Not sure how to use it tbh :/ Ideas?

Edited by HateDread

Share this post


Link to post
Share on other sites

I dont think that this "shadow" would create all that much trouble. After all its only supposed to be attached to player and take damage, die and be revived. The question is: if it will be invisible, can it take damage?

Anyway, I think you need to use CALL like this:

this addEventHandler ["HandleDamage",{[sOLDIER1] CALL "Checkhealth.sqf"}];

Just a guess.

BTW: Could you write that arcade script I was talking about? I could use that one.

EDIT: Dude I just realized that you can make "walk-it-off" health system using that "arcade" style script. However here you can combine this with first aid!

Edited by Taro8

Share this post


Link to post
Share on other sites

Yeah, a call (vs execVM/spawn) seems logical in such a time critical application. A call is is done similar to a spawn, in that it needs code rather than a script file (although you can precompile a script file using compile preprocessfilelinenumbers "file").

myFunction = { ...code...};

[] call myFunction;

Don't use sleep or waitUntil in myFunction though.

But...

this addeventhandler ["hit", setvalue playerdamagecount +1, ,{[sOLDIER1] call fn_checkHealth}];

What is "setvalue"? Call syntax is red, just for ref. Also, "hit" eventhandler isn't a good option, but "handledamage" allows you to, well, handle the damage, which means limit it if needed so that you're never actually killed by damage. "Hit" EH doesn't allow this.

Share this post


Link to post
Share on other sites

Im complete n00b at coding and I dont know proper commands.

The reason why it was hit was just an idea how to detect if player was hit while he's invincible. It would be something like arcade health system.

Anyway, good that you know how to use CALL, HateDread could use that knowledge. However there is still issue with stuff that can insta kill player.

Share this post


Link to post
Share on other sites

Okay, so something like, in init.sqf:

Telefunction =

{

_unit = _this select 0;

hint "Running";

if (damage _unit > 0.9) then

{

_unit allowDamage false;

hint "PRE-TELE";

_dir = random 360;

_dist = 500;

_unit setpos [(Getpos _unit select 0) + (sin _dir) * _dist, (Getpos _unit select 1) + (cos _dir) * _dist, 0];

hint "TELE";

_unit setdamage 0;

_unit allowDamage true;

};

};

(Ignoring debug 'hint's).

And this in the unit's init field:

this addEventHandler ["HandleDamage",{[sOLDIER1] call Telefunction}]

The unit still seems to die before it can be run, though?

Share this post


Link to post
Share on other sites

Maybe you could try out my idea with attached "shadow" just for now, until we come up with better idea.

BTW: Would you spare some time to write script for pretty pimped out "walk-it-off" system, with image blur, increasingly red and fading screen? Not now, maybe later.

Share this post


Link to post
Share on other sites

The problem with the 'shadow' is:

- Creating a human/soldier that is invisible, and without collision (or else it'd physically clash with the player it was 'attachto'-ed to), whilst still enabling it to 'collide' with incoming rounds, and therefore be damaged.

- Making sure the shadow is classed correctly, meaning that the enemies' hit-priority calculations are accurate - they will favour shooting certain types of units over others.

- Having the 'shadow' character be able to take the fire for the player - it would need to be physically bigger than the player, to cover all angles they could be shot from, so I would need to somehow expand its size and/or hitbox.

These are theoretical problems. I don't even know how to make a character invisible, and without collision, etc. I wish I did, but I can't see that working. It's a nice idea though :)

And sure thing; I'll give it a crack. First up is the basic 'arcade' style script you were talking about earlier. I'll get to that as soon as I can, yeah? Can you describe exactly what you are after so I can go about creating it easier, and more accurately?

Share this post


Link to post
Share on other sites

The unit still seems to die before it can be run, though?

Cool thread, ive been playing around with spawning my player at predefined places when dead, i found that you need to use this "onPlayerKilled.sqf" with just this in the file

sleep 1;

So that the game doesn't automatically go to game over...

I tried your script in the init and also in the onPlayerKilled.sqf but he just remains invincible, cannot die

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  

×