• 🏆 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!

Drop Item

Status
Not open for further replies.
Level 8
Joined
Jun 16, 2008
Messages
333
Is there away to make a trigger like if a unit dies and he drops the flag, 15 sec later the flag returns to the base.
I know how to do the drop flag part so im good with that.

Also since im here, is there away to have only special people pick up the flag
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Variables:
boolean flagDropped (default false)
item theFlag
point loc

  • Drop Flag
    • Events
      • Event - Unit Drops Item
    • Conditions
      • (Item Being Manipulated) Equal To (theFlag)
    • Actions
      • Set flagDropped = True
      • Wait - 15.00 seconds
      • Set loc = Center of Base < gen >
      • Custom script: if udg_flagDropped then
      • Item - Move theFlag to (loc)
      • Custom script: call RemoveLocation(udg_loc)
      • Set flagDropped = False
      • Custom script: endif
And make another trigger that sets flagDropped to "False" if a unit picks up the item.
 
Last edited:
JASS:
    function ItemDrop takes nothing returns nothing
        local item dropped = UnitDropItem(GetTriggerUnit(),'flag')  //drop the item
        local real x = GetItemX(dropped) //get its dropped x/y
        local real y = GetItemY(dropped)
        call TriggerSleepAction(15) //eh, the accuracy difference is negligible at 15 seconds for TSA
        if GetItemX(dropped)==x and GetItemY(dropped)==y and not IsItemOwned(dropped) then //check if the X/Y of the item after 15 seconds is the same as before
            call SetItemPosition(dropped,FLAG_RETURN_X,FLAG_RETURN_Y) //if it is, that means it wasn't moved
        endif                                                         //thus, you can return it to its base
        set dropped = null
    endfunction

You can try something like that.

EDIT: Whoops, Bribe beat me. I didn't know it was supposed to be in GUI neither. =P

EDIT2: Added IsItemOwned. This is just freehand code though. Also, replace 'flag' and FLAG_RETURN_X/Y with whatever it is you want.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
^Yes.

Bribe's trigger has a very minor mistake: flagDropped is supposed to be udg_flagDropped in the custom script.

Edit:
For your second question in the first post:
JASS:
function Trig_ItemSpecialPeopleOnly_Actions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local integer uid = GetUnitTypeId(u)
    local item i = GetManipulatedItem()
    local item itemid = GetItemTypeId()
    if itemid == YourItemId and uid != IamSoSpecialId then //Checks if the item is a certain item-type and if the unit is not a certain unit-type
        call UnitDropItemPoint(u,i,GetUnitX(u),GetUnitY(u))
        call DisplayTextToPlayer(GetOwningPlayer(u),0,0,"Sorry, you're not special enough")
    endif
    set u = null
    set i = null
    return false
endfunction

//===========================================================================
function InitTrig_ItemSpecialPeopleOnly takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddAction(t,Condition(function Trig_ItemSpecialPeopleOnly_Actions))
endfunction
I haven't tested it but I think it should work.
 
Level 8
Joined
Jun 16, 2008
Messages
333
you just declare it as an array and it dynamically allocates itself as larger when you need a higher index.
sorry about that, didn't put enough detail... but what I am saying is, I made this trigger
  • Untitled Trigger 001
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Unit-type of (Triggering unit)) Not equal to Heros[4]
      • (Unit-type of (Triggering unit)) Not equal to Heros[5]
      • (Unit-type of (Triggering unit)) Not equal to Heros[6]
      • (Item being manipulated) Equal to TheFlag[1]
    • Actions
      • Item - Move TheFlag[1] to (Center of aFlag <gen>)
how do I make it where I don't need to put all three or thats not possible?
 
Status
Not open for further replies.
Top