Template Projectile Template!

Flare

Stops copies me!
Reaction score
662
I can't see why it isn't MUI (judging by the code, haven't tested ingame yet).

Also, is the code in first post the latest? If so, you still haven't destroyed your triggers and timer

And you aren't using the ClearTriggerStruct and ClearTimerStruct from what I can see. Get it fixed :)

And fix all those locations. You only need to use one location in that trigger, and extra ones are just making more work (since you have to clear the location and then null it, whereas coordinates don't need clearing/nulling)
 

Vestras

Retired
Reaction score
248
I can't see why it isn't MUI (judging by the code, haven't tested ingame yet).

Also, is the code in first post the latest? If so, you still haven't destroyed your triggers and timer

And you aren't using the ClearTriggerStruct and ClearTimerStruct from what I can see. Get it fixed :)

And fix all those locations. You only need to use one location in that trigger, and extra ones are just making more work (since you have to clear the location and then null it, whereas coordinates don't need clearing/nulling)

> And you aren't using the ClearTriggerStruct and ClearTimerStruct from what I can see. Get it fixed :)

I tried, but it lags the hell out of the machine.
Where should I put it, if I may be wrong?


> Also, is the code in first post the latest? If so, you still haven't destroyed your triggers and timer

Still updating.

> And fix all those locations. You only need to use one location in that trigger, and extra ones are just making more work (since you have to clear the location and then null it, whereas coordinates don't need clearing/nulling)

Could you give an example?
 

Flare

Stops copies me!
Reaction score
662
For the ClearStructA, put it in your onDestroy method before destroying the timer/trigger e.g.
JASS:
method onDestroy takes nothing returns nothing
call ClearTimerStructA (.mytimer)
call DestroyTimer (.mytimer)
call ClearTriggerStructA (.mytrig)
call DestroyTrigger (.mytrig)
endmethod

//I think that's how it's done. Haven't used ABC in a while


As for locations -> coordinates:
(I will bundle everything into this, so it may look like alot)
JASS:
function test takes nothing returns nothing
local unit u = GetTriggerUnit ()
local real x1 = GetUnitX (u)
local real y1 = GetUnitY (u)
local location l = GetSpellTargetLoc ()
local real x2 = GetLocationX (l)
local real y2 = GetLocationY (l)
local real dx = x2-x1
local real dy = y2 - y1
 //This gets angle from caster to target point
local real angle = Atan2 (dy, dx)
//Distance between caster and target point
//This will probably only be used for projectiles that should stop at target point
local real distance = SquareRoot ((dx*dx) + (dy*dy))
//Now lets get XY coordinates of a point offset by a random distance which will be between caster and target
local real random = GetRandomReal (1, 500)
local real rx = x1 + Cos (angle) * random
local real ry = y1 + Sin (angle) * random
//l should no longer be needed anymore
call RemoveLocation (l)
set l = null
 

Vestras

Retired
Reaction score
248
For the ClearStructA, put it in your onDestroy method before destroying the timer/trigger e.g.
JASS:
method onDestroy takes nothing returns nothing
call ClearTimerStructA (.mytimer)
call DestroyTimer (.mytimer)
call ClearTriggerStructA (.mytrig)
call DestroyTrigger (.mytrig)
endmethod

//I think that's how it's done. Haven't used ABC in a while


As for locations -> coordinates:
(I will bundle everything into this, so it may look like alot)
JASS:
function test takes nothing returns nothing
local unit u = GetTriggerUnit ()
local real x1 = GetUnitX (u)
local real y1 = GetUnitY (u)
local location l = GetSpellTargetLoc ()
local real x2 = GetLocationX (l)
local real y2 = GetLocationY (l)
local real dx = x2-x1
local real dy = y2 - y1
 //This gets angle from caster to target point
local real angle = Atan2 (dy, dx)
//Distance between caster and target point
//This will probably only be used for projectiles that should stop at target point
local real distance = SquareRoot ((dx*dx) + (dy*dy))
//Now lets get XY coordinates of a point offset by a random distance which will be between caster and target
local real random = GetRandomReal (1, 500)
local real rx = x1 + Cos (angle) * random
local real ry = y1 + Sin (angle) * random
//l should no longer be needed anymore
call RemoveLocation (l)
set l = null

Isn't that what I'm doing?
 

Flare

Stops copies me!
Reaction score
662
JASS:
private function InRange takes nothing returns boolean
    local Data d = GetTriggerStructA(GetTriggeringTrigger())
    local unit u = GetEnteringUnit()
    local location l = GetUnitLoc(u) //Does that look like XY coordinates? <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />


JASS:
private function Move takes nothing returns nothing
   local Data d = GetTimerStructA(GetExpiredTimer())
   local real x
   local real y
   
   set x = GetLocationX(d.currentloc) + 5.00 * Cos(d.facing * bj_DEGTORAD)
   set y = GetLocationY(d.currentloc) + 5.00 * Sin(d.facing * bj_DEGTORAD)
   
        call SetUnitPosition(d.dummy, x, y)
        set d.currentloc = GetUnitLoc(d.dummy) //LEAKS. You aren&#039;t destroying d.currentloc, and you are overwriting it everytime the dummy moves. You don&#039;t need to have currentloc as a member of your struct data, its pointless


And, an improved version of the above (no leaks, no locations)
JASS:
   local Data d = GetTimerStructA(GetExpiredTimer())
   local real x = GetUnitX (d.dummy)
   local real y = GetUnitY (d.dummy)
local real x2 = x + Cos (d.facing) * MOVEDIST //d.facing should be set as a value in radians, and GetUnitFacing isnt accurate with point target skills
local real y2 = y + Sin (d.facing) * MOVEDIST
call SetUnitX (d.dummy, x2)
call SetUnitY (d.dummy, y2)
//There is a SetUnitXY function around that prevents units from leaving map boundaries, but it works exactly the same as the two above functions (mins the chance of crashing the game <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />)
 

Vestras

Retired
Reaction score
248
updated.

JASS:
private function InRange takes nothing returns boolean
    local Data d = GetTriggerStructA(GetTriggeringTrigger())
    local unit u = GetEnteringUnit()
    local location l = GetUnitLoc(u) //Does that look like XY coordinates? <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />


JASS:
private function Move takes nothing returns nothing
   local Data d = GetTimerStructA(GetExpiredTimer())
   local real x
   local real y
   
   set x = GetLocationX(d.currentloc) + 5.00 * Cos(d.facing * bj_DEGTORAD)
   set y = GetLocationY(d.currentloc) + 5.00 * Sin(d.facing * bj_DEGTORAD)
   
        call SetUnitPosition(d.dummy, x, y)
        set d.currentloc = GetUnitLoc(d.dummy) //LEAKS. You aren&#039;t destroying d.currentloc, and you are overwriting it everytime the dummy moves. You don&#039;t need to have currentloc as a member of your struct data, its pointless


And, an improved version of the above (no leaks, no locations)
JASS:
   local Data d = GetTimerStructA(GetExpiredTimer())
   local real x = GetUnitX (d.dummy)
   local real y = GetUnitY (d.dummy)
local real x2 = x + Cos (d.facing) * MOVEDIST //d.facing should be set as a value in radians, and GetUnitFacing isnt accurate with point target skills
local real y2 = y + Sin (d.facing) * MOVEDIST
call SetUnitX (d.dummy, x2)
call SetUnitY (d.dummy, y2)
//There is a SetUnitXY function around that prevents units from leaving map boundaries, but it works exactly the same as the two above functions (mins the chance of crashing the game <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />)

Didn't include that in the update though. ;)
 

Trollvottel

never aging title
Reaction score
262
...and you leak a point :rolleyes:

i think if you are not going to improve this, its time to graveyard this "template"

template should be well coded triggers without leaks and they should be dynamic. this one isnt
 

Vestras

Retired
Reaction score
248
...and you leak a point :rolleyes:

i think if you are not going to improve this, its time to graveyard this "template"

template should be well coded triggers without leaks and they should be dynamic. this one isnt

I am going to update it.. Just point the leaks out.. I'm just very tired today.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
You're nulling .t before destroying it in your onDestroy method.

Then there is this in your Move function:

JASS:
        set d.currentloc = GetUnitLoc(d.dummy)


Also taken directly from Cohadar's ABC system:
JASS:

//         In your final itearation of periodic timer
//         you need to clear stored values
//         ClearTimerStructA(myTimer)
//         ClearTimerStructB(myTimer)
//         If you don&#039;t system will start to overflow
 

Vestras

Retired
Reaction score
248
You're nulling .t before destroying it in your onDestroy method.

Then there is this in your Move function:

JASS:
        set d.currentloc = GetUnitLoc(d.dummy)


Also taken directly from Cohadar's ABC system:
JASS:

//         In your final itearation of periodic timer
//         you need to clear stored values
//         ClearTimerStructA(myTimer)
//         ClearTimerStructB(myTimer)
//         If you don&#039;t system will start to overflow

Aw, crap.

I will suggest anyone not to use this system until it has been updated.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Did you by any chance try to use "ClearTimerStructA" after nulling and/or destroying the timer?
 

Flare

Stops copies me!
Reaction score
662
Decided to try out the map and see what it was like

1) Wouldn't it make more sense to put the code into a library rather than a scope (since library stuff is placed in Map Header)

2) You should add more constants... what if someone wants to reduce/increase the collision radius? The system should minimize the work that end-user should do

3) The fireballs tend to explode for no apparent reason (maybe they are colliding with old fireballs?). I repeatedly cast at same point, and fireballs kept detonating at same point (I even allowed some time incase it was a bug caused by non-MUI-ness). And the detonation was about 800 distance in front of me...

4) You should destroy timers/triggers before nulling them.

5) Why are you destroying .t? You should be using ReleaseTimer instead (since you used NewTimer to get the timer)

6) If you are using FirstOfGroup loop, you don't really need a global unit. You can just do an IsUnitEnemy check within the loop.

7) Timer frequency and speed should be constant values as well (and the distance travelled per timer interval should be (speed) * (timer interval) so that you can keep track of the exact speed)
 

Flare

Stops copies me!
Reaction score
662
JASS:
        call ReleaseTimer(.t)
        call ReleaseTimer(.ti)
        call ClearTimerStructA(.t)
        call ClearTimerStructA(.ti)


Hmmm... does that actually work correctly? Not 100% sure on how CSSafety works though :\ Wouldn't it be safer to clear the struct before releasing the timer?

!!! YOU ARE DESTROYING TIMERS CREATED BY NEWTIMER!!! Bad! IIRC, NewTimer doesn't create a new timer, it just hands out an existing timer (and you are destroying the timer, meaning that there is no longer a timer in that array value to be handed out). CSSafety was made so you don't destroy timers -.-'


And why isn't there a configuration menu? Noone is going to use this if they can't easily configure as much as possible :p

g isn't being destroyed or nulled in the InRange function

You are destroying .dietrig before killing the dummy unit in InRange, is that really a good idea? If the trigger is destroyed before the dummy dies, how will the death actions run?

You are destroying the struct in InRange and in DummyDie -AND- you are killing the dummy AGAIN! Totally unnecessary :\
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top