Clan CBS

Go Back   Clan CBS Forums > Clan CBS > Clan Projects

Clan Projects Everything and nothing about Clan CBS projects.

Reply
 
Thread Tools Display Modes
Old 01-31-2010, 10:14 PM   #1
Zakamutt
One hilarious guy
Clan Member [Grunt]
 
Zakamutt's Avatar
 
Join Date: Dec 2006
Location: Sweden
Posts: 1,400
Zakamutt is a black spot on a cows hiveZakamutt is a black spot on a cows hive
Default Spell: Sanctify

I don't have a map, but I have a triggered spell scriptz!

This script allows you to deal damage and healing around a point x and y, and differentiates between allies and enemies. I suppose it's not very complex, but care.

Put it in your map header and call it with custom script or just plain JASS, be sure to satisfy those parameters and you should be ready to go, leakfree!

trig is triggering unit.

Code:
 
function SancFilt takes nothing returns boolean
return GetWidgetLife(GetFilterUnit()) > 0.405
endfunction
 
function Sanctify takes real x, real y, unit trig, real area, real heal, real dmg returns nothing
  local group g = CreateGroup()
  local unit u
  local real hp
  call GroupEnumUnitsInRange(g, x,y,area,Filter(function SancFilt))
   loop
     set u = FirstOfGroup(g)
     exitwhen u == null
     set hp = GetUnitState(u, UNIT_STATE_LIFE)
     if ( IsUnitAlly(u, GetOwningPlayer(trig)) ) then
     call SetWidgetLife(u, hp + heal)
     else
     call SetWidgetLife(u, hp - dmg)
     endif
     call GroupRemoveUnit(g, u)
     endloop
  call DestroyGroup(g)
  set u = null
  set g = null
  endfunction
__________________
A SPOTIFY PLAYLIST.
ProjectDescriptionStatus
Ninja TacticsFFA 3ps inspired by Archery Tactics with custom spells I am currently overworked but may improve this later / map is "Final-ish"
DuelistHero battles, arena style; solo or team. Skillbased gameplay with few things "Click-to-damage".Alpha. Concept 40-60%, Terrain 10%, Triggers like 5%. frozen-ish.
Caduan's TaleSingle-player linear RPGFrozen; story playable but only amounts to around 5 mins

Last edited by Zakamutt; 02-01-2010 at 06:42 PM. Reason: Optimization and leak removal
Zakamutt is offline   Reply With Quote
Old 02-01-2010, 06:27 PM   #2
DiamondBlade
Clan Member [Grunt]
 
Join Date: May 2009
Posts: 155
DiamondBlade is warm milk
Default

This isn't leak free.
You're not nulling 'u' in function 'SancFilt'.
Though that could be easily avoided:
Code:
function SancFilt takes nothing returns boolean
local unit u = GetFilterUnit()
if (GetUnitState(u, UNIT_STATE_LIFE) > 0) then //IsUnitAlive
return true
endif
return false
endfunction
Could be:
Code:
function SancFilt takes nothing returns boolean
return (GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0) //IsUnitAlive
endfunction
Or better yet:
Code:
function SancFilt takes nothing returns boolean
return GetWidgetLife(GetFilterUnit()) > 0.405 // GetWidgetLife is faster, and shorter. .405 is the actual life at which units are considered dead.
endfunction
You may also want to consider 'IsUnitType(u, UNIT_TYPE_DEAD) == true', as a dead units health can be (accidentally) set above 1, and the above conditions would fail.

Destroying filters isn't a good idea due to how Warcraft handles them (similarly to strings, that is), and hence there's rarely a reason to ever need to assign them to locals.
There's also no point in using locals if they're only being used once, as there are no advantages whatsoever, and it's slower, longer to type, and they have to be nulled.
Function arguments don't need to be nulled - they're properly recycled automatically.
Players don't need to be nulled as they're never destroyed.

'GetUnitState(u, UNIT_STATE_LIFE)' could be 'GetWidgetLife(u)', as it's faster and shorter.
'SetUnitState(u, UNIT_STATE_LIFE, <value>)' could be 'SetWidgetLife(u, <value>)' for the same reasons.
DiamondBlade is offline   Reply With Quote
Old 02-01-2010, 06:41 PM   #3
Zakamutt
One hilarious guy
Clan Member [Grunt]
 
Zakamutt's Avatar
 
Join Date: Dec 2006
Location: Sweden
Posts: 1,400
Zakamutt is a black spot on a cows hiveZakamutt is a black spot on a cows hive
Default

Code changed in line with your suggestions. I didn't really focus on the filter, I suppose that's why I did not catch the leak.

Function arguments automatically recycled... interesting. Though I guess not surprising.

IsUnitType is not really a problem. If the map has no issues due to it increasing the life of dead units, it has no issues with this also increasing or decreasing their life. Which check is faster?
__________________
A SPOTIFY PLAYLIST.
ProjectDescriptionStatus
Ninja TacticsFFA 3ps inspired by Archery Tactics with custom spells I am currently overworked but may improve this later / map is "Final-ish"
DuelistHero battles, arena style; solo or team. Skillbased gameplay with few things "Click-to-damage".Alpha. Concept 40-60%, Terrain 10%, Triggers like 5%. frozen-ish.
Caduan's TaleSingle-player linear RPGFrozen; story playable but only amounts to around 5 mins
Zakamutt is offline   Reply With Quote
Old 02-01-2010, 06:47 PM   #4
DiamondBlade
Clan Member [Grunt]
 
Join Date: May 2009
Posts: 155
DiamondBlade is warm milk
Default

> Function arguments automatically recycled... interesting. Though I guess not surprising.
It's nice to know Blizzard only fucked up partially.

> Which check is faster?
'GetWidgetLife' is much faster. There's a downside to 'IsUnitType', though I can't remember it off the top of my head. Speed isn't really important anyway; nobody can tell the difference. Use whichever you prefer.
DiamondBlade is offline   Reply With Quote
Reply

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
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:34 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Epicwar Hive Workshop War3 Workshop Wc3 Campaigns Elemental TD