1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  4. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] stop attack of a specific unit on a specific building

Discussion in 'Triggers & Scripts' started by 007007, Oct 17, 2009.

  1. 007007

    007007

    Joined:
    Oct 17, 2009
    Messages:
    7
    Resources:
    0
    Resources:
    0
    hey guys :)

    i got really interested in mapping and now i have a problem

    i'm doing a vampirism map, maybe you know them. and i want to make an admin tower. there is a gold supplier that must be killed by the humans to get gold. my problem is that the admin tower always attacks the gold supplier and i want to stop that.

    first of all, the tower is no tower. its a unit that cant be moved and has a attack with 20k range.

    thats my script. why is it not working?

    npn2 = ID of my admin unit
    n000 = ID of the gold supplier

    Code (vJASS):
    function Trig_AdminSupplier_Conditions takes nothing returns boolean

        if (not (GetUnitTypeId(GetAttacker())=='npn2')) then
            return false
        endif
       
        return true

    endfunction

    function Trig_AdminSupplier_Actions takes nothing returns nothing

        if (GetUnitTypeId(GetAttackedUnitBJ())=='n000') then
            call DisplayTimedTextToForce(GetPlayersAll(),30,"|cFFCC0000You can't attack the Gold Supplier!|r")
            call IssueImmediateOrderBJ(GetAttacker(),"stop")
        endif

    endfunction

        call TriggerRegisterAnyUnitEventBJ(udg_trigger98,EVENT_PLAYER_UNIT_ATTACKED)
        call TriggerAddCondition(udg_trigger98,Condition(function Trig_AdminSupplier_Conditions))
        call TriggerAddAction(udg_trigger98,function Trig_AdminSupplier_Actions)


    set udg_trigger98=CreateTrigger()
     


    i have to say that the script itself works. i dont get errors when saving the map. but my tower (or unit) still attacks the gold supplier.


    or is there a easier way with the object-editor in the WE?
    i want the tower just to attack friendly buildings.
     
  2. 007007

    007007

    Joined:
    Oct 17, 2009
    Messages:
    7
    Resources:
    0
    Resources:
    0
    ok i tried some other things but it still doesn't work
    really frustrating >.<

    i hope someone can help me
    and of course everyone who helps me gets +rep

    >bump<
     
  3. swipe5weep

    swipe5weep

    Joined:
    Mar 22, 2009
    Messages:
    273
    Resources:
    0
    Resources:
    0
    maybe you can play around with combat - attack 1 - target allowed and combat - targeted as ?

    i tried to create one in gui then converted it to jass and compare it to what you got.
    Code (vJASS):
    function Trig_stop1_Func002001 takes nothing returns boolean
        return ( GetUnitTypeId(GetAttacker()) == 'hgtw' )
    endfunction

    function Trig_stop1_Func002002 takes nothing returns boolean
        return ( GetUnitTypeId(GetAttackedUnitBJ()) == 'hpea' )
    endfunction

    function Trig_stop1_Conditions takes nothing returns boolean
        if ( not GetBooleanAnd( Trig_stop1_Func002001(), Trig_stop1_Func002002() ) ) then
            return false
        endif
        return true
    endfunction

    function Trig_stop1_Actions takes nothing returns nothing
        call IssueImmediateOrderBJ( GetAttacker(), "stop" )
    endfunction

    //===========================================================================
    function InitTrig_stop1 takes nothing returns nothing
        set gg_trg_stop1 = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_stop1, EVENT_PLAYER_UNIT_ATTACKED )
        call TriggerAddCondition( gg_trg_stop1, Condition( function Trig_stop1_Conditions ) )
        call TriggerAddAction( gg_trg_stop1, function Trig_stop1_Actions )
    endfunction

     
     
  4. 007007

    007007

    Joined:
    Oct 17, 2009
    Messages:
    7
    Resources:
    0
    Resources:
    0
    hey,

    at first. thx for your help :)

    i tried it but it still doesnt work >.<
    looks like i have to remove the tower. but thats ok its not that important^^
     
  5. swipe5weep

    swipe5weep

    Joined:
    Mar 22, 2009
    Messages:
    273
    Resources:
    0
    Resources:
    0
    did you changed the unit id?
    i think yes.
    thats too bad if the stop order doesn't affect buildings.
     
  6. 007007

    007007

    Joined:
    Oct 17, 2009
    Messages:
    7
    Resources:
    0
    Resources:
    0
    yes i changes the IDs and it doesn't work^^

    but its ok i dont rly need it, but it would have been helpful
     
  7. meOme

    meOme

    Joined:
    Jul 18, 2009
    Messages:
    272
    Resources:
    0
    Resources:
    0
    You don't need any triggers. Give the Gold Supplier the unit classification "suicidal" and add "non-suicidal" to the allowed attack targets of your admin unit. With this, your admin unit can't attack the gold supplier anymore.
     
  8. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,700
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    Given from your example, you seem to not have any or much Jass knowledge, so I will give you the example in GUI to avoid confusion.

    • Untitled Trigger 001
      • Events
        • Unit - YOUR_UNIT Is issued an order targeting an object
      • Conditions
        • (Target unit of issued order) Equal to YOUR_BUILDING
      • Actions
        • Unit - Order (Ordered unit) to Stop
     
  9. Lord_BoNes

    Lord_BoNes

    Joined:
    Sep 5, 2007
    Messages:
    264
    Resources:
    0
    Resources:
    0
    @swipe5weep: All that could've been simplified:
    Code (vJASS):

    function Trig_stop1_Actions takes nothing returns nothing
        if (GetUnitTypeId(GetAttacker()) == 'hgtw') then
            if (GetUnitTypeId(GetAttackedUnitBJ()) == 'hpea') then
                call IssueImmediateOrderBJ( GetAttacker(), "stop" )
            endif
        endif
    endfunction

    //===========================================================================
    function InitTrig_stop1 takes nothing returns nothing
        set gg_trg_stop1 = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(gg_trg_stop1, EVENT_PLAYER_UNIT_ATTACKED)
        call TriggerAddAction( gg_trg_stop1, function Trig_stop1_Actions )
    endfunction
     

    On top of that, it appears that meOme has given a valid solution.