- Joined
- Mar 3, 2006
- Messages
- 1,564
P.S. I am going to sleep. It's 2:10 am over here... I'll let someone else help you.
Sweet Dreams

P.S. I am going to sleep. It's 2:10 am over here... I'll let someone else help you.
SetUnitPosition also considers pathing - you should use SetUnitX/Y, as these functions do not.
Does that means that I will need two variables; one for X and another for Y instead of just one variable, which is stepPoint in my case ?SetUnitPosition(x, y) will make the unit jump to the point nearest where you want it to go that it is able to stand on. SetUnitX(x) / SetUnitY(y) will definitely put the unit exactly where you say, even if it shouldn't be able to stand there normally.
Just work the damn thing out yourself. We don't need to guide you through step-by-step! You can't learn if you don't try.
They'll give you hints you don't understand. You'll come back here and require more assistance, which results in more and more hints until they write your entire script for you. And you still won't understand it.
When it comes to stuff like programming, there is no "easy way". You have to learn by doing. Besides, it can be quite rewarding when you finally get something to work that you made all by yourself. You have to be willing to experiment and get your hands dirty to figure out how things work.
scope AoETemplate initializer Init
private keyword Data
globals
private constant real TIMER_INTERVAL = 0.03
private constant real DIST = 32
private constant integer NOVA_SIZE = 36 // number of the Nova Units
private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
endglobals
private struct Data
unit caster
unit array Nova[NOVA_SIZE]
player Owner
real cx
real cy
static method NovaStart takes unit caster, location centre returns nothing
local Data dat = Data.allocate()
local integer i = 0
local real A = 0
local real dA = 360. / NOVA_SIZE
local real dr = 0
set dat.caster = caster
set dat.Owner = GetOwningPlayer(dat.caster)
set dat.cx = GetLocationX(centre)
set dat.cy = GetLocationY(centre)
loop
exitwhen i == NOVA_SIZE
set dat.Nova[i] = CreateUnit(Player(0),UNIT_ID,dat.cx,dat.cy,A)
set A = A + dA
set i = i + 1
endloop
endmethod
static method NovaExpand takes nothing returns nothing
endmethod
endstruct
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == ABIL_ID
endfunction
private function Actions takes nothing returns nothing
call Data.NovaStart(GetTriggerUnit(), GetSpellTargetLoc())
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition(t,Condition(function Conditions))
call TriggerAddAction(t,function Actions)
endfunction
endscope
scope AoETemplate initializer Init
private keyword Data
globals
private constant real TIMER_INTERVAL = 0.03
private constant real DIST = 32.00
private constant real NOVA_RADIUS = 288.00 // radius of the Nova
private constant integer NOVA_SIZE = 36 // number of the Nova Units
private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
endglobals
private struct Data
unit caster
unit array Nova[NOVA_SIZE]
player owner
real cx
real cy
static method NovaStart takes unit caster, location centre returns nothing
local Data dat = Data.allocate()
local integer i = 0
local real A = 0.00
local real dA = 360.00 / NOVA_SIZE
local real dr = 0
set dat.caster = caster
set dat.owner = GetOwningPlayer(dat.caster)
set dat.cx = GetLocationX(centre)
set dat.cy = GetLocationY(centre)
loop
exitwhen i == NOVA_SIZE
set dat.Nova[i] = CreateUnit(dat.owner,UNIT_ID,dat.cx,dat.cy,A)
set A = A + dA
set i = i + 1
endloop
endmethod
static method NovaExpand takes nothing returns nothing
local Data dat
local integer index = 0
local real r
local real rmax = NOVA_RADIUS
local real array nux[NOVA_SIZE]
local real array nuy[NOVA_SIZE]
// nova expanding
loop
exitwhen r == rmax
call SetUnitX(dat.Nova[index],nux[index])
call SetUnitY(dat.Nova[index],nuy[index])
set index = index + 1
endloop
// nova damage
endmethod
endstruct
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == ABIL_ID
endfunction
private function Actions takes nothing returns nothing
call Data.NovaStart(GetTriggerUnit(), GetUnitLoc(GetTriggerUnit()))
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function Conditions))
call TriggerAddAction(t,function Actions)
endfunction
endscope
scope AoETemplate initializer Init
private keyword Data
globals
private constant real TIMER_INTERVAL = 0.5
private constant real DIST = 32.00
private constant real NOVA_RADIUS = 512.00 // radius of the Nova
private constant integer NOVA_SIZE = 9 // number of the Nova Units
private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
private timer tm
endglobals
private struct Data
unit caster
unit array Nova[NOVA_SIZE]
player owner
real cx
real cy
static method NovaExpand takes nothing returns nothing
local Data dat = Data.allocate()
local integer i2 = 0
local real r = 0
local real dr = DIST
local real rmax = NOVA_RADIUS
local real array nux
local real array nuy
local real A = 0.00
local real dA = 360.00 / NOVA_SIZE
// nova expanding
loop
exitwhen i2 == NOVA_SIZE
set nux[i2] = dat.cx + r * Cos(A * bj_DEGTORAD)
set nuy[i2] = dat.cy + r * Sin(A * bj_DEGTORAD)
call SetUnitX(dat.Nova[i2],nux[i2])
call SetUnitY(dat.Nova[i2],nux[i2])
set r = r + dr
set A = A + dA
set i2 = i2 + 1
endloop
// nova damage
endmethod
static method NovaStart takes unit caster, location centre returns nothing
local Data dat = Data.allocate()
local integer i = 0
local real A = 0.00
local real dA = 360.00 / NOVA_SIZE
set dat.caster = caster
set dat.owner = GetOwningPlayer(dat.caster)
set dat.cx = GetLocationX(centre)
set dat.cy = GetLocationY(centre)
loop
exitwhen i == NOVA_SIZE
set dat.Nova[i] = CreateUnit(dat.owner,UNIT_ID,dat.cx,dat.cy,A)
set A = A + dA
set i = i + 1
endloop
call TimerStart(tm,TIMER_INTERVAL,true,function Data.NovaExpand)
endmethod
endstruct
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == ABIL_ID
endfunction
private function Actions takes nothing returns nothing
call Data.NovaStart(GetTriggerUnit(), GetUnitLoc(GetTriggerUnit()))
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function Conditions))
call TriggerAddAction(t,function Actions)
set tm = CreateTimer()
endfunction
endscope
struct Str
unit U
location P
real R
real A
method takes m1 takes unit u, location p, real r, real a returns Str
local Str S = Str.allocate()
set S.U = u
set S.P = p
set S.R = r
set S.A = a
return S
endmethod
method m2 takes nothing returns nothing
local Str S = Str.allocate
local unit UNIT = S.U
local location LOC = S.P
local real RADIUS = S.R
local real ANGLE = S.A
endmethod
endstruct
What is the value of S when I say return S?
No. Str.allocate() allocates new memory for U,P,R,A variables. When you use Str.allocate(), the variables themselves aren't initialized yet.will the values of m2 local variables be the same as in m1 ?
That means that in order to transfer the value of m1 to m2 I will need another variable of Str type but it must be global in that case. Right or Wrong ?A unique value between 1 and 8190 (can be higher if you explicitly need more). Each struct you create corresponds with such a value. When a struct variable is destroyed, the index is available again. For example:
set s = Str.create() // s is 1
set s = Str.create() // s is 2
set d = Str.create() // d is 3
call s.destroy() // the index "2" is available again
set d = Str.create() // d is 2
Note that there are 2 leaks here, since we never destroy the first S we created and the first d we created. Thus, indices 1 and 3 are still in use and cannot be recycled.
No. Str.allocate() allocates new memory for U,P,R,A variables. When you use Str.allocate(), the variables themselves aren't initialized yet.
Thus, in m2 when you use Str.allocate(), U,P,R,A are still uninitialized. And thus UNIT, LOC, RADIUS and ANGLE too will be uninitialized because S.U, S.P, S.R, S.A don't have a value yet.
In m1, you allocate new memory for your U, P, R, A variables, and you change their values to u, p, r, a.
scope AoETemplate initializer Init
private keyword Data
globals
private constant real TIMER_INTERVAL = 0.02
private constant real DIST = 32.00
private constant real NOVA_RADIUS = 512.00 // radius of the Nova
private constant integer NOVA_SIZE = 64 // number of the Nova Units
private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
private timer tm
private Data array temp_dat
private integer index = 0
endglobals
private struct Data
unit caster
unit array Nova[NOVA_SIZE]
player owner
static real cx // cx: Centre X
static real cy // cy: Centre Y
static real r = 32.00 // current radius of the nova. initial value = 32.00
static real dr = DIST // radius increment
static real array nux[NOVA_SIZE] // nux: Nova Unit X
static real array nuy[NOVA_SIZE] // nuy: Nova Unit Y
static method NovaExpand takes nothing returns nothing
local Data dat
local integer i = 0
local real rmax = NOVA_RADIUS
local real A = 0
local real dA = 360.00 / NOVA_SIZE
// nova expanding
loop
exitwhen i >= NOVA_SIZE
set dat = temp_dat[i]
set dat.nux[i] = Data.cx + Data.r * Cos( A * bj_DEGTORAD )
set dat.nuy[i] = Data.cy + Data.r * Sin( A * bj_DEGTORAD )
call SetUnitX( dat.Nova[i] , Data.nux[i] )
call SetUnitY( dat.Nova[i] , Data.nuy[i] )
set i = i + 1
set A = A + dA
endloop
if Data.r >= rmax then
call dat.destroy()
endif
set Data.r = Data.r + Data.dr
endmethod
static method NovaCreate takes unit caster, location centre returns Data
local Data dat = Data.allocate()
local integer i = 0
local real A = 0.00
local real dA = 360.00 / NOVA_SIZE
set dat.caster = caster
set dat.owner = GetOwningPlayer(dat.caster)
set Data.cx = GetLocationX(centre)
set Data.cy = GetLocationY(centre)
loop
exitwhen i >= NOVA_SIZE
set dat.Nova[i] = CreateUnit( dat.owner , UNIT_ID , dat.cx , dat.cy , A )
set A = A + dA
set i = i + 1
endloop
if index == 0 then
call TimerStart(tm,TIMER_INTERVAL,true,function Data.NovaExpand)
endif
set temp_dat[index] = dat
set index = index + 1
return dat
endmethod
method onDestroy takes nothing returns nothing
local integer i = 0
call PauseTimer(tm)
loop
exitwhen i >= NOVA_SIZE
call KillUnit(.Nova[i])
set .Nova[i] = null
set i = i + 1
endloop
set index = index - 1
endmethod
endstruct
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == ABIL_ID
endfunction
private function Actions takes nothing returns nothing
call Data.NovaCreate(GetTriggerUnit(), GetUnitLoc(GetTriggerUnit()))
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function Conditions))
call TriggerAddAction(t,function Actions)
set tm = CreateTimer()
endfunction
endscope
struct Parent
stub method sayHello takes nothing returns nothing
call BJDebugMsg("Hello from the parent!")
endmethod
endstruct
struct Child extends Parent // see: extend
stub method sayHello takes nothing returns nothing // See: sayHello is already defined by the parent struct. This is not allowed, except when the method is a stub method.
call BJDebugMsg("Hello from the child!")
endmethod
endstruct
struct Grandchild extends Child
stub method sayHello takes nothing returns nothing
call super.sayHello() // super refers to the original struct, i.e. "Parent".
endmethod
endstruct
struct Child2 extends Parent
// We don't HAVE to redefine sayHello
endstruct
// In your code:
local Parent p = Parent.create()
local Parent c = Child.create() // Note: this is of local type "Parent", but it IS in fact a Child.
local Parent g = GrandChild.create()
local Child2 c2 = Child2.create()
call p.sayHello() // displays: "Hello from the parent!"
call c.sayHello() // displays: "Hello from the child!"
call g.sayHello() // displays: "Hello from the parent!" --> because g calls super.sayHello()
call c2.sayHello() // displays: "Hello from the parent!" --> because Child2 did not redefine sayHello, it simply uses sayHello that was already defined by Parent.
struct Test
private real x
private real y
unit u
method operator x= takes real x returns nothing
call SetUnitX(.u, x)
set .x = x
endmethod
method operator x takes nothing returns real
return .x
endmethod
method operator y= takes real y returns nothing
call SetUnitY(.u, y)
set .y = y
endmethod
method operator y takes nothing returns real
return .y
endmethod
endstruct
Actually, it displays: "Hello from the child!" (I tested it). super actually gives you the struct that this struct extends from. Since GrandChild extends Child, it calls Child.sayHello().// In your code:
local Parent g = GrandChild.create()
call g.sayHello() // displays: "Hello from the parent!" --> because g calls super.sayHello()[/code]
library Table
//***************************************************************
//* Table object 3.0
//* ------------
//*
//* set t=Table.create() - instanceates a new table object
//* call t.destroy() - destroys it
//* t[1234567] - Get value for key 1234567
//* (zero if not assigned previously)
//* set t[12341]=32 - Assigning it.
//* call t.flush(12341) - Flushes the stored value, so it
//* doesn't use any more memory
//* t.exists(32) - Was key 32 assigned? Notice
//* that flush() unassigns values.
//* call t.reset() - Flushes the whole contents of the
//* Table.
//*
//* call t.destroy() - Does reset() and also recycles the id.
//*
//* If you use HandleTable instead of Table, it is the same
//* but it uses handles as keys, the same with StringTable.
//*
//* You can use Table on structs' onInit if the struct is
//* placed in a library that requires Table or outside a library.
//*
//* You can also do 2D array syntax if you want to touch
//* mission keys directly, however, since this is shared space
//* you may want to prefix your mission keys accordingly:
//*
//* set Table["thisstring"][ 7 ] = 2
//* set Table["thisstring"][ 5 ] = Table["thisstring"][7]
//*
//***************************************************************
//=============================================================
globals
private constant integer MAX_INSTANCES=8100 //400000
//Feel free to change max instances if necessary, it will only affect allocation
//speed which shouldn't matter that much.
//=========================================================
private hashtable ht
endglobals
private struct GTable[MAX_INSTANCES]
method reset takes nothing returns nothing
call FlushChildHashtable(ht, integer(this) )
endmethod
private method onDestroy takes nothing returns nothing
call this.reset()
endmethod
//=============================================================
// initialize it all.
//
private static method onInit takes nothing returns nothing
set ht = InitHashtable()
endmethod
endstruct
//Hey: Don't instanciate other people's textmacros that you are not supposed to, thanks.
//! textmacro Table__make takes name, type, key
struct $name$ extends GTable
method operator [] takes $type$ key returns integer
return LoadInteger(ht, integer(this), $key$)
endmethod
method operator []= takes $type$ key, integer value returns nothing
call SaveInteger(ht, integer(this) ,$key$, value)
endmethod
method flush takes $type$ key returns nothing
call RemoveSavedInteger(ht, integer(this), $key$)
endmethod
method exists takes $type$ key returns boolean
return HaveSavedInteger( ht, integer(this) ,$key$)
endmethod
static method flush2D takes string firstkey returns nothing
call $name$(- StringHash(firstkey)).reset()
endmethod
static method operator [] takes string firstkey returns $name$
return $name$(- StringHash(firstkey) )
endmethod
endstruct
//! endtextmacro
//! runtextmacro Table__make("Table","integer","key" )
//! runtextmacro Table__make("StringTable","string", "StringHash(key)" )
//! runtextmacro Table__make("HandleTable","handle","GetHandleId(key)" )
endlibrary
local Table intTable = Table.create()
set intTable[20] = 5
call intTable.setIndex(20, 5)
intTable[20]
intTable.getIndex(20)
.Table["category1"]
. Used by itself, this static method operator is useless. However, since it returns a struct instance, we can use it in combination with the regular method operators. For example,set Table["category1"][0] = 4
struct operatortest
string str=""
method operator [] takes integer i returns string
return SubString(.str,i,i+1)
endmethod
method operator[]= takes integer i, string ch returns nothing
set .str=SubString(.str,0,i)+ch+SubString(.str,i+1,StringLength(.str)-i)
endmethod
endstruct
function test takes nothing returns nothing
local operatortest x=operatortest.create()
set x.str="Test"
call BJDebugMsg( x[1])
call BJDebugMsg( x[0]+x[3])
set x[1] = "."
call BJDebugMsg( x.str)
endfunction
call BJDebugMsg(x[1])
call BJDebugMsg(x[0] + x[3])
struct Test
private real fx
method getX takes nothing returns real
return this.fx
endmethod
method operator x takes nothing returns real
return this.fx
endmethod
endstruct
// in a function:
local Test s = Test.create()
local real x = s.getX() // notice the ()
local real y = s.x // notice no () are used.
set s.x = 5 // NOT ALLOWED. s.x is an operator, NOT a variable, therefor you cannot assign a new value to it.
So Whats wrong with what I said in post #226 ?
function SubStringBJ takes string source, integer start, integer end returns string
return SubString(source, start-1, end)
endfunction
Tracking of triggers and functions???
You can't learn by doing that. You just correct stuff.
//! textmacro TextMacroName takes DISPTEXT
function Message$DISPTEXT$ takes nothing returns nothing
Call DisplayTimedTextToPlayer(Player(0),0,0,10,"$DISPTEXT$ Test" )
endfunction
//! endtextmacro
function exe takes nothing returns nothing
//! runtextmacro TextMacroName("Integer")
//! runtextmacro TextMacroName("Real")
//! runtextmacro TextMacroName("Unit")
endfunction
function InitTrig_text_macro takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterPlayerChatEvent(t,Player(0),"tm",false)
call TriggerAddAction(t, function exe )
endfunction
I never used textmacros but i just read a tutorial about it.
I think this will work:
EDIT: You must just change "Integer" into Integer
//! textmacro blabla
//! endtextmacro
//! runtextmacro blabla
, and the parameters are being replaced.function exe takes nothing returns nothing
function MessageInteger takes nothing returns nothing
call DisplayTimedTextToPlayer(Player(0),0,0,10,"Integer Test" )
endfunction
function MessageReal takes nothing returns nothing
call DisplayTimedTextToPlayer(Player(0),0,0,10,"Real Test" )
endfunction
function MessageUnit takes nothing returns nothing
call DisplayTimedTextToPlayer(Player(0),0,0,10,"Unit Test" )
endfunction
endfunction
function InitTrig_text_macro takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterPlayerChatEvent(t,Player(0),"tm",false)
call TriggerAddAction(t, function exe )
endfunction
//! textmacro TextMacroName takes DISPTEXT
call DisplayTimedTextToPlayer(Player(0),0,0,10,"$DISPTEXT$ Test" )
//! endtextmacro
function exe takes nothing returns nothing
//! runtextmacro TextMacroName("Integer")
//! runtextmacro TextMacroName("Real")
//! runtextmacro TextMacroName("Unit")
endfunction
function InitTrig_text_macro takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterPlayerChatEvent(t,Player(0),"tm",false)
call TriggerAddAction(t, function exe )
endfunction
This is so true. i was stumped and thought a function was the same as a trigger.Posted by Silvenon
Yeah. People who work in GUI have a different concept of a trigger. They think that a trigger is something that in fact is some kind of a "folder" where you can have multiple triggers.