• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Backpack

Status
Not open for further replies.
Level 14
Joined
Dec 29, 2009
Messages
931
Okie so I have this trigger and it does this thing...
Lol, it moves the backpack to the player's hero every 0.03 seconds so it appears as if the hero is carrying the backpack.
You've all seen this before.

But it feels to simple.. I have to be missing something, and I can't think straight right now.

  • Backpack 01
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set BackPack_TempInt = 1
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (gen_PlayerHero[BackPack_TempInt] is alive) Equal to True
        • Then - Actions
          • Set BackPack_TempLoc = (Position of gen_PlayerHero[BackPack_TempInt])
          • Unit - Move (Triggering unit) instantly to BackPack_TempLoc
          • Custom script: call RemoveLocation(udg_BackPack_TempLoc)
        • Else - Actions
          • Trigger - Turn off (This trigger)
There will be 8 copies of this trigger, each one being exactly the same except the BackPack_TempInt.
It will be a number between 1 and 8, for each trigger respectively, representing the player number.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
There's no need to copy trigger 8 times, instead, you could add backpacks to a unit group and iterate group with a 0.03 period. When a backpack owner dies, remember to remove backpack as well.
Also, you forgot to replace triggering unit there.

What also might be good is to use SetUnitX/Y functions for moving backpack as these don't interrupt orders so you'll be able to issue backpack to give items to owner during movement or such.

It would look something like this:
  • BackpackAssignment
    • Event
      • whoknowswhat
    • Actions
      • Create backpack
      • add backpack to BackpackGroup
      • set backpacks[player id of owner] = created backpack
  • Backpack
  • Events
    • Every 0.03 seconds of game time
  • Actions
    • Unit group - pick every unit in BackpackGroup and do
      • Custom script: call SetUnitX(GetEnumUnit(), GetUnitX(udg_gen_PlayerHero[GetPlayerId(GetEnumUnit()) + 1]))
      • Custom script: call SetUnitY(GetEnumUnit(), GetUnitY(udg_gen_PlayerHero[GetPlayerId(GetEnumUnit()) + 1]))
  • Backpack removal
    • Events
      • Unit dies
    • Conditions
      • Triggering unit has backpack //Do some check here
    • Actions
      • Remove Backpacks[GetPlayerId(GetTriggerUnit())] from BackpackGroup
      • Remove unit Backpacks[GetPlayerId(GetTriggerUnit())]
 
Level 14
Joined
Dec 29, 2009
Messages
931
For the SetUnitX/Y wouldn't you use the variable for the backpack unit, not the player hero for the first part?

Something like this?

  • BackPacks Test
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer BP_TempInt) from 1 to 8, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (gen_PlayerHero[BP_TempInt] is alive) Equal to True
            • Then - Actions
              • Set BP_TempLoc = (Position of gen_PlayerHero[BP_TempInt])
              • Custom script: call SetUnitX(udg_BP_Unit[udg_BP_TempInt], GetLocationX(udg_BP_TempLoc))
              • Custom script: call SetUnitY(udg_BP_Unit[udg_BP_TempInt], GetLocationY(udg_BP_TempLoc))
              • Custom script: call RemoveLocation(udg_BP_TempLoc)
            • Else - Actions
              • Trigger - Turn off (This trigger)
 
Status
Not open for further replies.
Top