(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Resources > JASS Functions

JASS Functions Approved JASS functions will be located here.
Remember to submit your own resources to the submission forum.

Reply
 
LinkBack Thread Tools Display Modes
Old 07-29-2008, 12:45 AM   #151 (permalink)
 
Herman's Avatar

Me in a few words???
 
Join Date: Aug 2007
Posts: 949

Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)


Quote:
Originally Posted by Troll-Brain View Post
The function main is the function generated by the world editor.
It's the function which is run the first and call all the others init.
Btw it can be custom easily with the jasshelper.

function main() -> InitBlizzard() ->InitMapRects()

function InitMapRects takes nothing returns nothing
    set bj_mapInitialPlayableArea = Rect(GetCameraBoundMinX()-GetCameraMargin(CAMERA_MARGIN_LEFT), GetCameraBoundMinY()-GetCameraMargin(CAMERA_MARGIN_BOTTOM), GetCameraBoundMaxX()+GetCameraMargin(CAMERA_MARGIN_RIGHT), GetCameraBoundMaxY()+GetCameraMargin(CAMERA_MARGIN_TOP))
    set bj_mapInitialCameraBounds = GetCurrentCameraBoundsMapRectBJ()
endfunction



For the smallest map possible, 32*32 :


So calculate yourself how many iterations your loop will do, it's pretty huge...
"Irritated" NOT MY CALCULATION "End"
__________________
77% of all people are neurotic
Herman is offline   Reply With Quote
Old 07-29-2008, 09:51 AM   #152 (permalink)

Anozer jasser
 
Join Date: Apr 2008
Posts: 237

Troll-Brain has little to show at this moment (13)Troll-Brain has little to show at this moment (13)


What ?
Troll-Brain is offline   Reply With Quote
Old 07-29-2008, 05:43 PM   #153 (permalink)
 
Herman's Avatar

Me in a few words???
 
Join Date: Aug 2007
Posts: 949

Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)


Quote:
Originally Posted by Troll-Brain View Post
What ?
You kept saying it was my function with my calculation...

I did not post either
__________________
77% of all people are neurotic
Herman is offline   Reply With Quote
Old 08-21-2008, 05:01 PM   #154 (permalink)
 
Ciebron's Avatar

I'm The Supervisor
 
Join Date: Apr 2008
Posts: 332

Ciebron has little to show at this moment (28)Ciebron has little to show at this moment (28)Ciebron has little to show at this moment (28)


This is a small dummy recycling system i made (took 10 min),its just a simple stack of units and very easy to use. any suggestions or idéa's are welcome :)

Dummy Recycling

library DummyRecycling initializer Init

globals
    private constant real WAIT_TIME = 1. //time to wait before "removing" a dummy
    private constant integer Dummy_id = 'hfoo' //dummy rawcode
    private constant integer ARRAY_SIZE = 20 //Max Number of Dummy's (u dont need so many)
    private unit array Dummys [ARRAY_SIZE]
    private integer Total = 0
    private integer Index = 0
endglobals

function CreateDummy takes player P, real x,real y returns unit
    if Total < ARRAY_SIZE then // if the stack isnt full we create or move a unit
        if Index >= Total then //if there no free units we create more
            set Dummys[Index] = CreateUnit(P,Dummy_id,x,y,0.)
            call UnitRemoveAbility(Dummys[Index],'Amov')
            set Total = Total + 1
            set Index = Index + 1
        else //else we move one
            call SetUnitX(Dummys[Index],x)
call SetUnitY(Dummys[Index],y)
            call SetUnitOwner(Dummys[Index],P,false)
            set Index = Index + 1
        endif
        return Dummys[Index-1]
    debug else
debug call BJDebugMsg("To many dummy's, increase the ARRAY_SIZE")
    endif

    return null
endfunction

function CreateDummyLoc takes player P, location loc returns nothing
    call CreateDummy(P,GetLocationX(loc),GetLocationY(loc))
    call RemoveLocation(loc)
    set loc = null
endfunction

function ReleaseDummy takes unit u returns nothing //this just change the owner of the dummy (maybe we should move them some where?)
    if GetUnitTypeId(u) == Dummy_id then
            call TriggerSleepAction(WAIT_TIME) //maybe use a timer instead?
            call SetUnitOwner(u,Player(15),false)
            set Index = Index - 1
        debug else
        debug call BJDebugMsg("function RemoveDummy: Unit given is not a Dummy Unit")
    endif
endfunction

private function Init takes nothing returns nothing
    set Dummys[Index] = CreateUnit(Player(15),Dummy_id,0.,0.,0.)
    call UnitRemoveAbility(Dummys[Index],'Amov')
    set Total = Total + 1
endfunction

endlibrary



e.g of usage

set Temp = CreateDummy(GetOwningPlayer(GetTriggerUnit(),0.,0.)
//dummy stuff
call ReleaseDummy(Temp)

well im in a rush so can't write more (ill get back later)
Ciebron is offline   Reply With Quote
Old 08-21-2008, 11:35 PM   #155 (permalink)
 
Herman's Avatar

Me in a few words???
 
Join Date: Aug 2007
Posts: 949

Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)


I don't really get why one would need a dummy recycling system, if you think about it, you only ever need the amount of units to be used when they are used, holding more just uses space, like a leak.

Unless it takes more memory to create unit than it does to run all of those functions to store an already created one, I really don't know, but I feel like the memory usage is from the presence of the unit, not its coming into usage.

EDIT - Something I just thought up, used for calling code without using TriggerEvaluate(), while avoiding constantly destroying the triggers you use

library CallCode
globals
    private trigger T = CreateTrigger()
    private conditionfunc C
    private boolean B
endglobals
function CallCode takes code c returns boolean
    set C = TriggerAddCondition(T, Condition(c))
    set B = TriggerEvaluate(T)
    call TriggerRemoveCondition(C)
    return B
endfunction
endlibrary
__________________
77% of all people are neurotic
Herman is offline   Reply With Quote
Old 08-22-2008, 03:15 PM   #156 (permalink)
 
Ciebron's Avatar

I'm The Supervisor
 
Join Date: Apr 2008
Posts: 332

Ciebron has little to show at this moment (28)Ciebron has little to show at this moment (28)Ciebron has little to show at this moment (28)


i can see no use for the function
Ciebron is offline   Reply With Quote
Old 08-23-2008, 04:44 AM   #157 (permalink)
 
ShaDowPoWeR's Avatar

Half human - Half Demon
 
Join Date: Nov 2007
Posts: 22

ShaDowPoWeR has little to show at this moment (1)


here is a little function, probably leaked because i am a noob but works ingame perfectly, removes a unit in a period of time like native UnitApplyTimedLife... this function's proper way to use is after death of an unit to clean it faster for example whenever death animation ends of an special effect dummie unit so you don't have to use buggy waits. (pause game doesn't affect waits)

Requieres handle vars


function RemoveUnitTimer takes nothing returns nothing
local timer T = GetExpiredTimer()
local unit U = GetHandleUnit(T, "u")
local real duration = GetHandleReal(T, "dur")
if duration > 0.05 then
call SetHandleReal(T,"dur", duration-0.05)
else
call RemoveUnit(U)
call FlushHandleLocals(T)
endif
endfunction
function AddRemoveUnitTimer takes unit U, real duration returns nothing
local timer T = CreateTimer()
call SetHandleReal(T,"dur", duration)
call SetHandleHandle(T,"u", U)
call TimerStart(T,0.05,true, function RemoveUnitTimer)
set T = null
endfunction
ShaDowPoWeR is offline   Reply With Quote
Old 08-24-2008, 07:37 PM   #158 (permalink)

User
 
Join Date: Mar 2005
Posts: 230

DiscipleOfLife is on a distinguished road (71)DiscipleOfLife is on a distinguished road (71)


If you create a locusted unit at (x, y), the unit will consider pathing (as if it didn't have locust) (EDIT: at the moment of its creation). This can be avoided by moving the unit with SetUnitX/Y right after.
__________________

Last edited by DiscipleOfLife; 08-25-2008 at 09:40 PM..
DiscipleOfLife is offline   Reply With Quote
Old 08-25-2008, 06:43 PM   #159 (permalink)
 
Herman's Avatar

Me in a few words???
 
Join Date: Aug 2007
Posts: 949

Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)


Oh, that sounds really good

Like, if you had a projectile that had locust, and then sent it on its path without using the X/Y, the locust would move all f*cked up when it got to a cliff or something, but if you first use the X/Y, then it will do it cleanly?

(I don't have war3 isntalled on this comp, but I would very very much appreciate somebody checking that for me)
__________________
77% of all people are neurotic
Herman is offline   Reply With Quote
Old 08-25-2008, 08:56 PM   #160 (permalink)

User
 
Join Date: Mar 2005
Posts: 230

DiscipleOfLife is on a distinguished road (71)DiscipleOfLife is on a distinguished road (71)


Quote:
Originally Posted by Herman View Post
Like, if you had a projectile that had locust, and then sent it on its path without using the X/Y, the locust would move all f*cked up when it got to a cliff or something, but if you first use the X/Y, then it will do it cleanly?
I tried to create a unit with locust at the position of a normal unit, but the locusted unit appeared on the side of it, not 'inside' it like it would if I had moved it there with SetUnitX/Y.

(forgot to mention in my earlier post that I was only talking about the moment of creation)
__________________

Last edited by DiscipleOfLife; 08-25-2008 at 09:41 PM..
DiscipleOfLife is offline   Reply With Quote
Old 08-26-2008, 05:29 PM   #161 (permalink)
 
Herman's Avatar

Me in a few words???
 
Join Date: Aug 2007
Posts: 949

Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)


But, if you use SetUnitX/Y, it will get 'inside it' ?
__________________
77% of all people are neurotic
Herman is offline   Reply With Quote
Old 08-26-2008, 06:28 PM   #162 (permalink)

User
 
Join Date: Mar 2005
Posts: 230

DiscipleOfLife is on a distinguished road (71)DiscipleOfLife is on a distinguished road (71)


Quote:
Originally Posted by Herman View Post
But, if you use SetUnitX/Y, it will get 'inside it' ?
Yep.
__________________
DiscipleOfLife is offline   Reply With Quote
Old 10-02-2008, 01:33 AM   #163 (permalink)
 
Dreadnought[dA]'s Avatar

Map Maker Fanatic
 
Join Date: Feb 2007
Posts: 298

Dreadnought[dA] has little to show at this moment (18)Dreadnought[dA] has little to show at this moment (18)


Deciseconds

scope GameClock
globals
private multiboarditem i
private integer c=0
endglobals

private function Deciseconds takes nothing returns string
if ModuloInteger(c,100)>9 then
    return I2S(ModuloInteger(c,100))
else
    return "0"+I2S(ModuloInteger(c,100))
endif
endfunction

private function Seconds takes nothing returns string
if ModuloInteger(c/100,60)>9 then
    return I2S(ModuloInteger(c/100,60))
else
    return "0"+I2S(ModuloInteger(c/100,60))
endif
endfunction

private function Minutes takes nothing returns string
if ModuloInteger(c/6000,60)>9 then
    return I2S(ModuloInteger(c/6000,60))
else
    return "0"+I2S(ModuloInteger(c/6000,60))
endif
endfunction

private function Hours takes nothing returns string
if c/360000>9 then
    return I2S(c/360000)
else
    return "0"+I2S(c/360000)
endif
endfunction

private function Timer takes nothing returns nothing
set c=c+1
call MultiboardSetItemValue(i,Hours()+":"+Minutes()+":"+Seconds()+":"+Deciseconds())
endfunction

private function Actions takes nothing returns nothing
local multiboard m=CreateMultiboard()
call MultiboardSetTitleText(m,"Game Clock")
call MultiboardSetTitleTextColor(m,100,100,255,0)
call MultiboardSetColumnCount(m,1)
call MultiboardSetRowCount(m,1)
call MultiboardDisplay(m,true)
set i=MultiboardGetItem(m,0,0)
call MultiboardSetItemWidth(i,.06)
call MultiboardSetItemValueColor(i,0,255,0,0)
call MultiboardSetItemStyle(i,true,false)
call TimerStart(CreateTimer(),0.01,true,function Timer)
call DestroyTrigger(GetTriggeringTrigger())
set m=null
endfunction
//===========================================================================
function InitTrig_GameClock takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterTimerEvent(t,0,false)
call TriggerAddAction(t,function Actions)
set t=null
endfunction
endscope



Seconds

scope GameClock

globals
private multiboarditem i
private integer c=0
endglobals

private function Seconds takes nothing returns string
if ModuloInteger(c,60)>9 then
    return I2S(ModuloInteger(c,60))
else
    return "0"+I2S(ModuloInteger(c,60))
endif
endfunction

private function Minutes takes nothing returns string
if ModuloInteger(c/60,60)>9 then
    return I2S(ModuloInteger(c/60,60))
else
    return "0"+I2S(ModuloInteger(c/60,60))
endif
endfunction

private function Hours takes nothing returns string
if c/3600>9 then
    return I2S(c/3600)
else
    return "0"+I2S(c/3600)
endif
endfunction

private function Timer takes nothing returns nothing
set c=c+1
call MultiboardSetItemValue(i,Hours()+":"+Minutes()+":"+Seconds())
endfunction

private function Actions takes nothing returns nothing
local multiboard m=CreateMultiboard()
call MultiboardSetTitleText(m,"Game Clock")
call MultiboardSetTitleTextColor(m,100,100,255,0)
call MultiboardSetColumnCount(m,1)
call MultiboardSetRowCount(m,1)
call MultiboardDisplay(m,true)
set i=MultiboardGetItem(m,0,0)
call MultiboardSetItemWidth(i,.06)
call MultiboardSetItemValueColor(i,0,255,0,0)
call MultiboardSetItemStyle(i,true,false)
call TimerStart(CreateTimer(),1,true,function Timer)
call DestroyTrigger(GetTriggeringTrigger())
set m=null
endfunction
//===========================================================================
function InitTrig_GameClock takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterTimerEvent(t,0,false)
call TriggerAddAction(t,function Actions)
set t=null
endfunction

endscope



I improved upon my old timer. Hopefully you like this one.
__________________
Dreadnought[dA] is offline   Reply With Quote
Old 10-20-2008, 12:38 PM   #164 (permalink)
 
Herman's Avatar

Me in a few words???
 
Join Date: Aug 2007
Posts: 949

Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)


Errr, when would you need to check just one integer variable?

I think as a concept this is ok, but as code to be used, this isn't too useful as a debugging tool unless you could specify the array being checked, converting it to a textmacro may be helpful
__________________
77% of all people are neurotic
Herman is offline   Reply With Quote
Old 10-21-2008, 11:35 PM   #165 (permalink)
 
Herman's Avatar

Me in a few words???
 
Join Date: Aug 2007
Posts: 949

Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)Herman has little to show at this moment (40)


If its buggy shit why would you post it?
__________________
77% of all people are neurotic
Herman is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On