• 🏆 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] Need help implementing InvX_EnhanceInventory to unit groups(Attribute menu system)

Status
Not open for further replies.
Level 2
Joined
Nov 17, 2008
Messages
8
I have successfully imported Attribute menu into my map, however i can only implement the Attribute menu system to specific pre-generated units.
e.g call InvX_EnhanceInventory(gg_unit_Hamg_0010,12)

However i wish to allow unit groups such as heroes to use this system, and the units are not pre-generated
. Is there any way to replace gg_unit_xxxx_xxxx with something else to allow this?
Replies and help is really really appreciated!!


The concerning script below:


///===============================================================================================
function InvX_Item_Setup takes nothing returns nothing
call InvX_Initialize()
call InvX_EnhanceInventory(gg_unit_Hamg_0010,12)
call InvX_EnhanceInventory(gg_unit_O000_0126,12)

endfunction

///===============================================================================================
function InitTrig_Setup_InvX_stuff takes nothing returns nothing
call ExecuteFunc("InvX_Item_Setup")
endfunction
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
Did you already try
JASS:
call InvX_EnhanceInventory(udg_YourVariableWichStoresYourUnit,12)
or pick them in a loop
JASS:
//local unit u
//local group g = CreateGroup()
// Group your UnitGroup with GroupEnumUnitsInRange/Rect or whatever, then:
loop
     set u = FirstOfGroup(g)
     exitwhen u == null
     call InvX_EnhanceInventory(u,12)
     call GroupRemoveUnit(g,u)
endloop

?
 
Level 2
Joined
Nov 17, 2008
Messages
8
First of all thanks for your help emma :grin:
Replacing it with a udg_xxx unit group variable doesnt seem to work.
The error shown when i tried this is: invalid argument type (group)

And sorry but i dont really know how to pick units in a loop

Thanks again!
 
Level 2
Joined
Nov 17, 2008
Messages
8
seems like i've found this problem common, trying to implement a equipment system i ran into something similar.

similar script from equipment system.
call FixHero(gg_unit_Hpal_0000,1)

Im sure people have found a way around this. Just need some direction if anyone can help :sad:
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
You cant use a unit group variable, you have to use a UNIT variable, as the function already says: invalid argument type (group)

Other than this, here is an example for picking units in a loop:

Do you know JASS CRAFT? Download it and you have a catalog with functions, if you type in the search window on the right: "GroupEnum".

Here are some of those functions:
JASS:
native GroupEnumUnitsInRange                takes group whichGroup, real x, real y, real radius, boolexpr filter returns nothing // picks all units in range of a target point(X,Y)
native GroupEnumUnitsOfType               takes group whichGroup, player whichPlayer, boolexpr filter returns nothing // picks all units of Type X on the map
native GroupEnumUnitsSelected               takes group whichGroup, player whichPlayer, boolexpr filter returns nothing // picks all units of Type selected by Player X

In this example, i used this one:
JASS:
native GroupEnumUnitsOfPlayer               takes group whichGroup, player whichPlayer, boolexpr filter returns nothing

FIRST STEP

Look at this function, it has a few arguments, that you have to pass to it.
Group, Player is clear.
But there is also this one: boolexpr filter

This means you have to declare a function, in which you can set the conditions for picking the units.
So you could pick all units by player 1 and then add in the function added here the conditon: UnitType == Soldier.

If you dont want to add a condition, just type in there NULL. In this way, you can pick for example all units by player 1 without any condition.

SECOND STEP

Lets start our example.
Make a new map and place 5 footmen on the map for player 1.
Make a new trigger in WE, i named it "Unit Pick".
Convert the trigger into custom script in the WE and copy this text into JassCraft.

I have this text in jasscraft now:
JASS:
function Trig_Unit_Pick_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_Unit_Pick takes nothing returns nothing
    set gg_trg_Unit_Pick = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Unit_Pick, Player(0), "example", true )
    call TriggerAddAction( gg_trg_Unit_Pick, function Trig_Unit_Pick_Actions )
endfunction

This is the basic init function, which each trigger needs, and the action function, this trigger calls, when its runned.
I just added the event "Player types "example"
As you can see player 1 is in jass player 0.

THIRD STEP

Now we gonna modify this trigger in jasscraft. We want to pick all units by player 1, if he types "example".
So first thing is, we have to create local variables. If you dont understand this part, i recommand you reading some basic jass tutorials. If want me to explain this in GUI, you can write me a PN, and i can send you the GUI code.

The variables we need are one for the group, one for the unit, we want to handle in the loop, and one for the player 0.

JASS:
function Trig_Unit_Pick_Actions takes nothing returns nothing
     local unit u
     local group g = CreateGroup() // Creates the group g, in which we want to store all units owned by player 0
     local player p = Player(0)
endfunction

//===========================================================================
function InitTrig_Unit_Pick takes nothing returns nothing
    set gg_trg_Unit_Pick = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Unit_Pick, Player(0), "example", true )
    call TriggerAddAction( gg_trg_Unit_Pick, function Trig_Unit_Pick_Actions )
endfunction

Next Thing is the Pick Function, so now lets just insert it.
JASS:
function PickAllUnitsByPlayerOfType takes nothing returns boolean
endfunction

function Trig_Unit_Pick_Actions takes nothing returns nothing
     local unit u
     local group g = CreateGroup() // Creates the group g, in which we want to store all units owned by player 0
     local player p = Player(0)
     call GroupEnumUnitsOfPlayer(g,p,Condition(function PickAllUnitsByPlayerOfType))
endfunction

//===========================================================================
function InitTrig_Unit_Pick takes nothing returns nothing
    set gg_trg_Unit_Pick = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Unit_Pick, Player(0), "example", true )
    call TriggerAddAction( gg_trg_Unit_Pick, function Trig_Unit_Pick_Actions )
endfunction

As you can see i also added the condition function, in which we want to put some code to define, which units of player 0 we want to pick in the group g.

Lets see, how this can be done:
JASS:
function PickAllUnitsByPlayerOfType takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == 'hfoo' // hfoo == footman Id
endfunction
As you see, this function returns true or false. First, the function GroupEnumUnits picks all units by player 0, and now, this function PickAllunitsByPlayer only returns true, if the unit picked is a footman.
Go to the object editor in WE and press CTRL + D, and you can see, that "hfoo" stands for footman in the WE.

Next thing is the loop.
JASS:
function PickAllUnitsByPlayerOfType takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == 'hfoo'
endfunction

function Trig_Unit_Pick_Actions takes nothing returns nothing
     local unit u
     local group g = CreateGroup() // Creates the group g, in which we want to store all units owned by player 0
     local player p = Player(0)
     call GroupEnumUnitsOfPlayer(g,p,Condition(function PickAllUnitsByPlayerOfType))
     loop
         set u = FirstOfGroup(g) // we pick the first unit in the group g
         exitwhen u == null // the loop exits, if there are no units left in it!
         call DisplayTextToPlayer(p,0,0,GetUnitName(u)) // this is just a message, so that you can see, that our example works
         call GroupRemoveUnit(g,u) // this removes our unit u from the group, so we can pick the next one and continue in our loop through the units of player 0
     endloop
     // This is just to remove leaks, because we have to destroy our local variables
     call DestroyGroup(g)
     set g = null
     set p = null // dont destroy Player(0) because this will crash wc3, it would be like killing yourself ^^
         
endfunction

//===========================================================================
function InitTrig_Unit_Pick takes nothing returns nothing
    set gg_trg_Unit_Pick = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Unit_Pick, Player(0), "example", true )
    call TriggerAddAction( gg_trg_Unit_Pick, function Trig_Unit_Pick_Actions )
endfunction

If you look at the Pick-Function, it will do this:
-It picks all units on the map of player 0
-It stores all units by play 0 of Type footman (hfoo) in the group g
-You got 5 footman in group g after this

If you look at the loop, it will do this:
-You have 5 footman by Player 0
-It sets u == the first footman in group g
-It writes the units name "footman" on the screen
-It removes the unit u from the group g, you got 4 footmen left.
-It sets u == the next footman in group g
ETC ETC ETC ETC
-If there are 0 footmen left in group g, the loop ends, and we destroy our leaks

So this is everything about looping through unit groups in jass.

For example you can modify this trigger so that you can try to change the function
JASS:
call DisplayTextToPlayer(p,0,0,GetUnitName(u))

with

JASS:
call InvX_EnhanceInventory(u,12)

to test, if this would work with your system. I dont know, because i dont know it.

If you have more questions feel free to ask. Its also possible in GUI, its not different, its just another language.

Greets
 
Status
Not open for further replies.
Top