Jump to content
Sign in to follow this  
febriannas

Handle Damage for Passenger inside the truck init

Recommended Posts

TRUCK addEventHandler ["handleDamage",{ TRUCK setDamage ((damage TRUCK) /1.01)}];

its working for the TRUCK, but its not working for the passanger inside it?

because i already give my unit that init too..

but its not working, maybe theres a diffrent class eventhandler when the UNIT get inside the TRUCK, is that right?

if so how to write the init for the truck?

Share this post


Link to post
Share on other sites

It's not working for your unit, because when the truck damaged (by a bullet), the crew does not.

I'm not sure, but I believe this should work as you wish:

[color=#FF8040]this [color=#191970][b]addEventHandler[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"HandleDamage"[/color][color=#8B3E2F][b],[/b][/color] 
[color=#8B3E2F][b]{[/b][/color]
   [color=#1874CD]_truck[/color]        [color=#8B3E2F][b]=[/b][/color] [color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_damage[/color]       [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]2[/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]/[/b][/color] [color=#FF0000]1.01[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_truck[/color] [color=#191970][b]setDamage[/b][/color] [color=#1874CD]_damage[/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]{[/b][/color][color=#000000]_x[/color] [color=#191970][b]setDamage[/b][/color] [color=#1874CD]_damage[/color][color=#8B3E2F][b];[/b][/color][color=#8B3E2F][b]}[/b][/color] [color=#191970][b]count[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#191970][b]crew[/b][/color] [color=#1874CD]_truck[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_damage[/color]    [color=#006400][i]//must not forget to return the damage![/i][/color]
[color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color][/color]

Kudos to Killzone_Kid for his SQF to BBCode Converter.

EDIT:

You shouldn't use the "damage" command inside a damage EH. This can cause problems if the damage is inflicted by something which hits more than one part at once, like e.g. a granade, because the EH fires for every hit part, hence you might by that set inaccurate damage (way more or way less) to the truck than the granade would have done.

Edited by waltenberg

Share this post


Link to post
Share on other sites

this will be undefined inside EH scope, you should use _this select 0. This is not to say that that code will work, which I doubt will.

Share this post


Link to post
Share on other sites
boby addEventHandler ["handleDamage",{ boby setDamage ((damage boby) /1.01)}];

the init only working with the "unit name boby" i dont know its not working with the "this" thing?

so i use my code inisde the infantry unit "boby" init,

it makes the infantry never dies from gun shoot or rocket, only get reduce health and wounded from it.

but when the unit is inside the truck, it gets killed with the truck by AT rocket shoot.

Share this post


Link to post
Share on other sites

im sory im still...

maybe what im trying to do is..

truck1 addEventHandler ["handleDamage",{ (crew truck1) setDamage ((damage (crew truck1)) /1.01)}];

or maybe

truck1 addEventHandler ["HandleDamage", {{(crew truck1) setDamage 0.7;} count (crew truck1) == 0}]

but it all cannot be done.

so it will effect anyone who board the truck

can you show me to do it right? im a little bit newb :p hehe

please i really appreciate it

Edited by febriannas

Share this post


Link to post
Share on other sites

Please read the statement(s) above. You are putting this code into the init part of the truck. That means, "truck1" does not exist. In the init part, the truck itself refers as "this".

As Killzone_Kid mentioned, you cannot use "this" (resp. "truck1") inside the event handler. Replace "truck1" in the event handler code with "_this select 0":

I'll post it again, please just try it as-is and tell us if it worked:

[color=#FF8040]this [color=#191970][b]addEventHandler[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"HandleDamage"[/color][color=#8B3E2F][b],[/b][/color] 
[color=#8B3E2F][b]{[/b][/color]
   [color=#1874CD]_truck[/color]        [color=#8B3E2F][b]=[/b][/color] [color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_damage[/color]       [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]2[/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]/[/b][/color] [color=#FF0000]1.01[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_truck[/color] [color=#191970][b]setDamage[/b][/color] [color=#1874CD]_damage[/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]{[/b][/color][color=#000000]_x[/color] [color=#191970][b]setDamage[/b][/color] [color=#1874CD]_damage[/color][color=#8B3E2F][b];[/b][/color][color=#8B3E2F][b]}[/b][/color] [color=#191970][b]count[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#191970][b]crew[/b][/color] [color=#1874CD]_truck[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_damage[/color]    [color=#006400][i]//must not forget to return the damage![/i][/color]
[color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color][/color]

Share this post


Link to post
Share on other sites

its still not working..

just did a try it as-is again, (doing some editing in notepad) because the text format (space and tab) it gets massed up when pasted into game editor init,

and still, all the passanger get killed KIA

its wierd.. the unit (boby) never got killed when outside vehicle even with granade and at launcher.

but when they all inside the truck, and the truck destroyed by at launcher or granade, they all get killed.

its like the unit (boby) init the EH /1.01 only work outside the truck.

when they inside the truck they got killed, even after i put the code above as is..

maybe they become different class after boarding the truck?

Share this post


Link to post
Share on other sites

OK, I don't understand what you actually want. My code was based on your first post where you wrote an EH, wrote it wouldn't work and that you want the same code to work for the units inside that truck (when the truck gets hit as I understood it). But now you say, the crew should not be killed.

Probably you should describe the setting/context you want to have this EH and describe, what you actually want to achieve with it. Probably you could even provide a small template mission containing the important objects.

And what should this "damage truck / 1.01" do anyway? Why 1.01?

Edited by waltenberg

Share this post


Link to post
Share on other sites

it will devide the damage, right? so if the bullet damage hit, it will devide it and never exceed the damage size, the .01 to prevent the larger size damage,

ohya maybe i can set it to .05?

i dont exactly know what the damage of each gun or maybe explosion,

maybe can you get me to the list of the damage?

or is there any other way to prevent unit from diying, still get damage but never exceed 0.9?

Share this post


Link to post
Share on other sites

or is there any other way to prevent unit from diying, still get damage but never exceed 0.9?

Yes, there is. Simply stop the HandleDamage EH to return the dealt damage, if that would exceed 0.9. So putting the following into the init field of the car and/or the unit will set their damage limit to 0.9:

[color="#FF8040"]this [color="#191970"][b]addEventHandler[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"HandleDamage"[/color][color="#8B3E2F"][b],[/b][/color] 
[color="#8B3E2F"][b]{[/b][/color]
   [color="#1874CD"]_object[/color]    [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
   [color="#1874CD"]_damage[/color]    [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]2[/color][color="#8B3E2F"][b];[/b][/color]
   [color="#191970"][b]if[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#191970"][b]damage[/b][/color] [color="#1874CD"]_object[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]+[/b][/color] [color="#1874CD"]_damage[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]0.9[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]then[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#FF0000"]0.9[/color][color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]else[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#1874CD"]_damage[/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

If you know exactly, which units will be crew of the respective vehicle, put the same code into their init field. But keep in mind that this actually means that you can neither kill the unit(s) nor destroy the car!

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  

×