Staredit Network > Forums > Modding Assistance > Topic: Making spells require resources to cast
Making spells require resources to cast
Dec 16 2011, 1:49 am
By: xAngelSpiritx  

Dec 16 2011, 1:49 am xAngelSpiritx Post #1

eternal lurker

I really, really wish I was more proficient at C++. :P

Pretty self-explanatory though; I'm curious to know if there's a way to make spells cost resources to cast. Since you can't subtract resources from a player via iscript, I'd like to know if it's possible another way.

Although I'm guessing I'll need to script a plugin, what should I do in order to get it to work properly? Just detecting the order and subtracting the appropriate amount of resources won't work, since, if I'm not mistaken, it will cause the resources to be subtracted every frame that the order is being carried out instead of just once.


Dec 16 2011, 2:57 am Biophysicist Post #2

This is an interesting question. There are a few ways it could be pulled off.
  • Hijack nobrkcode. nobrkcodestart sets a flag that can be read (and manipulated) via plugin; iirc, it's one bit of the status variable. So, if the unit doesn't use nobrkcodestart anywhere else in its iscript, you can put one in its casting animation. If the unit is executing the spell order and in a nobrkcode section, clear the nobrkcode and deduct resources.

  • Detect the unit's energy decreasing (assuming the unit isn't going to be hit by Feedback or EMP Shockwave). Specifically, you'd need to use some unused variable (such as shields for an unshielded unit, rally coordinates for a unit that doesn't rally, etc, or possibly one of the unknowns) in the unit struct, which will hold the energy value from the previous frame (or 0, if the unit was not executing this order in the previous frame), and, each frame, check if the value of this variable is greater than the unit's energy. If it is, then the unit cast the spell. Next, set this variable to the unit's energy. Finally, if the unit is /not/ executing the order for the spell, set this value to 0.

  • Spawn and detect a dummy unit. The obvious way is to make the unit cast Spawn Broodlings (and use BWAI's EXE Edit that makes Broodlings not kill its target and work on terrain if flagged to do so, and another edit to make it spawn only one Broodling) in the casting animation, via useweapon. If a player has a live Broodling, then one of his units cast that spell. Spider Mines could possibly work. Dweb, Dswarm, or Scanner Sweep could be hacked to do it, too.

  • If the spell in question is supposed to buff the caster, then it's easy. Use StimPacks or Burrow (or Cloaking or Siege Mode, possibly) as the trigger; they're easy to detect (and, with everything except Siege Mode, their normal effects can be removed instantly).

  • If the unit doesn't have shields, you could hypothetically use Mind Control as the trigger, and detect the shield decrease. (Though, iirc, you'd have to set the caster's shields to a non-zero value upon spawn and after casting - I don't think that nonshielded units regenerate shields.)

  • Lastly, certain spells that buff the caster can be done by using the Carrier or Reaver, or one of their heroes, and letting them train a dummy unit and doing interesting stuff in the IsWorking animation via imgol.

I'm sure pq or A(s,t) would have a better way with their fancy ubercoding, but that stuff completely flies over my head, and I don't know the memory locations, nor possess the means to find them, anyway.


Dec 17 2011, 3:35 am poiuy_qwert Post #3

PyMS and ProTRG developer

You could check out the STF Plugin source. It has examples of how to do some stuff you might want. It is probably a little overwhelming when opening the source so to give you some direction, look at how kills (killCount) to cash is done.

  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[04:12 pm]
lil-Inferno -- ya
[05:32 am]
Ultraviolet -- :teach: *
[05:32 am]
Ultraviolet -- lil-Inferno
lil-Inferno shouted: ya, if the person I found is actually him lmao
creep :prof:
[10:31 pm]
lil-Inferno -- ya, if the person I found is actually him lmao
[2020-5-24. : 5:06 pm]
Voyager7456 -- lil-Inferno
lil-Inferno shouted: youarenotworthy Are you thinking of Tuxlar? I don't remember anyone else who ever made map trailers
isn't he literally a professor now too?
[2020-5-24. : 1:17 pm]
Zycorax -- Is it possible that he went by Professor Tuxlar or something for a brief period?
[2020-5-23. : 10:38 am]
NudeRaider -- youarenotworthy
youarenotworthy shouted: Regarding the other user I'm looking for, I know he was a member of this community but was more involved with the other main map making community at the time (I cant remember what it was called... MM?) but just wondering if anybody remembers him.. Professor something. I don't remember any of his projects.
that's all we got
[2020-5-22. : 6:34 pm]
Vrael -- yeah I can't remember any professor usernames either sry :(
[2020-5-22. : 3:58 pm]
Oh_Man -- I made some youtube vids for my map
[2020-5-22. : 2:22 pm]
lil-Inferno -- I can't think of anyone who went by Professor either
Please log in to shout.

Members Online: Roy, kamszot145705, jjf28, IlyaSnopchenko