HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need help with my Jass script, problem with conditions

08-21-2007, 08:31 PM#1
crayz
I decided to experiment with jass a little today, and ran into a problem.

Basically what I am trying below is to check if the item type is an artifact. If it isn't, it won't display the message. If it is, it will then check if hasWeapon[GetOwningPlayer(GetTriggerUnit())] == 0

If hasWeapon[] is set to 0, and the item is an artifact then it will display the message, otherwise it won't display anything.

Collapse JASS:
function Trig_One_Weapon_Jass_Conditions takes nothing returns boolean
    if ( not( GetItemType(GetManipulatedItem()) == ITEM_TYPE_ARTIFACT)) then
          return false
    endif
    if ( hasWeapon[GetOwningPlayer(GetTriggerUnit())] == 0 ) then
       return true
    else
       return false
    endif
endfunction

function itemPickup takes nothing returns nothing
       call DisplayTextToForce(GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), GetItemName(GetManipulatedItem()))
endfunction

//===========================================================================
function InitTrig_One_Weapon_Jass takes nothing returns nothing
    local integer array hasWeapon
    set gg_trg_One_Weapon_Jass = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_One_Weapon_Jass, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition(gg_trg_One_Weapon_Jass, Condition(function Trig_One_Weapon_Jass_Conditions))
    call TriggerAddAction( gg_trg_One_Weapon_Jass, function itemPickup )
endfunction

Any suggestions?

Thanks!
08-21-2007, 08:43 PM#2
Pyrogasm
local integer array hasWeapon won't work the way you want it to. You'll have to use a global integer array (which you declare in the Variable Editor) instead. The variable would then be called "udg_hasWeapon".

Instead of call DisplayTextToForce(GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit())), GetItemName(GetManipulatedItem())), the BJDebugMsg(...) function is very handy. Thus, it would be better written call BJDebugMsg(GetItemName(GetManipulatedItem())).

Last, your condition is inefficient. You can simply use return <boolean statement> instead of those ugly if/then/else return false things. Thus, you'd write:
Collapse JASS:
function Trig_One_Weapon_Jass_Conditions takes nothing returns boolean
    return (GetItemType(GetManipulatedItem()) == ITEM_TYPE_ARTIFACT) and (udg_hasWeapon[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))] == 0)
endfunction

Last, you'll need to change the value of that variable once they have picked up a weapon:
Collapse JASS:
function itempickup takes nothing returns nothing
    call BJDebugMsg(GetItemName(GetManipulatedItem()))
    set udg_hasWeapon[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))] = 1
endfunction
08-21-2007, 09:00 PM#3
crayz
Alright I fixed it up. Just one question, does BJDebugMsg() only show it to the owner of the triggering unit?

Also, when I save the map I get a bunch of errors :X

Here's the final code so far:
Collapse JASS:
function Trig_One_Weapon_Jass_Conditions takes nothing returns boolean
    return (GetItemType(GetManipulatedItem()) == ITEM_TYPE_ARTIFACT) and (udg_hasWeapon[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))] == 0)
endfunction

function itemPickup takes nothing returns nothing
    call BJDebugMsg(GetItemName(GetManipulatedItem()))
    set udg_hasWeapon[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))] = 1
endfunction

//===========================================================================
function InitTrig_One_Weapon_Jass takes nothing returns nothing
    set gg_trg_One_Weapon_Jass = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_One_Weapon_Jass, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition(gg_trg_One_Weapon_Jass, Condition(function Trig_One_Weapon_Jass_Conditions))
    call TriggerAddAction( gg_trg_One_Weapon_Jass, function itemPickup )
endfunction


Edit: Woops, I thought when you meant 'The variable would then be called "udg_hasWeapon"' I had to rename hasWeapon to udg_hasWeapon in the variable manager =\

The script compiles fine now, thanks for the advice Pyro!
08-22-2007, 07:02 AM#4
Pyrogasm
BJDebugMsg is simply a debug message. It displays text for all players for a long period of time.

I assumed that the display message was only for testing purposes.