Warcraft III resources & community, 2003–2006 · archived

Forge System Help

13 posts
#1

Forge System Help

So, I'm rather new at JASS.
I know how to look at a lot of the coding now, but I really have no idea how to make it from scratch.
I tried my best on this, and clearly I cannot get it right, nor do I know how many memory leaks it has. I'd greatly appreciate if you could fix this up for me so that I could use it, with the concept of making a unit that is buildable do the forging, not a preplaced unit. Here it is:




function Forge_System_Actions takes nothing returns nothing
    local unit u = GetAttachedUnit()
    local item i = GetAttachedItem()

    if GetUnitTypeId(u) == 'hbla' then
        if GetItemTypeId(belv) == true and GetItemTypeId(bspd) == true then
            call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Other\\ToonBoom\\ToonBoom.mdl",u,"origin"))
            call DisplayTextToForce(bj_FORCE_PLAYER[GetConvertedPlayerId(GetOwningPlayer(u))-1],"|cff00dd00Item Forged|r")
            call RemoveItem(belv)
            call RemoveItem(bspd)
            call UnitAddItemByIdSwapped('rat6',u)  
        endif
    endif

    set i = null
    set u = null
endfunction 

//===========================================================================
function InitTrig_Forge_System takes nothing returns nothing
    set gg_trg_Forge_System = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Forge_System, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Forge_System, function Forge_System_Actions )
endfunction
#2
it should look like This

function Forge_System_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local item i = GetManipulatedItem()

    if GetUnitTypeId(u) == 'hbla' then
        //second if should reference 2 items. GetItemTypeId is used the same as GetUnitTypeId
            call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Other\\ToonBoom\\ToonBoom.mdl",u,"origin"))
            call DisplayTextToForce(bj_FORCE_PLAYER[GetPlayerId(GetOwningPlayer(u))],"|cff00dd00Item Forged|r")//GetConvertedPlayerId-1 is the same as GetPlayerId because GetConvertedPlayerId is GetPlayerId + 1
            //where you remove the items, this would be done just like removing a unit.
            call UnitAddItemById(u,'rat6')//swapped funcs suck
        endif
    endif

    set i = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Forge_System takes nothing returns nothing
    set gg_trg_Forge_System = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Forge_System, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Forge_System, function Forge_System_Actions )
endfunction
#3
So the main function that I jacked up was my variables?
Heh.

And as far as the adding new units and junk, I got those right, I think... in my post, or did I do them incorrectly?
Blah.

function Forge_System_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local item i = GetManipulatedItem()
     
    if GetUnitTypeId(u) == 'hbla' then
        if GetItemTypeId(belv) == true and GetItemTypeId(bspd) == true then
            call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Other\\ToonBoom\\ToonBoom.mdl",u,"origin"))
            call DisplayTextToForce(bj_FORCE_PLAYER[GetPlayerId(GetOwningPlayer(u))],"|cff00dd00Item Forged|r")//GetConvertedPlayerId-1 is the same as GetPlayerId because GetConvertedPlayerId is GetPlayerId + 1
            call RemoveItem('belv') 
            call RemoveItem('bspd')
            call UnitAddItemById(u,'rat6')
        endif
    endif

set i = null
set u = null
endfunction
 
//===========================================================================
function InitTrig_Forge_System takes nothing returns nothing
set gg_trg_Forge_System = CreateTrigger(  )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Forge_System, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_Forge_System, function Forge_System_Actions )
endfunction
#4
GetItemTypeId does not take the Item's rawcode, like youre doing, it takes the item, and you check if it == the item's rawcode.
#5
erm...
then would it be...


if GetItemTypeId() == 'belv' and GetItemTypeId() == 'bspd' then


or what?
I can't figure it out....
#6
no, but close

it would be GetItemTypeId( youritem ) = 'belv'

and etc.

where youritem is the item that you are checking to see if it IS the wanted item.
#7
so are you telling me...
since you aren't putting in an example, just spacial "if's"
leaving me to guess

it would be

GetItemTypeId(Boots of Quel'Thalas +7) = 'belv'
or...
GetItemTypeId('belv') = 'belv'
or...
what?
#8
well, it would look like this ( ill put everything inside the brackets in GUI so you understand )

GetItemTypeId( Item Carried By ( yourunit ) in slot 1 ) = 'belv'
#9
I think the part he was confused about was '=' and not '=='.

= is always assign, despite post typos.
== is always equal compare.
if(GetItemTypeId(i) == 'belv') and (GetItemTypeId(i) == 'bspd') then

endif


Don't forget the '' marks. The two ''s are very important, and change how data is interpretted internally.
#10
Thank you very much, that helped a lot.
I'm still new at JASS, so I'll make n00b mistakes nonstop because I really haven't seen how things are supposed to be done much at all.
But I'm running into another problem:



call RemoveItem('belv') 


How to change this for it to work?
Everything else works except this part now.... which was that which was causing my error.
#11
call RemoveItem(i)

Everything in computers is numbers. An item(like i) is a number pointing to more numbers in memory, which control all aspects of the "item". 'belv' is another number(or several, really), which labels the type of item.

So picture this:

Item in memory:
[number] ItemType
[number] Model
[number] Position X
[number] Position Y
[number] ChargesLeft
[number] ...

Ok, so an item has all these numbers contained within, and JASS functions let you aquire them to compare:

function myItemFunc takes nothing returns nothing
local item i = GetManipulatedItem()

if(GetItemTypeId(i) == 'belv') then
endif

if(GetItemTypeId(i) == 1650814070) then
endif

if(GetItemX(i) == 1024.00) then
if(GetItemY(i) == -512.00) then
endif
endif

if(GetItemCharges(i) == 4) then
endif
endfunction


Make some sense? =)
#12
simply said:
No.
=]

this right here confuses me:


[number] Model
[number] Position X
[number] Position Y

if(GetItemTypeId(i) == 1650814070) then
endif

if(GetItemX(i) == 1024.00) then
if(GetItemY(i) == -512.00) then
endif
endif

Anyways, it's all excess weight to me, what I'm truely looking for is a way to combine items into another item, I don't are whether triggered by the casting of an ability, or by instant transmutating upon placing the items in the required unit.

It's not working at the minute, so I feel troubled, hah.
#13
GetItemX

is the X - Coordinate of the Item on the map ( yes, wc3 runs points like a graph )

any location is an (x,y) data field.

and that string of random numbers is what some item rawcode, maybe 'belv' really is. that 4-digit letter-number sequence is just an easier way to write it, it really refers to a ten-digit number :wink: