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

How do I make this MUI? Jass?

Status
Not open for further replies.
Level 6
Joined
Aug 12, 2007
Messages
201
  • CookingItems
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Firepit
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Uncooked Ham
        • Then - Actions
          • Custom script: local unit h = GetTriggerUnit()
          • Hero - Drop (Item being manipulated) from (Hero manipulating item)
          • Item - Remove (Item being manipulated)
          • Wait 5.00 seconds
          • Item - Create Large Ham at (Position of (Triggering unit))
        • Else - Actions
I know because of the wait I have to use local variables, not global ones, but I don't know any Jass at all save for what I can cut paste from other jass I've seen, and even then it never works. I know the last line 'Item - Create Large Ham at (Position of (Triggering unit))' leaks but I don't know the jass line to create the ham at local unit h.

If anyone could help me clean this up that would be great.
 
Level 31
Joined
May 3, 2008
Messages
3,155
at jass, the condition can be set to something like return trigger unittype equal to firepit (unit code) and itemtype equal to (item code)

then you could do like

local real x1 = GetUnitx(h)
local real y1 = Getunity(h)

then create xx item at real x1,real y1

I don't have JNGP with me now, so cannot post the jass version of trigger.
 
Level 31
Joined
May 3, 2008
Messages
3,155
The unit is not the problem, the Wait is the problem.
I had created some similar-issue small system in GUI that is MUI. Use the same method to fit your case.
http://www.hiveworkshop.com/forums/requests-341/simple-spell-triggers-161807/#post1515305

or he could use something as good as this.

JASS:
function Item takes nothing returns nothing
      local unit h = GetTriggerUnit()
      local real x = GetUnitX(h)
      local real y = GetUnitY(h)
      //ooops!! I don't have JNGP with me at this moment, maybe some1 else can post it.

      call Wait (5.00)
      //rofl!! I don't have JNGP, i forgot the call for creating item at unit position. but it was something like call CreateItem(item id, real x, real y)
      set h = null

endfunction
 
Level 6
Joined
Aug 12, 2007
Messages
201
I don't like using wait if I can help it I just couldn't think of any way to time how long it is before the food is done that is also MUI. I'm looking at your map that was in that post now Pharaoh, give me a sec to see if it is what I am talking about/needing.
 
Level 31
Joined
May 3, 2008
Messages
3,155
It's
CreateItem ('id', GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerY()))
and the action is of course TriggerSleepAction; Wait is in GUI :D

Anyway, wait is inefficient. He either needs to use a timer or the one I suggested, which is MUI ;)

cannot remember the call name actually.. lol

he can use timer to make it more efficient or just use wait, since local variable won't be effected by it.
 
Here you go. You can use timers if you want, but it shouldn't make that much of a difference in terms of accuracy (0.250 or so) if it is as long as 5 seconds. It only gets really (or well, it just makes more of a noticeable difference) inaccurate below 1 second or so.

JASS:
constant function FirePitId takes nothing returns integer
    return 'h000'   //REPLACE THIS WITH THE RAWCODE OF THE FIREPIT
endfunction
constant function UncookedHam takes nothing returns integer
    return 'i000'   //REPLACE THIS WITH THE RAWCODE OF THE UNCOOKED HAM
endfunction
constant function LargeHam takes nothing returns integer
    return 'i001'   //REPLACE THIS WITH THE RAWCODE OF THE LARGE HAM
endfunction

function CookAct takes nothing returns nothing
    local unit h = GetTriggerUnit()
    call RemoveItem(GetManipulatedItem()) 
    call TriggerSleepAction(5.) //basically waits 5 seconds
    call CreateItem(LargeHam(),GetUnitX(h),GetUnitY(h))
//yeah I could always assign X/Y to variables, but what if the firepit moves? =P
    set h = null
endfunction
function CookCond takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == FirePitId() and GetItemTypeId(GetManipulatedItem()) == UncookedHam()
endfunction
function InitTrig_CookingItems takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t,Condition(function CookCond))
    call TriggerAddAction(t,function CookAct)
endfunction

Just replace the ids of the items/units in the top. You can view the rawcodes of the ham and the firepit by opening the object editor, and pressing "CTRL+D" (or something like View -> Rawcodes) to check the rawcodes. It should be a four-digit code, and pick the one listed on the left.
 
Level 6
Joined
Aug 12, 2007
Messages
201
Bribe was asking what I was trying to do and I am just trying to make a unit that is a firepit that can't move or do anything, and when you place an item in its inventory, it cooks the item after a period of time and then places the cooked version on the ground.

And I looked at your map Pharaoh and it looks interesting but I've never found a use for hash tables so I don't have any experience with them, I don't really understand how this works or how to use it to make what I want to do work since it is something else entirely when dropping items and vanishing them.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
  • CookingItems
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Firepit
      • (Item-type of (Item being manipulated)) Equal to Uncooked Ham
    • Actions
      • Item - Remove (Item being manipulated)
      • Wait 5.00 seconds
      • Set Point = (Position of (Triggering unit))
      • Item - Create Large Ham at (Point)
      • Custom script: call RemoveLocation(udg_Point)
JASS:
// Conditions ==
function Cooking_Trig_Conditions        takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'h000' and GetItemTypeId(GetManipulatedItem()) == 'i000'
endfunction // replace the above 'h000' with rawcode of Firepit; replace 'i000' with racode of raw ham
// Actions ==
function Cooking_Trig_Actions           takes nothing returns nothing
    call RemoveItem(GetManipulatedItem())
    call TriggerSleepAction(5.)
    call CreateItem('i001',GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()))
    // replace the above 'i001' with the rawcode of large ham
endfunction
// Trigger Initializer (creates the trigger, assigns its events, conditions and actions)
function InitTrig_CookingItems          takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t,Condition(function Cooking_Trig_Conditions))
    call TriggerAddAction(t,function Cooking_Trig_Actions)
endfunction
 
Level 6
Joined
Aug 12, 2007
Messages
201
Oh Bribe the If else etc was there because I plan on having more then just one food item to cook but it is pretty easy to add the conditions to that to have it compensate for item types.

Is setting the point after the wait MUI though, because if another Firepit receives an item wouldn't it change 'Point' to itself?

And I'm opening your new map now Pharaoh.
EDIT: Okay I think I grasp what it is doing better now, instead of a wait you have a dummy that dies on an expiration timer, not sure where the hash tables comes into it but I think I can work that into my current broken trigger.

How does this look?:

  • CookingItems
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Firepit
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Uncooked Ham
        • Then - Actions
          • Set TempPoint2 = (Position of (Triggering unit))
          • Hero - Drop (Item being manipulated) from (Hero manipulating item)
          • Item - Remove (Item being manipulated)
          • Unit - Create 1 FoodIsCookingDummy for (Owner of (Triggering unit)) at TempPoint2 facing Default building facing degrees
          • Unit - Add a 8.00 second Generic expiration timer to (Last created unit)
          • Custom script: call RemoveLocation( udg_TempPoint2)
        • Else - Actions
  • FoodIsCooked
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to FoodIsCookingDummy
    • Actions
      • Set TempPoint2 = (Position of (Triggering unit))
      • Item - Create Large Ham at TempPoint2
      • Custom script: call RemoveLocation( udg_TempPoint2)
Later versions would have more food and more types of dummies for each food type. I think this is where the Hashtable comes in but I'm not sure how to work that out.
 
Level 6
Joined
Aug 12, 2007
Messages
201
I might switch over to using your system Bribe because with Pharaoh's two trigger version I can't figure out how to compensate for how many foods were in that stack before they were removed, should work since Purge said it would.

  • CookingItems Copy
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Firepit
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Uncooked Ham
        • Then - Actions
          • Hero - Drop (Item being manipulated) from (Hero manipulating item)
          • Item - Remove (Item being manipulated)
          • Wait 5.00 seconds
          • Set TempPoint2 = (Position of (Triggering unit))
          • Set TempInt = (Charges remaining in (Item being manipulated))
          • Item - Create Large Ham at TempPoint2
          • Item - Set charges remaining in (Last created item) to TempInt
          • Custom script: call RemoveLocation( udg_TempPoint2)
        • Else - Actions
How about this then?
Hurm, that didn't work, the created cooked Ham had no charges in it. Is it because I'm setting the charges after the wait, and the item has already been removed so the charges must be 0? But I can't set the charges before the wait because then it stops being MUI,

And in the end neither Bribe nor Pharaoh's system works as smoothly or cleanly as I really want, since there is no visual cue that food is actually being cooked, you can cook multiple food at the same time, and that there is no way to interrupt it once the process has started.

Ideally it would work in that you place a stack of one food item in the inventory of the fire, and then it somehow shows a count down or something to let you know that the food is cooking such as transforming into the firepit model that has a pig over it via Chaos, but if you remove the food before it is done cooking it stops the whole process. Maybe it builds a dummy unit so you can see the progress bar, and once the unit is done building it is removed and a cooked food is added to the inventory. It would have two inventory slots maybe, one for incoming food and one 'reserved' with an undroppable item where the cooked food would go that is replaced with the cooked food once it is done cooking. Gosh this sure is complex.
 
Status
Not open for further replies.
Top