• 🏆 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!

[vJASS] Whats wrong with this easy code?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
I have not coded in vjass for about a year, and I lost my hard drive, so can't look back at my old work. No idea what I'm doing wrong here. Explain it to me please! ;(

JASS:
library citydev

private function selection takes nothing returns boolean
    if GetTriggerEventId() == EVENT_PLAYER_UNIT_SELECTED then
        call BJDebugMsg("SELECTION!")
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_DESELECTED then
        call BJDebugMsg("DESELECTION!")
    endif
    return false
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DESELECTED, null)
        set i = i + 1
    endloop
    call TriggerAddCondition(t, Condition(function selection))
endfunction

endlibrary
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
I'm using 2d arrays, is the limit still a[89][89] ?

JASS:
globals
    integer array buildingOrder
    integer array buildingType 
    constant integer CITY_RADIUS = 800
    integer array owningCity
    hashtable hash = InitHashtable()
endglobals

library CityBuilding initializer init 
    
private function buildOrder takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer order
    local integer i 
    local integer n = GetPlayerId(GetOwningPlayer(u))
    local real x1
    local real y1
    local real x2 
    local real y2 
    local real dx
    local real dy
    if u == cityController[n] then
        set order = GetIssuedOrderId()
        set i = 1
        loop
            exitwhen buildingOrder[i] == null
            if order == buildingOrder[i] then
                set x1 = GetLocationX(GetUnitLoc(u))
                set y1 = GetLocationY(GetUnitLoc(u))
                set x2 = GetLocationX(GetOrderPointLoc())
                set y2 = GetLocationY(GetOrderPointLoc())
                set dx = x2 - x1
                set dy = y2 - y1
                
                if (SquareRoot(dx*dx + dy*dy) > CITY_RADIUS) then     
                    set u = CreateUnit(Player(12), 'n000',x2,y2,0)
                    call UnitApplyTimedLife(u,'BTLF', 0.1)
                endif
                call SetUnitX(cityBuilder[n], x2)
                call SetUnitY(cityBuilder[n], y2)
                call IssueBuildOrderById(cityBuilder[n], buildingType[i], x2, y2)
            endif
            set i = i + 1
        endloop 
    endif
    set u = null
endfunction

private function startBuilding takes nothing returns nothing
    local unit u = GetConstructingStructure()
    local integer id = GetUnitUserData(u)
    local integer city = selected[GetPlayerId(GetOwningPlayer(u))]
    set owningCity[id] = city 
    call GroupAddUnit(cityBuildings[city], u)
    call GroupAddUnit(cityBuildings[0], u)
    set cityBuildingCount[city][0] = cityBuildingCount[city][0] + 1
    call BJDebugMsg(I2S(cityBuildingCount[city][0]))
    set u = null
endfunction

private function finishBuilding takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer id = GetUnitUserData(u)
    local integer city = owningCity[id]
    local integer load = LoadInteger(hash, GetUnitTypeId(u), 0)
    set cityBuildingCount[city][0] = cityBuildingCount[city][0] - 1
    set cityBuildingCount[city][load] = cityBuildingCount[city][load] + 1
    call BJDebugMsg(I2S(cityBuildingCount[city][0]))
    call BJDebugMsg("Building " + I2S(load) + ": " + I2S(cityBuildingCount[city][load]))
    call GroupRemoveUnit(cityBuildings[0], u)
    set u = null
endfunction 

private function deathBuilding takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer id = GetUnitUserData(u)
    local integer city = owningCity[id]
    local integer load

    if IsUnitInGroup(u, cityBuildings[0]) == true then // This part don't work... 
        call GroupRemoveUnit(cityBuildings[0], u) 
        set cityBuildingCount[city][0] = cityBuildingCount[city][0] - 1
        call BJDebugMsg(I2S(cityBuildingCount[city][0]))
    else 
        set load = LoadInteger(hash, GetUnitTypeId(u), 0)
        set cityBuildingCount[city][load] = cityBuildingCount[city][load] - 1
        call BJDebugMsg(I2S(cityBuildingCount[city][load]))
    endif 
    set u = null 
endfunction 

private function main takes nothing returns boolean
    if GetTriggerEventId() == EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER then
        call buildOrder()
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_CONSTRUCT_START then 
        call startBuilding()
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_CONSTRUCT_FINISH then 
        call finishBuilding()
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_DEATH then 
        call deathBuilding()
    endif
    return false
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null)
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_CONSTRUCT_FINISH, null)
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_CONSTRUCT_START, null)
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
        set i = i + 1
    endloop
    
    call TriggerAddCondition(t, Condition(function main))
    
    // Barracks
    set buildingOrder[1] = String2OrderIdBJ("humanbarracks") 
    call SaveInteger(hash, 'hbar', 0, 1)
    set buildingType[1] = 'hbar'
    // Farm
    set buildingOrder[2] = String2OrderIdBJ("farm")
    call SaveInteger(hash, 'hhou', 0, 2)
    set buildingType[2] = 'hhou'
    // Granary
    set buildingOrder[3] = String2OrderIdBJ("gryphonaviary")
    call SaveInteger(hash, 'hgra', 0, 3)
    set buildingType[3] = 'hgra'
    // Well
    set buildingOrder[4] = String2OrderIdBJ("moonwell")
    call SaveInteger(hash, 'emow', 0, 4)
    set buildingType[4] = 'emow'
    
endfunction 

endlibrary

Why isn't the if-statement in the deathBuilding scope not working?
 
Last edited:
Level 15
Joined
Nov 30, 2007
Messages
1,202
As far as I know you can put it to any number as long as your RAM can handle id.

integer array i [99999999999999999] should technically work.

Okey, breaking Wc3 limit should be OK on any PC...

Could you take a look at this line aswell?

JASS:
    if IsUnitInGroup(u, cityBuildings[0]) == true then // This part don't work... 
        call GroupRemoveUnit(cityBuildings[0], u) 
        set cityBuildingCount[city][0] = cityBuildingCount[city][0] - 1
        call BJDebugMsg(I2S(cityBuildingCount[city][0]))
    else

Basicially cityBuildings[0] is a group for buildings currently under construction, perhaps i should create a seperate variable to make it more clear. And if a unit is in this group, the count of buildings currently under construction should decrease by one. But for some reason it doesnt pass the if-statement.
 
Status
Not open for further replies.
Top