System Autocast System

Status
Not open for further replies.

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Code:
//====================================================================================
//The following Triggers may be removed if you have Kattana's System already in place.
//====================================================================================

function H2I takes handle H returns integer
    return H
    return 0
endfunction

function LocalVars takes nothing returns gamecache
    return InitGameCache("jasslocalvars.w3v")
    //======Replace "InitGameCache("jasslocalvars.w3v")" with a global Variable!======
endfunction

function GetHandleTimer takes handle h, string key returns timer
    return GetStoredInteger(LocalVars(),I2S(H2I(h)),key)
    return null
endfunction

function GetHandleString takes handle h, string key returns string
    return GetStoredInteger(LocalVars(),I2S(H2I(h)),key)
    return ""
endfunction

function GetHandleUnit takes handle h, string key returns unit
    return GetStoredInteger(LocalVars(),I2S(H2I(h)),key)
    return null
endfunction

//====================================================================================
//=============The following functions must be implemented into the map.==============
//====================================================================================

function StopAutoCast takes unit Caster returns nothing
//================Call this function to stop a unit from autocasting.=================
    local string S = GetHandleString(Caster,"O")
    call DestroyTimer(GetHandleTimer(Caster,S))
    call FlushStoredMission(LocalVars(),S)
    call FlushStoredMission(LocalVars(),I2S(H2I(Caster)))
    set S = ""
endfunction

function AutoCastAbil takes nothing returns nothing
    local timer T = GetExpiredTimer()
    local unit u = GetHandleUnit(T,"u")
    local string O = GetHandleString (T,"O")
    call IssueImmediateOrder(u,O)
    set T = null
    set u = null
endfunction

function AutoCastInit takes unit Caster, string Order, real CoolDown returns nothing
//==========This is the Init function.  Call it to start a unit autocasting.==========
    local timer T = CreateTimer()
    local string O = Order
    local string t = I2S(H2I(T))
    local unit u = Caster
    call StoreInteger(LocalVars(),I2S(H2I(Caster)),O,H2I(T))
    call StoreInteger(LocalVars(),t,"O",S2I(Order))
    call StoreInteger(LocalVars(),t,"u",H2I(u))
    call TimerStart(T,CoolDown + 0.01,true,function AutoCastAbil)
	set O = ""
    set u = null
    set t = ""
    set T = null
endfunction

//========Description========//
This is an autocasting system, for any spell. To make a unit start autocasting, simply call the last function (AutoCastInit), with the Caster, Ability order, and the cooldown of the ability. Once you call this function, it will constantly order the unit to cast, but only when the cooldown of the spell has finished. It is compatable with Kattana's Local Handle Variable system, as well as Vexorian's Caster System.

//========Implement Instructions========//
In order to use this in your map, copy and paste the code into your map header, and change the LocalVars function to include your global gamecache. You must also properly initialize the game cache, in a trigger that runs at map initialization, like this:

Code:
Custom Script:    call FlushGameCache(InitGameCache("udg_GC"))
Custom Script:    set udg_GC = InitGameCache("udg_GC")

When an autocasting unit dies, you will have to call the StopAutoCast function with your dieing unit, so that the function will not keep ordering the dead unit to cast.

//========Features========//
-Accurate timer orders
-Completely MUI (Multi-Instanceable)
-Leakless
-An easy-off function to stop an autocasting unit, and remove all useless attached variables.
-Simple to use

Please give credit if you use this in your map! :)
 
Z

Zync

Guest
A tip or 2!

Leaks:
- You never destroy your timers in any of your function, you just set it to null.
Extra Steps:
- Why do you have the local variable "O" in AutoCastInit? Just use the Order paramater.
- Why do you "set O = null" (or "t = null")? It's a native string, that doesn't leak, only Objects leak.
Remark:
- This implementation only works for an instant spell. That is, one that does not target unit, location, region, or a group. (And who would want to auto-cast stomp, especially when there is no notation?) Since you're using JASS, you should include different functionality based on at least some of these target types. Afterall, this will never be used by another who can JASS, it's too specific, and what you have takes less time to write your own than it does to search through these forums.

Although this sort of thing is good practice! =D
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Yeah, this is the type of thing I did in my spare time in my Drafting class at school. :p

>> - You never destroy your timers in any of your function, you just set it to null.

I know. I wanted it to be able to be used on any unit, and if I destroyed the timer, it would stop autocasting. So I added another function (function StopAutoCast) to destroy the timer, so that way the mapper could stop the autocast anytime he wished.

>> - Why do you "set O = null" (or "t = null")?

Well you do have to nullify all locals. Handles leak for any type of variable, whereas all locals leak except for integers and reals.

This implementation only works for an instant spell. That is, one that does not target unit, location, region, or a group. (And who would want to auto-cast stomp, especially when there is no notation?) Afterall, this will never be used by another who can JASS, it's too specific, and what you have takes less time to write your own than it does to search through these forums.

Well I remember many times wanting an aoe spell to autocast. I tried to add very specific implement instructions, so that any mapper (including non-JASSers) would be able to use this easily.

Thanks for the feedback though. :eek:
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
I might want to use this but your implement instructions for this aren't very good, care to elaborate?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
This system was a big failure, as it required someone to know the order string, didn't allow for insufficient mana. Plus, it's based on the very outdated Kattana's Handle Variable system. :p

Can a mod/admin please move this to the graveyard? :p

Thanks :D
 
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top