• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Forge System Help

Status
Not open for further replies.
Level 4
Joined
May 20, 2006
Messages
43
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:




Code:
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
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
it should look like This

JASS:
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
 
Level 4
Joined
May 20, 2006
Messages
43
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.

JASS:
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
 
Level 2
Joined
Sep 21, 2005
Messages
27
I think the part he was confused about was '=' and not '=='.

= is always assign, despite post typos.
== is always equal compare.
JASS:
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.
 
Level 4
Joined
May 20, 2006
Messages
43
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:



JASS:
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.
 
Level 2
Joined
Sep 21, 2005
Messages
27
JASS:
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:

JASS:
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? =)
 
Level 4
Joined
May 20, 2006
Messages
43
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.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
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:
 
Status
Not open for further replies.
Top