• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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

Status
Not open for further replies.
Level 2
Joined
Oct 17, 2009
Messages
7
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

JASS:
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.
 
Level 2
Joined
Oct 17, 2009
Messages
7
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<
 
Level 6
Joined
Mar 22, 2009
Messages
276
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.
JASS:
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
 
Level 2
Joined
Oct 17, 2009
Messages
7
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^^
 
Level 2
Joined
Oct 17, 2009
Messages
7
yes i changes the IDs and it doesn't work^^

but its ok i dont rly need it, but it would have been helpful
 
Level 7
Joined
Jul 18, 2009
Messages
272
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.
 
Level 6
Joined
Sep 5, 2007
Messages
264
@swipe5weep: All that could've been simplified:
JASS:
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.
 
Status
Not open for further replies.
Top