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

Some Jass and Hash problems

Status
Not open for further replies.
i have some problems with a jass system and a hash revive sys

1) Jass Unit Collision sys
The Problem:
I use it in a 0.03 loop (missle system) and it lag heaviely (after a secound launch of a missle wc3 has 0 fps.
The Code:
JASS:
function AddUnitCollision takes integer uID, real rad returns nothing
    set udg_UC_Number                    = udg_UC_Number + 1
    set udg_UC_Type[udg_UC_Number]       = uID
    set udg_UC_UnitRadius[udg_UC_Number] = rad
    if rad > udg_UC_MaxCollisionsSize then
        set udg_UC_MaxCollisionsSize =rad+1
    endif
endfunction

function UnitCollisionInit takes nothing returns nothing
    call AddUnitCollision('h004',110)
    call AddUnitCollision('h001', 60)
    call AddUnitCollision('h002', 65)
    call AddUnitCollision('h005', 60)
    call AddUnitCollision('h007', 80)
endfunction

function GetUnitCollSize takes unit u returns real
    local integer i= 1
    loop
        exitwhen i >= udg_UC_Number
        if GetUnitTypeId(u) == udg_UC_Type[i] then
            set u=null
            return udg_UC_UnitRadius[i]
        endif
        set i= i+1
    endloop
    set u=null
    return 0.
endfunction

function CheckForCollision takes location loc, real z, player p, real CollSize returns boolean
    local group      g = GetUnitsInRangeOfLocMatching(udg_UC_MaxCollisionsSize,loc,null)
    local unit       u
    local real array r
    local boolean    b = false
    loop
        set u =FirstOfGroup(g)
        exitwhen u ==null or b ==true
        if GetOwningPlayer(u) != p then
            set r[0] = GetLocationX(loc) - GetUnitX(u)
            set r[1] = GetLocationY(loc) - GetUnitY(u)
            set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
            set r[3] = GetUnitFlyHeight(u)-z
            set r[4] = SquareRoot(r[2] * r[2] + r[3] * r[3])
            if r[4] <= (GetUnitCollSize(u)-CollSize) then
                call DestroyGroup(g)
                call RemoveLocation(loc)
                set loc=null
                set p  =null
                set g  =null
                set u  =null
                return true
            endif
        endif
    endloop
    call DestroyGroup(g)
    call RemoveLocation(loc)
    set loc=null
    set p  =null
    set g  =null
    set u  =null
    return false
endfunction
and a trigger that call the init

2) Revive with Hash
The Problem:
the unit doesn't spawn.
The Code:
Init:
  • Hash init
    • Ereignisse
      • Map initialization
    • Bedingungen
    • Aktionen
      • Set CR_TimeBeforRevive = 10.00
      • -------- ====================== --------
      • Hashtabelle - Create a hashtable
      • Set CR_Hash = (Last created hashtable)
      • -------- ====================== --------
      • Set CR_Enemys = Spieler 2 (Blau)
      • -------- ====================== --------
      • Custom script: set bj_wantDestroyGroup = true
      • Einheitengruppe - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Schleifen - Aktionen
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • 'IF'-Bedingungen
              • (Owner of (Picked unit)) Gleich CR_Enemys
            • 'THEN'-Aktionen
              • Einheitengruppe - Add (Picked unit) to CR_ReviveAbleGroup
              • Set CR_LeakPoint = (Position of (Picked unit))
              • Hashtabelle - Save Handle OfCR_LeakPoint as 0 of (Key (Picked unit)) in CR_Hash
              • Hashtabelle - Save (Facing of (Picked unit)) as 1 of (Key (Picked unit)) in CR_Hash
              • Custom script: call RemoveLocation(udg_CR_LeakPoint)
            • 'ELSE'-Aktionen
The Revive Trigger:
  • Hash revive
    • Ereignisse
      • Einheit - A unit Stirbt
    • Bedingungen
      • ((Triggering unit) is in CR_ReviveAbleGroup) Gleich True
    • Aktionen
      • Custom script: local location p = LoadLocationHandleBJ(0, GetHandleIdBJ(GetTriggerUnit()), udg_CR_Hash)
      • Custom script: local real f = LoadRealBJ(1, GetHandleIdBJ(GetTriggerUnit()), udg_CR_Hash)
      • Custom script: local integer ID = GetUnitTypeId(GetTriggerUnit())
      • Spiel - Display to (All players) the text: locals created
      • -------- ----------------------------------------------------------------- --------
      • Custom script: call TriggerSleepAction( udg_CR_TimeBeforRevive )
      • -------- ----------------------------------------------------------------- --------
      • Custom script: call CreateUnitAtLoc(udg_CR_Enemys,ID,p,f)
      • Custom script: call GroupAddUnitSimple( GetLastCreatedUnit(), udg_CR_ReviveAbleGroup )
      • Spiel - Display to (All players) the text: create new unit
      • -------- ----------------------------------------------------------------- --------
      • Custom script: call SaveLocationHandleBJ( p, 0, GetHandleIdBJ(GetLastCreatedUnit()), udg_CR_Hash )
      • Custom script: call SaveRealBJ( f, 1, GetHandleIdBJ(GetLastCreatedUnit()), udg_CR_Hash )
      • Spiel - Display to (All players) the text: save hash
      • -------- ----------------------------------------------------------------- --------
      • Custom script: call RemoveLocation (p)
      • Custom script: set p = null
plz can someone help me
 
Level 9
Joined
Aug 27, 2009
Messages
473
I dont know Jass / vJass, either Hashtables.. But why use hashtables?..

You can get X and Y of unit and facing angle of unit, then create a new unit after respawn time and save his values too..

I will recommand to use "Unit - Custom Value" for some of the thing..
Here is a good Tutorial: http://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/creep-respawn-gui-65987/, but instead of "Creep Point" use CreepX and CreepY variables.. :) Thats leakless.
 
Level 9
Joined
Aug 27, 2009
Messages
473
O.,o

Dubble post, anyway. The "Respawn Sys" looks realy wierd.. I can make it with 4 variables and 2 triggers. And if im lucky, just 10 actions.. This is messy and uneffective, you use Hashtables wrong.. They are supose to save values that almost are impossible to store in other ways, here you just use hashtables... Just for using it.. I will "Highly Recommand" you to use CreepX and CreepY, and stuff like that...
I can make a short Trigger to show you, if you want to...
 
sry for doubble post

ok here is the new Unit Collision sys: (same bug; it look like that the system never returns something)
JASS:
function AddUnitCollision takes integer uID, real rad returns nothing
    set udg_UC_Number                    = udg_UC_Number + 1
    set udg_UC_Type[udg_UC_Number]       = uID
    set udg_UC_UnitRadius[udg_UC_Number] = rad
    if rad > udg_UC_MaxCollisionsSize then
        set udg_UC_MaxCollisionsSize =rad+1
    endif
endfunction

function UnitCollisionInit takes nothing returns nothing
    call AddUnitCollision('h004',110)
    call AddUnitCollision('h001', 60)
    call AddUnitCollision('h002', 65)
    call AddUnitCollision('h005', 60)
    call AddUnitCollision('h007', 80)
endfunction

function GetUnitCollSize takes unit u returns real
    local integer i= 1
    loop
        exitwhen i >= udg_UC_Number
        if GetUnitTypeId(u) == udg_UC_Type[i] then
            set u=null
            return udg_UC_UnitRadius[i]
        endif
        set i= i+1
    endloop
    set u=null
    return 0.
endfunction

function CheckForCollision takes location loc, real z, player p, real CollSize returns boolean
    local group      g = CreateGroup()
    local unit       u = null
    local real array r
    local boolean    b = false
    set              g = GetUnitsInRangeOfLocMatching(udg_UC_MaxCollisionsSize+CollSize,loc,null)
    loop
        set u =FirstOfGroup(g)
        exitwhen u ==null or b ==true
        if GetOwningPlayer(u) != p then
            set r[0] = GetLocationX(loc) - GetUnitX(u)
            set r[1] = GetLocationY(loc) - GetUnitY(u)
            set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
            set r[3] = GetUnitFlyHeight(u)-z
            set r[4] = SquareRoot(r[2] * r[2] + r[3] * r[3])
            if r[4] <= (GetUnitCollSize(u)-CollSize) then
                call DestroyGroup(g)
                call RemoveLocation(loc)
                set loc=null
                set p  =null
                set g  =null
                set u  =null
                return true
            endif
            call GroupRemoveUnit(g,u)
            set u = null
        endif
    endloop
    call DestroyGroup(g)
    call RemoveLocation(loc)
    set loc=null
    set p  =null
    set g  =null
    set u  =null
    return false
endfunction

EDIT:
udg_UC_Number is an Integer
udg_UC_Type is an UnitType
udg_UC_UnitRadius is a Real
udg_UC_MaxCollisionsSize is a Real
 
The error is that you do not delete the unit from the group if the condition is false.
JASS:
   if GetOwningPlayer(u) != p then
            //Other stuff
            call GroupRemoveUnit(g,u)
            set u = null
   endif
You have to put it outside the conditon.

I've pimped your function a bit, here we go:

JASS:
function CheckForCollision takes real x, real y, real z, player p, real CollSize returns boolean
    local group			g = CreateGroup()
    local unit			u = null
    local real	array	r
    local boolean		b = false

    call GroupEnumUnitsInRange(g, x, y, udg_UC_MaxCollisionsSize + CollSize, null)
    
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null or b == true
        if GetOwningPlayer(u) != p then
            set r[0] = x - GetUnitX(u)
            set r[1] = y - GetUnitY(u)
            set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
            set r[3] = GetUnitFlyHeight(u)-z
            set r[4] = SquareRoot(r[2] * r[2] + r[3] * r[3])
            set b = (r[4] <= (GetUnitCollSize(u)-CollSize))
        endif
        
        call GroupRemoveUnit(g,u)
        set u = null
    endloop
    
    call DestroyGroup(g)
    set p 	= null
    set g 	= null
    set u 	= null
    return b
endfunction
 
thx a lot and +rep
(you forgot to remove the location)
EDIT:
your function have some errors
Edit2:
I have fixed some things but this error is still alive ^^:
local group g= GroupEnumUnitsInRange(x , y , udg_UC_MaxCollisionsSize + CollSize , null)
Cannot convert real to group
cannot convert null to real
not enought arguments passed to function
cannot convert nothing to group
New function:
JASS:
function CheckForCollision takes real x, real y, real z, player p, real CollSize returns boolean
    local group 		g = GroupEnumUnitsInRange(x, y, udg_UC_MaxCollisionsSize + CollSize, null)
    local unit 			u = null
    local real array 	r    
    local boolean 		b = false    
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null or b == true
        if GetOwningPlayer(u) != p then
            set r[0] = x - GetUnitX(u)
            set r[1] = y - GetUnitY(u)
            set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
            set r[3] = GetUnitFlyHeight(u)-z
            set r[4] = SquareRoot(r[2] * r[2] + r[3] * r[3])
            if r[4] <= (GetUnitCollSize(u)-CollSize) then
                set b = true
            endif
        endif
        call GroupRemoveUnit(g,u)
        set u = null
    endloop
    call DestroyGroup(g)
    set p 	= null 
    set g 	= null 
    set u 	= null
    return b
endfunction
 
Code
JASS:
function CheckForCollision takes real x, real y, real z, player p, real CollSize returns boolean
    local group			g = CreateGroup()
    local unit			u = null
    local real	array	r
    local boolean		b = false
    set g = GroupEnumUnitsInRange(x, y, udg_UC_MaxCollisionsSize + CollSize, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null or b == true
        if GetOwningPlayer(u) != p then
            set r[0] = x - GetUnitX(u)
            set r[1] = y - GetUnitY(u)
            set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
            set r[3] = GetUnitFlyHeight(u)-z
            set r[4] = SquareRoot(r[2] * r[2] + r[3] * r[3])
            set b = (r[4] <= (GetUnitCollSize(u)-CollSize))
        endif
        call GroupRemoveUnit(g,u)
        set u = null
    endloop
    call DestroyGroup(g)
    set p 	= null
    set g 	= null
    set u 	= null
    return b
    endfunction
does not change anything
 
Use this:

JASS:
function CheckForCollision takes real x, real y, real z, player p, real CollSize returns boolean
    local group g = CreateGroup()
    local unit u = null
    local real array r
    local boolean b = false

    call GroupEnumUnitsInRange(g, x, y, udg_UC_MaxCollisionsSize + CollSize, null)

    loop
        set u = FirstOfGroup(g)
        exitwhen u == null or b == true
        if GetOwningPlayer(u) != p then
            set r[0] = x - GetUnitX(u)
            set r[1] = y - GetUnitY(u)
            set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
            set r[3] = GetUnitFlyHeight(u)-z
            set r[4] = SquareRoot(r[2] * r[2] + r[3] * r[3])
            set b = (r[4] <= (GetUnitCollSize(u)-CollSize))
        endif

        call GroupRemoveUnit(g,u)
        set u = null
    endloop

    call DestroyGroup(g)
    set p = null
    set g = null
    set u = null
    return b
endfunction

I am always editing this post.
 
Maybe because this:

JASS:
    local integer i= 1
    loop
        exitwhen i >= udg_UC_Number
        if GetUnitTypeId(u) == udg_UC_Type[i] then
            set u=null
            return udg_UC_UnitRadius[i]
        endif
        set i= i+1
    endloop
    set u=null
    return 0.
Always returns 0.?

Also the loop is kinda bad, use tables instead.

this only returns 0 if the unit type is not added.

you mean i should use anoter hash to store the coll sitze to each unit?
 
Status
Not open for further replies.
Top