Results 1 to 9 of 9

Thread: if damage then command

  1. #1

    if damage then command

    I want to have a trigger command to check if a unit has taken damage. So when you put a bullet in the leg, arms he will then drop weapons. Ive tried the search, both here and google it and biki wiki searched around

    Something like this I would want:
    Condition > if UNITNAME getsdmg


    Then I just add something like:
    On act: UNITNAME action ["dropWeapon", UNITNAME, "weaponsystem"];

  2. #2
    Hi trick99,

    There are Event Handlers that monitor exactly that.

    In this case you can use a Hit or HandleDamage, like this:
    PHP Code:
    _unit addEventHandler ["Hit"
    {
       
    _unit _this select 0;

       { 
    _unit action ["DropWeapon"_x] } forEach weapons _unit;
       { 
    _unit action ["DropMagazine"_x] } forEach magazines _unit;
    }]; 
    _neo_
    Proud community admin/member of The Tour of Teamrespawn

  3. #3
    Thanks man,

    Even tho I dont really get the event handlar part, where it goes or where to store it
    Looked through the addEventHandler "hit", did a small test with a hint "I got shot".. and yeah that worked.

    in unit INIT:
    Code:
    this addEventHandler ["hit", "hint format['I got shot, ouch',_this select 1]"]
    as per example on the wiki.

    So I thought it would be easy to just delete the hint format and copypaste a action "dropWeapon" -code.. but that didnt work so guess you have to go about it as per the code you have done ?
    Last edited by trick99; May 26 2011 at 21:52.

  4. #4
    Hey,

    Just drop the following in the unit init line that you want to handle:
    PHP Code:
    this addEventHandler ["Hit"
    {
       
    _unit _this select 0;

       { 
    _unit action ["DropWeapon"_x] } forEach weapons _unit;
       { 
    _unit action ["DropMagazine"_x] } forEach magazines _unit;
    }]; 
    _neo_

  5. #5
    Nope.. sorry feeling a real noob now. I just ran a copy paste Looking like a good code.. on hit they just normaly drop and return fire.

  6. #6
    Quote Originally Posted by trick99 View Post
    Nope.. sorry feeling a real noob now. I just ran a copy paste Looking like a good code.. on hit they just normaly drop and return fire.
    Sorry about that, now is tested and working.

    PHP Code:
    this addEventHandler ["Hit"
    {
       
    _unit _this select 0;

       { 
    _unit action ["DropWeapon"_unit_x] } forEach weapons _unit;
       { 
    _unit action ["DropMagazine"_unit_x] } forEach magazines _unit;
    }]; 
    _neo_

  7. #7
    That works like a charm, however when he puts downt the guns and mags he starts to spams out instead as reaching for a weapon he doesnt have anymore.. so he stands there drawing a invicible gun over and over. Is there a way to put in say "disableai" or "playactionnow surrender" or "setpos middle" or so to just make him stop and just have a standstill..

    I tried to put in a bracket at the end of magazine drop bracket; but that didnt get understood by him

    Code:
    this addEventHandler ["Hit",  
    { 
       _unit = _this select 0; 
    
       { _unit action ["DropWeapon", _unit, _x] } forEach weapons _unit; 
       { _unit action ["DropMagazine", _unit, _x] } forEach magazines _unit;
       { _unit playActionNow "Surrender"};
     }  
    }];

  8. #8
    Hey,

    You could try this (Not Tested):
    PHP Code:
    this addEventHandler ["Hit",  

       
    _unit _this select 0

       
    _unit disableAi "ANIM";
       
    _unit disableAi "MOVE";
       { 
    _unit action ["DropWeapon"_unit_x] } forEach weapons _unit
       { 
    _unit action ["DropMagazine"_unit_x] } forEach magazines _unit;
       
    _unit playMoveNow "AmovPercMstpSnonWnonDnon_AmovPercMstpSsurWnonDnon";
     }  
    }]; 
    _neo_

  9. #9
    Nope that didnt work, but I went for disableAi and that worked really good. My problem was the bracket, as I went with no bracket it just worked. If you went with playmove or playaction, he just did the anim and then took the gun and proned so total fail on that hehe... but now my code is:

    Code:
    this addEventHandler ["Hit",   
    {  
       _unit = _this select 0;  
    
       _unit disableAi "ANIM"; 
       _unit disableAi "MOVE"; 
       { _unit action ["DropWeapon", _unit, _x] } forEach weapons _unit;  
       { _unit action ["DropMagazine", _unit, _x] } forEach magazines _unit; 
       _unit disableAI "ANIM"; 
     }   
    }];
    What it does is when hit, he drops weapon and magazine, then the disableAi makes him not go up again so he stands kneeled. So that is what I will use Thanks alot for the help of easy code getting the bad guy drop everything if he gets injured instead of continue until death.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •