• 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] GetRectCenterX and Y returning 0.00

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
HEY GAIZ!!!!!!one

It's meeeeee. I'm having issues this time with this little diddy I created:

JASS:
//How this works: Players will go to ForceRectOne if they're in Force One and ForceRectTwo
scope DyingHeroWindowTimer initializer Init

globals
    private constant real minTime       = 30. //This is how long a player will have to wait to be revived at level 1
    private constant real maxTime       = 150. //Maximum time a maxed out level hero should have to wait to revive
    private constant real maxLevel      = 25. //Maximum Level as defined by your Gameplayer Constants
    rect ForceRectOne    = gg_rct_Force1Spawn // Name your region for Team 1 here, gg_rect_ and then the regions name
    rect ForceRectTwo    = gg_rct_Force2Spawn // Name your Region for Team 2 here, gg_rect_ and then the regions name
    private constant string ReviverFX     = "Abilities\\Spells\\Human\\Polymorph\\PolyMorphFallingSheepArt.mdl"
    private constant string FriendsFX     = "Abilities\\Spells\\Human\\ReviveHuman\\ReviveHuman.mdl"
    
endglobals

private struct Data

    unit d
    timerdialog timdia
    
    static method create takes unit died returns Data
     local Data D = Data.allocate()
        set D.d = died
     return D
    endmethod
    
endstruct

private function Conditions takes nothing returns boolean
    return IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == true
endfunction

private function Timer takes nothing returns nothing
 local timer tim = GetExpiredTimer()
 local Data D = Data(GetTimerData(tim))
 local real X
 local real Y
 local string lol
    if IsUnitAlly(D.d, Player(0)) == false then
        set X = GetRectCenterX(ForceRectOne)
        set Y = GetRectCenterY(ForceRectOne)
    else
        set X = GetRectCenterX(ForceRectTwo)
        set Y = GetRectCenterY(ForceRectTwo)
    endif
    call BJDebugMsg(R2S(X))
    call BJDebugMsg(R2S(Y))
    call ReviveHero(D.d, X, Y, false)
    if (GetLocalPlayer() == GetOwningPlayer(D.d)) then
        call PanCameraTo( X, Y)
        call TimerDialogDisplay(D.timdia, false)
        set lol = ReviverFX
        call ClearSelection()
        call SelectUnit(D.d, true)
    else
        set lol = FriendsFX
    endif
    call DestroyEffect(AddSpecialEffectTarget(lol, D.d, "origin"))
    call DestroyTimerDialog(D.timdia)
    call ReleaseTimer(tim)
    call D.destroy()
endfunction

private function Actions takes nothing returns nothing
 local timer tim = NewTimer()
 local Data D = Data.create(GetDyingUnit())
 local real curLevel = GetHeroLevel(D.d)
 local real dur = (minTime - (maxLevel/maxTime)) + ((maxLevel/maxTime) * curLevel)
    call SetTimerData(tim,D)
    set D.timdia = CreateTimerDialog(tim)
    if (GetLocalPlayer() == GetOwningPlayer(D.d)) then
        call TimerDialogDisplay(D.timdia, true)
    endif
    call TimerStart(tim, dur, false, function Timer)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
 local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition(t, Condition( function Conditions ) )
    call TriggerAddAction(t, function Actions )
endfunction

endscope

You see the problem is that it is returning (0, 0) for the center of the rects, so I assume it's giving me null. I've looked over the code but just can seem to figure it out, even after trying several things I figured would work.

Also, are all the GetLocalPlayers() being used properly, preventing a desync online?
 

Attachments

  • Timer404.w3x
    24.4 KB · Views: 67
Last edited by a moderator:
Level 7
Joined
Jul 18, 2009
Messages
272
I tried to test your map but I get a Syntax Error in the TimerUtils trigger.

Have you tested if GetRectCenterX(gg_rct_Force1Spawn) returns the right value? Maybe something in your variable declaration/setting goes wrong.
 
Level 11
Joined
Apr 29, 2007
Messages
826
I assume your variable get's set up before the rect does, so your variable is just null.

e/ Yeah, was right. Look at your code and how it looks when it's converted to plain JASS.
JASS:
    trigger                 gg_trg_Timer               = null
    rect                    gg_rct_Force1Spawn         = null
    rect                    gg_rct_Force2Spawn         = null
    trigger                 gg_trg_TimerUtils          = null
    constant real DyingHeroWindowTimer___minTime       = 30. //This is how long a player will have to wait to be revived at level 1
    constant real DyingHeroWindowTimer___maxTime       = 150. //Maximum time a maxed out level hero should have to wait to revive
    constant real DyingHeroWindowTimer___maxLevel      = 25. //Maximum Level as defined by your Gameplayer Constants
    rect ForceRectOne    = gg_rct_Force1Spawn // Name your region for Team 1 here, gg_rect_ and then the regions name
    rect ForceRectTwo    = gg_rct_Force2Spawn // Name your Region for Team 2 here, gg_rect_ and then the regions name
    constant string DyingHeroWindowTimer___ReviverFX     = "Abilities\\Spells\\Human\\Polymorph\\PolyMorphFallingSheepArt.mdl"
    constant string DyingHeroWindowTimer___FriendsFX     = "Abilities\\Spells\\Human\\ReviveHuman\\ReviveHuman.mdl"
You see, the rect is null at the beginning, so you're setting your variables to null aswell.

It get's initialized here
JASS:
function CreateRegions takes nothing returns nothing
    local weathereffect we

    set gg_rct_Force1Spawn=Rect(832.0, - 1344.0, 1120.0, - 1056.0)
    set gg_rct_Force2Spawn=Rect(- 384.0, - 256.0, - 192.0, - 96.0)
endfunction
Which is called out of the main function.

JASS:
function main takes nothing returns nothing
    local weathereffect we
    call SetCameraBounds(- 1280.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), - 1536.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM), 1280.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), 1024.0 - GetCameraMargin(CAMERA_MARGIN_TOP), - 1280.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), 1024.0 - GetCameraMargin(CAMERA_MARGIN_TOP), 1280.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), - 1536.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM))
    call SetDayNightModels("Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl", "Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl")
    set we=AddWeatherEffect(Rect(- 2048.0, - 2048.0, 2048.0, 2048.0), 'RAhr')
    call EnableWeatherEffect(we, true)
    call NewSoundEnvironment("Default")
    call SetAmbientDaySound("BlackCitadelDay")
    call SetAmbientNightSound("BlackCitadelNight")
    call SetMapMusic("Music", true, 0)
    call CreateRegions() //HERE
    call CreateAllUnits()
    call InitBlizzard()

call ExecuteFunc("jasshelper__initstructs543853937")
call ExecuteFunc("TimerUtils___init")
call DyingHeroWindowTimer___Init()

    call InitGlobals()
    call InitCustomTriggers()

endfunction
 
Last edited by a moderator:
Level 14
Joined
Jul 26, 2008
Messages
1,009
But I initialized the Rect on the map as Force1Spawn and Force2Spawn, simply by creating them in the map with the Rect Pallete.

When I try initializing the rects like you've demonstrated, it still returns 0,0. I didn't set the rects to null on initialization like you demonstrated, but I didn't see a point in it.

JASS:
//How this works: Players will go to ForceRectOne if they're in Force One and ForceRectTwo
scope DyingHeroWindowTimer initializer Init

globals
    private constant real minTime       = 30. //This is how long a player will have to wait to be revived at level 1
    private constant real maxTime       = 150. //Maximum time a maxed out level hero should have to wait to revive
    private constant real maxLevel      = 25. //Maximum Level as defined by your Gameplayer Constants
    rect ForceRectOne    = gg_rct_Force1Spawn // Name your region for Team 1 here, gg_rect_ and then the regions name
    rect ForceRectTwo    = gg_rct_Force2Spawn // Name your Region for Team 2 here, gg_rect_ and then the regions name
    private constant string ReviverFX     = "Abilities\\Spells\\Human\\Polymorph\\PolyMorphFallingSheepArt.mdl"
    private constant string FriendsFX     = "Abilities\\Spells\\Human\\ReviveHuman\\ReviveHuman.mdl"
    
endglobals

private struct Data

    unit d
    timerdialog timdia
    
    static method create takes unit died returns Data
     local Data D = Data.allocate()
        set D.d = died
     return D
    endmethod
    
endstruct

private function Conditions takes nothing returns boolean
    return IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == true
endfunction

private function CreateRegions takes nothing returns nothing    //<<<<<<<<<<<<<
    set gg_rct_Force1Spawn = Rect(- 300, -170,- 295, - 165)    
    set gg_rct_Force2Spawn = Rect( 970, -1200, 975, - 1195)
endfunction

private function Timer takes nothing returns nothing
 local timer tim = GetExpiredTimer()
 local Data D = Data(GetTimerData(tim))
 local real X
 local real Y
 local string lol
    if IsUnitAlly(D.d, Player(0)) == false then
        set X = GetRectCenterX(ForceRectOne)
        set Y = GetRectCenterY(ForceRectOne)
    else
        set X = GetRectCenterX(ForceRectTwo)
        set Y = GetRectCenterY(ForceRectTwo)
    endif
    call BJDebugMsg(R2S(X))
    call BJDebugMsg(R2S(Y))
    call ReviveHero(D.d, X, Y, false)
    if (GetLocalPlayer() == GetOwningPlayer(D.d)) then
        call PanCameraTo( X, Y)
        call TimerDialogDisplay(D.timdia, false)
        set lol = ReviverFX
        call ClearSelection()
        call SelectUnit(D.d, true)
    else
        set lol = FriendsFX
    endif
    call DestroyEffect(AddSpecialEffectTarget(lol, D.d, "origin"))
    call DestroyTimerDialog(D.timdia)
    call ReleaseTimer(tim)
    call D.destroy()
endfunction

private function Actions takes nothing returns nothing
 local timer tim = NewTimer()
 local Data D = Data.create(GetDyingUnit())
 local real curLevel = GetHeroLevel(D.d)
 local real dur = (minTime - (maxLevel/maxTime)) + ((maxLevel/maxTime) * curLevel)
    call CreateRegions()                //<<<<<<
    call SetTimerData(tim,D)
    set D.timdia = CreateTimerDialog(tim)
    if (GetLocalPlayer() == GetOwningPlayer(D.d)) then
        call TimerDialogDisplay(D.timdia, true)
    endif
    call TimerStart(tim, dur, false, function Timer)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
 local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition(t, Condition( function Conditions ) )
    call TriggerAddAction(t, function Actions )
endfunction

endscope
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
I drifted in and out.

Naw seriously I just wasn't entirely sure what you were saying. I forgot I put rain in my map, and didn't even realize it'd show up in the JASS. I honestly thought you were showing me a demonstration of what to do using weather effects, not actually something to put into my map. I've never looked at the jass in war3map.j

It's not something that's familiar with me. However what you've currently shown me has given me an idea of how it works and what it's doing.

I see what you're saying though, and am recalling the part of vJASS and scopes tutorial that states what Init triggers do and how the initializers work. (Straight to the top of the map)

I'll see if I calling CreateRegion() from the Init function doesn't fix it. Though maybe I should make it require CreateRegion()? Thanks.
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
Yeah that seems a lot simpler. Thanks.

EDIT: I figured out what you were saying BTW.

private function Init takes nothing returns nothing
local trigger t= CreateTrigger()
call TriggerAddActions(t,function stuff)
call TriggerAddConditions(t, function morestuff)
set gg_rct_Force1Spawn=Rect(832.0, - 1344.0, 1120.0, - 1056.0)
set gg_rct_Force2Spawn=Rect(- 384.0, - 256.0, - 192.0, - 96.0)
endfunction
 
Last edited:
Status
Not open for further replies.
Top