• 🏆 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] Why won't this work?

Status
Not open for further replies.
I've been trying to get this to work but every attempt fails:

JASS:
function MakeUnit takes unit u, integer unitID returns nothing
    local real unitx = GetUnitX( u )
    local real unity = GetUnitY( u )
    local real unitfacing = GetUnitFacing( u )
    call CreateUnit( GetOwningPlayer( u ), unitID, unitx, unity, unitfacing )   
endfunction

function Snowball takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer unitID = 'B001'
    call MakeUnit( u, unitID )
    set u = null
endfunction

I want to make it so that it creates a unit in front of the triggering unit when he uses the Snowball item.

Here is the thing which fires it off:

JASS:
function Snowball_Conditions takes nothing returns boolean
    if ( not( GetItemTypeId( GetManipulatedItem()) == 'I000' ) ) then
        return false
    endif
    return true
endfunction

function InitTrig_Snowball takes nothing returns nothing
    set gg_trg_Snowball = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Snowball, EVENT_PLAYER_UNIT_USE_ITEM )
    call TriggerAddCondition( gg_trg_Snowball, Condition( function Snowball_Conditions ) )
    call TriggerAddAction( gg_trg_Snowball, function Snowball )
endfunction

An image of the object:
screeniezl4.png
 
Level 9
Joined
Mar 25, 2005
Messages
252
Try using GetManipulatingUnit() instead of trigger unit.
If that doesn't work put a BJDebugMsg() to the Snowball_Conditions function and another one to the Snowball function to see if they are fired correctly at the event.

Also you can change your condition function into this:
JASS:
function Snowball_Conditions takes nothing returns boolean
    return GetManipulatedItem()) == 'I000'
endfunction
 
Level 14
Joined
Nov 18, 2007
Messages
816
so, basically youre creating a new unit on top of an older unit. This may cause some problems. You better create that new unit 200 units far away.
JASS:
call CreateUnit( GetOwningPlayer(u), UnitID, unitx + (Sin(unitfacing*bj_DEGTORAD)*200), unity + (Cos(unitfacing*bj_DEGTORAD)*200), unitfacing)


You could also just inline those two functions.
 
Level 17
Joined
Jun 17, 2007
Messages
1,433
You should probably optimize your conditions/Init into:
JASS:
function Snowball_Conditions takes nothing returns boolean
    return GetItemTypeId( GetManipulatedItem()) == 'I000'
endfunction

function InitTrig_Snowball takes nothing returns nothing
    local integer i = //Your minimum player slot
    set gg_trg_Snowball = CreateTrigger( )
    loop
        exitwhen i>//your highest player slot
        call TriggerRegisterPlayerUnitEvent( gg_trg_Snowball, Player(i), EVENT_PLAYER_UNIT_USE_ITEM, null )
        set i=i+1
    endloop
    call TriggerAddCondition( gg_trg_Snowball, Condition( function Snowball_Conditions ) )
Deaod seems to be correct, also.
 
Status
Not open for further replies.
Top