• 🏆 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 doesnt this work?

Status
Not open for further replies.
Level 1
Joined
Dec 28, 2008
Messages
4
Code:
function Mensaje takes nothing  returns nothing
    if GetUnitTypeId(GetLastCreatedUnit())=='Harf' then
        call BJDebugMsg("Arthas")
    endif    
endfunction    

function Spawn_Unidad takes nothing returns nothing
    call CreateUnit(Player(0),'Harf',GetLocationX(GetRectCenter(GetPlayableMapRect())),GetLocationY(GetRectCenter(GetPlayableMapRect())),270)
    call Mensaje()
endfunction

function InitTrig_Trigger takes nothing returns nothing
    local trigger Trigger2 = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(Trigger2, 2.00)
    call TriggerAddAction(Trigger2, function Spawn_Unidad)
endfunction


its pretty simple though i cant make the message appear, and i couldnt make it work with GetUnitName
 
Level 7
Joined
Jul 20, 2008
Messages
377
BJDebugMsg doesn't work, I don't think. You use DisplayTextToForce or DisplayTextToPlayer.
 
Level 1
Joined
Dec 28, 2008
Messages
4
i dont think thats the problem, because if i modify it this way


Code:
function Mensaje takes nothing  returns nothing
    if GetUnitTypeId(GetLastCreatedUnit())=='Harf' then
        call BJDebugMsg("Arthas")
    else
        call BJDebugMsg("Something")
    endif    
endfunction
it shows the msj "Something"
 
Level 11
Joined
Apr 6, 2008
Messages
760
BJDebug message works.

to the problem

i dont think call CreateUnit sets a GetLastCreatedUnit() (which is bj_lastCreatedUnit)

can't try it now, im at a friend's place

Edit:

ok installed wc3 on hes comp. and yes it was as i tought u can how ever fix this

JASS:
function Mensaje takes unit u returns nothing
    if GetUnitTypeId(u)=='Harf' then
        call BJDebugMsg("Arthas")
    endif    
endfunction    

function Spawn_Unidad takes nothing returns nothing
    local unit u = CreateUnit(Player(0),'Harf',GetLocationX(GetRectCenter(GetPlayableMapRect())),GetLocationY(GetRectCenter(GetPlayableMapRect())),270)
    call Mensaje(u)
    set u = null
endfunction

this will do it for you
 
Level 1
Joined
Dec 28, 2008
Messages
4
ok another problem

JASS:
function FootmanMuere takes nothing returns boolean
    return IsUnitDeadBJ(bj_lastCreatedUnit)
endfunction

function Footman takes nothing returns nothing
    local integer FootmanInteger = 1
    call DisableTrigger(gg_trg_Comienzo)
    loop
    exitwhen FootmanInteger==10
        call CreateUnitAtLoc(Player(1),'hfoo',Location(-1799.4,755.4),270)
        loop 
        exitwhen FootmanMuere()==true
        call TriggerSleepAction(1)
        endloop
        set FootmanInteger = FootmanInteger+1
    endloop
    
endfunction

function InitTrig_Comienzo takes nothing returns nothing
    set gg_trg_Comienzo = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(gg_trg_Comienzo,Player(0),"Empezar",true)
    call TriggerAddAction(gg_trg_Comienzo,function Footman)
endfunction

when i type "Empezar" 10 footmans spawn, while i want only 1 footman to spawn, and when that footman dies, another one should be created
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
If you're so fond on using bj_lastCreatedUnit, then you can still avoid using CreateUnitAtLoc...

replace
JASS:
        call CreateUnitAtLoc(Player(1),'hfoo',Location(-1799.4,755.4),270)
by
JASS:
        set bj_lastCreatedUnit = CreateUnit(Player(0),'hfoo',-1799.4,755.4,270) // not sure if this is correct, but something like that anyway

Besides, the FootmanMuere function is utterly useless.

You can simply replace
JASS:
        exitwhen FootmanMuere()==true

with

JASS:
        exitwhen (GetUnitState(bj_lastCreatedUnit, UNIT_STATE_LIFE) <= 0.0)
        // basically check if life of last created unit is ... well... 0...

I also think CreateUnitAtLoc doesn't use bj_lastCreatedUnit either. It probably has to be CreateUnitAtLocBJ. But as I said, just use "CreateUnit" and set a unit variable as the result of that function call.

An example script would look like this:
JASS:
function Footman takes nothing returns nothing
    local integer FootmanInteger = 1
    local unit footman
    call DisableTrigger(gg_trg_Comienzo)
    loop
    exitwhen FootmanInteger==10
        set footman = CreateUnit(Player(0),'hfoo',-1799.4,755.4,270)
        loop
            exitwhen (GetUnitState(footman, UNIT_STATE_LIFE) <= 0.0)
            call TriggerSleepAction(1.0)
        endloop
        set FootmanInteger = FootmanInteger+1
    endloop
    set footman = null
endfunction

function InitTrig_Comienzo takes nothing returns nothing
    set gg_trg_Comienzo = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(gg_trg_Comienzo,Player(0),"Empezar",true)
    call TriggerAddAction(gg_trg_Comienzo,function Footman)
endfunction
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
What exactly is a problem here? You made a loop that will loop from 1 to 10 and create footmans.
I'm not sure why the nested loop doesn't stop the spawning, probably because of the wait, but anyhow - when a unit dies you tell the main loop to continue and create footmans.

Please, at least look at your freaking code and think how to write whatever you want... writing a mish-mesh and coming here with every stupid question won't make you smarter.
 
Status
Not open for further replies.
Top