Noob jass help

Status
Not open for further replies.
Level 8
Joined
Mar 3, 2009
Messages
327
I'm trying to make a creep revival system for my RPG. I'm good with gui, but im only beginning to dabble in JASS. Anyway;

JASS:
function Trig_creeprevive_Copy_Copy_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) != 'h002' ) ) then
        return false
    endif
    return true
endfunction

function Trig_creeprevive_Copy_Copy_Func005Func001C takes nothing returns boolean
    if ( ( GetUnitTypeId(GetTriggerUnit()) == 'h00B' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetTriggerUnit()) == 'h00C' ) ) then
        return true
    endif
    return false
endfunction

function Trig_creeprevive_Copy_Copy_Func005C takes nothing returns boolean
    if ( not Trig_creeprevive_Copy_Copy_Func005Func001C() ) then
        return false
    endif
    return true
endfunction

function Trig_creeprevive_Copy_Copy_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local timer t = CreateTimer()
    call StartTimerBJ( t, false, 20.00, )
endfunction

//===========================================================================
function InitTrig_creeprevive_Copy_Copy takes nothing returns nothing
    set gg_trg_creeprevive_Copy_Copy = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_creeprevive_Copy_Copy, Player(11), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_creeprevive_Copy_Copy, Condition( function Trig_creeprevive_Copy_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_creeprevive_Copy_Copy, function Trig_creeprevive_Copy_Copy_Actions )
endfunction

Thats what i have so far. When timer t expires i want it to do

JASS:
call CreateNUnitsAtLoc( 1, GetUnitTypeId(u), Player(11), udg_Creep_Point[GetUnitUserData(u)], 270 )
    call SetUnitUserData( GetLastCreatedUnit(), GetUnitUserData(u) )
    if ( Trig_creeprevive_Copy_Copy_Func005C() ) then
        call SetUnitVertexColorBJ( GetLastCreatedUnit(), GetRandomReal(30.00, 100.00), GetRandomReal(30.00, 100.00), GetRandomReal(30.00, 100.00), 0 )
    else
    endif

In the same function, so it doesnt stuff up my local variables. I know it's possible but I'm just starting with JASS so yeah :)

Also, can noone please try and convert me to vJASS, i've tried all i can and JNGP will not work.
 
Level 9
Joined
Nov 4, 2007
Messages
933
Seeing as how you have a non-repeating timer why not just use a TriggerSleepAction(20.00) then put your code in after that? By the way you shouldnt have the extra comma after the 20.00 in your script.
 
Level 9
Joined
Nov 4, 2007
Messages
933
Well thats probably because the unit has been dead for too long and no longer registers in the game, if such is the case then your Timer solution might be just as useless, it might help if instead of referring to the user data of that unit, you instead set a local integer to its data, and you can reuse that integer in place of GetUserData(), if its necessary to get the dead units Id as well for your respawn an integer can be set to that as well.
 
Level 4
Joined
Jan 27, 2010
Messages
133
Your problem with TriggerSleepAction likely has to do with the fact that the unit might be already dead and recycled by the system. Instead of storing the unit, copy the data you want from it:

JASS:
function Trig_creeprevive_Copy_Copy_Actions takes nothing returns nothing

  // Store the dying unit's UserData and Unit Type
    local integer unitid = GetUnitTypeId( GetTriggerUnit() )
    local integer userdata = GetUnitUserData( GetTriggerUnit() )
    local unit newUnit

  // Wait 20 seconds
    call TriggerSleepAction( 20 )

  // Respawn the creep
    set newUnit = CreateUnitAtLoc(Player(11), unitid, udg_Creep_Point[userdata],270)
    call SetUnitUserData(newUnit, userdata)

  // Color 'h00B' and 'h00C' 
    if (unitid == 'h00B' or unitid == 'h00C') then
        call SetUnitVertexColorBJ(newUnit, GetRandomReal(30.00, 100.00), GetRandomReal(30.00, 100.00), GetRandomReal(30.00, 100.00), 0 )
    endif

    set newUnit=null

endfunction

A brief warning about TriggerSleepAction is that it is:
1. Inaccurate
2. Ignoring Waiting-For-Players dialog in multiplayer. That is, if you have a wait for 60 seconds, and Waiting-For-Players appear for 45 seconds, your wait will expire in 15 seconds after that.

Also, can noone please try and convert me to vJASS, i've tried all i can and JNGP will not work.

Are you a mac-user?

The thing is, you want to pass data over a timer-call. That's one of the things which is really simplified by vJASS.

Perhaps if you tell us why it wouldn't work, we would be able to sort it out? :)
 
Last edited:
you don't need the last condition
JASS:
function Trig_creeprevive_Copy_Copy_Func005C takes nothing returns boolean
    if ( not Trig_creeprevive_Copy_Copy_Func005Func001C() ) then
        return false
    endif
    return true
endfunction

//you dont need this, just use Trig_creeprevive_Copy_Copy_Func005Func001C() directly...

and for what you're trying to do just use a wait, I cannot see a problem with it... else you might need to learn structs...

here use this function
JASS:
function Trig_creeprevive_Copy_Copy_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer utype = GetUnitTypeId(u)
   local integer data = GetUnitUserData(u)
    call TriggerSleepAction(20.00)
   call CreateUnitAtLoc( Player(11), utype,  udg_Creep_Point[data], 270 )//Not sure about the sequence of the parameters here, you dont need to create N units at loc because you only create 1 unit..
    call SetUnitUserData( GetLastCreatedUnit(), data )
    if ( Trig_creeprevive_Copy_Copy_Func005C() ) then
        call SetUnitVertexColorBJ( GetLastCreatedUnit(), GetRandomReal(30.00, 100.00), GetRandomReal(30.00, 100.00), GetRandomReal(30.00, 100.00), 0 )
    else
    endif
    set u = null
endfunction
 
Status
Not open for further replies.
Top