wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Tutorials > JASS/AI scripts tutorials
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 07-02-2008, 07:50 PM   #16
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Quote:
I think this version will work perfectly for you: http://www.wc3campaigns.net/pastebin...5d68521ab3cde7
Well, somehow that doesn't work on my map =S
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 07-15-2008, 06:53 PM   #17
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Bump!!!!

Found a bug and fixed more stuff...
moyack is offline   Reply With Quote
Old 10-08-2008, 06:06 PM   #18
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

CSSafety is deprecated as TimerUtils has replaced it, so you should delete the link to it.

Likewise, you really shouldn't be endorsing something as outdated as HandleVars anymore. You should use one of the more modern attachment systems you list (you should also list Table). However, since you're using TimerUtils anyway, you don't need an extra attachment system in the first place since TimerUtils comes with Set/GetTimerData. Also, since timers get recycled anyway there's no need to set the local variables pointing to them to null.

You don't need to set .hasbuff to false in the onDestroy method because calling allocate gives it it's default value anyway.

Instead of adding to the counter and checking if it has exceeded duration every time, it would be simpler to set it to duration at the beginning of the spell and then subtract from it, checking if it has gone below 0.0

The highlighting seems a bit odd in "Rabid Bite with non stacktable effect", you're highlighting some old functions but not the new code.

I don't really approve of the way you loop through your structs, since you're likely to come across indexes that are no longer active. In your example with one timer, this could directly lead to buggy behaviour of units still taking damage even after they are no longer affected by the spell. Instead, you should maintain a separate array of active struct instances like this spell does.

Last, but not least, you're missing an important chapter:
Approach N 3: using the ABuff a buff system. ;)
__________________
Anitarf is offline   Reply With Quote
Old 10-08-2008, 07:38 PM   #19
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by Anitarf
CSSafety is deprecated as TimerUtils has replaced it, so you should delete the link to it.

Likewise, you really shouldn't be endorsing something as outdated as HandleVars anymore. You should use one of the more modern attachment systems you list (you should also list Table). However, since you're using TimerUtils anyway, you don't need an extra attachment system in the first place since TimerUtils comes with Set/GetTimerData. Also, since timers get recycled anyway there's no need to set the local variables pointing to them to null.

You don't need to set .hasbuff to false in the onDestroy method because calling allocate gives it it's default value anyway.

Instead of adding to the counter and checking if it has exceeded duration every time, it would be simpler to set it to duration at the beginning of the spell and then subtract from it, checking if it has gone below 0.0

The highlighting seems a bit odd in "Rabid Bite with non stacktable effect", you're highlighting some old functions but not the new code.
Ok, I'll dot the respective updates and improvements...

Quote:
I don't really approve of the way you loop through your structs, since you're likely to come across indexes that are no longer active. In your example with one timer, this could directly lead to buggy behaviour of units still taking damage even after they are no longer affected by the spell. Instead, you should maintain a separate array of active struct instances like this spell does.
I'll check it this night... but all those codes were tested before and I didn't have that situation...

Quote:
Last, but not least, you're missing an important chapter:
Approach N 3: using the ABuff a buff system. ;)
Post how this spell should look with Abuff, and I'll add it to the first post :)
moyack is offline   Reply With Quote
Old 12-05-2008, 01:27 PM   #20
PitzerMike
Alcopops
 
PitzerMike's Avatar


Tools & Tutorials Moderator
 
Join Date: Jan 2003
Posts: 2,794

Submissions (12)

PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)

Approved Map: Pitzer's Minesweeper

Default

Why wasn't this approved long ago?
Noone knows.
__________________
Zoom (requires log in)
PitzerMike is offline   Reply With Quote
Old 12-06-2008, 10:50 PM   #21
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Yes it was approved ages ago.
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote
Old 12-09-2008, 12:00 PM   #22
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,154

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

nonstackable version is not working for me :/
gave me a syntax error unknown function IsUnitGroup
i assume it should be "IsUnitInGroup"...
but still ..doesnt work

stackable version works though

EDIT: Forget that...a firefox addon caused the trouble ....the Firefox addon replaces "Innen" with "en" and "In" with "e"....cant explain what it is for ...its something like a german special xDD

Last edited by akolyt0r : 12-09-2008 at 12:13 PM.
akolyt0r is offline   Reply With Quote
Old 12-14-2008, 10:17 PM   #23
Zerzax
Zerzy
 
Zerzax's Avatar
 
Join Date: Mar 2008
Posts: 708

Submissions (2)

Zerzax is a jewel in the rough (192)Zerzax is a jewel in the rough (192)Zerzax is a jewel in the rough (192)

2008 Spell olympics - Fire - SilverSpell Making Session 13 WinnerSpell Making Session 12 Winner

Send a message via AIM to Zerzax Send a message via MSN to Zerzax
Default

Nice Moyack. I'm going to use your indexing methods for global timers now, it is the best I've seen yet, none of those cumbersome arrays. +rep When I can.
Zerzax is offline   Reply With Quote
Old 12-18-2008, 01:59 AM   #24
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Added new info about an efficient way to iterate through data using unit groups.

Quote:
Originally Posted by me
Addition: Looping throught units.

As a part of development of spells controlled with a single timer, we need to iterate through an array of data. this can be done in several way, ones are less efficients than others. If we have units as a part of the data struct, we can use them to develop a very safe way of iteration using the ForGroup command. An example can help us right now.

Collapse Spell that uses second approach and uses units as reference...:
// ================================================================= \\
// Custom Immolation modifier spell, so it targets destructables too \\
// Request by Abriko, by moyack. 2008.                               \\
// ================================================================= \\
// Requires Table to work...                                         \\
// ================================================================= \\
scope Immolation2 initializer init

// Configuration Part...
globals
    private constant integer SpellID = 'AEi2' //Spell based on Immolation
    private constant integer BuffID = 'BEim' //Immolation buff, please base it on the immolation buff.
    private constant real dt = 1.
endglobals

private constant function DamageRate takes integer level returns real
    return 10. + 5. * (level - 1)
endfunction

private constant function AOE takes integer level returns real
    return 160.
endfunction
// End configuration Part...

private struct data
    static HandleTable T
    static group G
    static rect R
    static unit U

    unit c
    boolean flag = false
    
    static method Start takes unit c returns nothing
        local data D = data.allocate()
        set D.c = c
        call GroupAddUnit(data.G, c)
        set data.T[c] = integer(D)
    endmethod
    
    method onDestroy takes nothing returns nothing
        call GroupRemoveUnit(data.G, .c)
        call data.T.flush(.c)
    endmethod
endstruct

private function GetLivingDestructables takes nothing returns boolean
    return GetDestructableLife(GetFilterDestructable()) > 0.405
endfunction 

private function BurnDestructables takes nothing returns nothing
    local destructable d = GetEnumDestructable()
    call DestroyEffect(AddSpecialEffect(GetAbilityEffectById(BuffID, EFFECT_TYPE_SPECIAL, 0), GetWidgetX(d), GetWidgetY(d)))
    call UnitDamageTarget(data.U, d, DamageRate(GetUnitAbilityLevel(data.U, SpellID)) * dt, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS)
    set d = null
endfunction

private function CheckStatus takes nothing returns nothing
    local unit u = GetEnumUnit()
    local data D = data( data.T[u] )
    if not D.flag and GetUnitAbilityLevel(u, BuffID) > 0 then
        set D.flag = true
    endif
    if D.flag and GetUnitAbilityLevel(u, BuffID) > 0 then
        call SetRect(data.R, GetUnitX(u) - AOE(GetUnitAbilityLevel(u, SpellID)), GetUnitY(u) - AOE(GetUnitAbilityLevel(u, SpellID)), GetUnitX(u) + AOE(GetUnitAbilityLevel(u, SpellID)), GetUnitY(u) + AOE(GetUnitAbilityLevel(u, SpellID))) 
        set data.U = u
        call EnumDestructablesInRect(data.R, Condition(function GetLivingDestructables), function BurnDestructables)
    endif
    if D.flag and GetUnitAbilityLevel(u, BuffID) < 1 then
        call D.destroy()
    endif
    set u = null
endfunction

private function Loop takes nothing returns nothing
    call ForGroup(data.G, function CheckStatus)
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SpellID
endfunction

private function Actions takes nothing returns nothing
    if not IsUnitInGroup(GetTriggerUnit(), data.G) then
        call data.Start(GetTriggerUnit())
    endif
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 t = null
    set data.T = HandleTable.create()
    set data.G = CreateGroup()
    set data.R = Rect(0,0,1,1)
    call TimerStart(CreateTimer(), dt, true, function Loop)
endfunction

endscope

What I'm doing in this spell:
  • I use a group to store all the units that cast the spell. Those units will be my reference or index key.
  • I use a HandleTable to store the struct data ID related to the unit.
  • To iterate though all the active struct data, I call the ForGroup command and in the enumerating function I retrieve the data struct related to the unit with the command data.

The advantages of this iterating process:
  • You can have total control of the structs.
  • Therefore, you'll have control over all the struct in a safe way.
  • Data search is practically O(1) thanks to the usage of table (gamecache search property)

Disadvantage:
  • Only can be used with handles which support grouper handles (units > groups, player > force)

This procedure is very useful in spells because almost in all the cases (for not saying all the cases) there's a unit involved in the spell process, and that unit can serve us as a index for the spell itself.
moyack is offline   Reply With Quote
Old 12-18-2008, 08:41 AM   #25
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Collapse JASS:
    static method Start takes unit c returns nothing
        local data D = data.allocate()
        set D.c = c
        call GroupAddUnit(data.G, c)
        set data.T[c] = integer(D)
    endmethod
gamecache + units = phail
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 12-18-2008, 10:42 AM   #26
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by cohadar
gamecache + units = phail
I've searched through this site looking a post of you with a clear explanation and unfortunately I didn't find it. Could you please give us a good explanation why it sucks??
moyack is offline   Reply With Quote
Old 12-18-2008, 02:13 PM   #27
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

http://www.wc3campaigns.net/showpost...4&postcount=66
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 12-18-2008, 02:59 PM   #28
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Quote:
gamecache + units = phail
Not necessarily.

You can use a group for control, and if all you are attaching to the unit is the spell instance for a channeling spell, it actually works without safeguards.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 12-18-2008, 04:33 PM   #29
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

There is like a million places where that is not applicable.

If groups get too large IsUnitInGroup() gets slow.
You would also have to use that refresh-group thing that griffein made.
And sometimes you want to add some unit-property to all units on the map preferably with some default value.
Spells are not the only things that need custom unit properties you know.
Physics engine, Buff engine, DamageDetection engine....
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 12-19-2008, 01:01 AM   #30
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by cohadar
*sigh*

Ok I see some of you people really need a mathematical explanation,
so here it is:

Code:
Lets suppose we have a unit whose handle number is 'u001'
Now you attach to that unit some data.

During the course of spell before we get to retrieve that data 
the unit 'u001' dies, decays and it's handle gets recycled.

Now somewhere on the map a new unit is created,
and that new unit get a recycled handle 'u001'

After that we decide to retrieve units data and continue our spell execution
using a wrong unit - FUCKUP

This cannot happen with PUI.
well, it can happen, but it would happen if the code that uses the attaching procedure doesn't take into consideration the unit death. So the problem is not gamecache on units but the coder if it doesn't take into account that situation. I take that situation into consideration using the buff, because as you know, a buff is turned off if the spell duration is reached, or when a unit dies or when is debuffed. In my code, by using the buffs I take in account these scenarios making the code reliable.

Now about your other arguments...

Quote:
If groups get too large IsUnitInGroup() gets slow.
Well, and doing a full code that search on units can be faster than a native function? I don't think so...

Quote:
You would also have to use that refresh-group thing that griffein made.
What refresh group?? Did I miss something... EDIT: found it: http://www.wc3campaigns.net/showthread.php?t=102162

Quote:
And sometimes you want to add some unit-property to all units on the map preferably with some default value.
Spells are not the only things that need custom unit properties you know.
Physics engine, Buff engine, DamageDetection engine....
Yes, sometimes, but attaching a struct data to a unit is not a big deal regardless of the attaching system, IF AND ONLY IF THE USER CODES PROPERLY.

Last edited by moyack : 12-19-2008 at 01:50 AM.
moyack is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 11:41 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services