• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Energy link system

Status
Not open for further replies.
Level 4
Joined
Apr 27, 2009
Messages
94
Right so, even though im not exactly new to triggering I havent been able to figure this one out.

What I basically want, is to link buildings together as if they share energy with each other.
The idea is to make a building (lets say power plant for example) which will supply other buildings with mana(energy) and the power plant should create a stream connected to the buildings, like a siphon mana animation for example.

Now the point where I got stuck is, I do not exactly see how to work with unit groups here and ill explain why.

Lets say, you give an ability to the power plant an do something like this.
  • unit starts the effect of an ability
  • ability being cast equal to *random name*
then add the power plant and the target of ability being cast to unit groups, but then the issue would be, if i were to create more than 1 power plant, its going to be a complete mess, does anyone know a way around this?
Or more specifically, how to do this?
Also I would like to be able to link 1 power plant to several buildings.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
With other words: you want to recreate the TD (I can't recall the name... Power TD?), but then working in patch 1.24? :p
Probably one of the most inovative and advanced TD's I've played (it's in my top-5 for sure).

The TD you probably like to remake is completely written in JASS (I believe vJass), but it probably also works with GUI, but it's a bit more complicated.
Perhaps you could do it with either hashtables or indexing, I personally find hashtables the easiest to use.

When a power plant casts the spell, save all values (such as mana drained/sec, color of the lightning, ...) for the targetted unit (not the power plant, since a power plant can have multiple connections).
Then you need to save the power plant in the targetted unit's hashtable (as a unit) and add it to a unit group.

Well, I wanted to create the same TD myself (a while ago), but I'm just too lazy.
 
Level 6
Joined
Mar 20, 2008
Messages
208
You can use custom unit data, its a free variable.

Store a global integer/real and have it incremented whenever a powerplant is created.

Power plant is created
-Assign the custom value to the stored integer
-Increment the stored integer

Powerplant uses an ability onto a target
-Set that target's custom value to that of the powerplant.

A building uses an ability
-Pick all units of type powerplant and compare custom values
-If the values match, drain mana from the plant, increase mana to the building (Or however you want it to power things)
 
Level 4
Joined
Nov 7, 2009
Messages
83
You can trigger when unit that requires power plant is added finished and join them using a lightning animation. Then you add unit to a unitgroup that says which units deppend on the power plant. Finally, you can make a periodic trigger that says that all units in unit group "feeded by power plant" get x mana.

  • PowerPlantLink
  • Events
    • Unit - A unit finishes construction
  • Conditions
    • (Unit-type of (constructed structure)) equal to Your unit types
  • Actions
    • Unit group - add (constructed structure) to FeededByPowerPlant
    • Lightning - Create a whatever lightning effect - lightning effect from (position of PowerPlant unit) to target (position of (constructed structure))
  • PowerPlantFeed
  • Events
    • Time - every xxx seconds of game time
  • Conditions
  • Actions
    • Unit group - Pick every unit in FeededByPowerPlant and do (Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) +yyy))
 
Level 4
Joined
Apr 27, 2009
Messages
94
Thanks for the replies, as for Shyhalu.
Unless I misunderstand something, wouldnt your theory mean that 1 powerplant will power the all buildings? If im wrong please enlighten me with trigger examples.

And flamesoul, another way of handling it but yet again the same problem that you would need only 1 power plant.
What I want is that each power plant can only handle a few buildings, maybe 2-4 induvidually, so that you would have to make several power plants to keep all your buildings running.

appreciate all replies however.
 
Level 4
Joined
Nov 7, 2009
Messages
83
Then you can have a variable called energy. You increase it when you build a new power plant. Decrease it when you build any building that consumes energy. If you try to build something that uses energy and you have not enough, you don't allow that construction. Something like this.

  • Building Construction
  • Events
    • Unit starts effect of an ability
  • Conditions
    • (Ability being cast) equal to whichever ability tha constructs something that uses energy
      • (Energy required) less or equal to (energy available-energy consumed)
  • Actions
    • Start construction
    • energy consumed = energy consumed + energy used by construction
  • Power Plant Construction
  • Events
    • Unit starts effect of an ability
  • Conditions
    • (Ability being cast) equal to power plant build
  • Actions
    • Energy available = energy available + power plant energy
  • Plant is destroyed
  • Events
    • Unit dies
  • Conditions
    • Dying unit equal to power plant
  • Actions
    • energy available=energy available-power plant energy
  • Building is destroyed
  • Events
    • Unit dies
  • Conditions
    • Dying unit equal to consuming power structure
  • Actions
    • energy consumed = energy consumed - energy used by that building
This is just a quick example. I think maybe it would look and be better on JASS, maybe I'll come back with something in JASS later. But forget about the nice linking drawing.
 
Level 9
Joined
May 30, 2008
Messages
430
The following information is how to make a simple energy transfer system with one power plant. It's actually working as a normal spell in GUI but units are added by different way so have fun

Actually it's pretty simple to create this system (effects will be problem for me because i have never create any of the lighting type). You simple need to create a 2 spells that will give your power plant ability to target your units/buildings and to can make "link" and "unlink" if link is casted add the unit to a unit group and here is the tricky part. You must make a periodic trigger that will fire every x seconds and it will be something like
  • pick every unit in the unit group "Units to be powered group"
  • Set integer "units to be powered" unit count in "Units to be powered group"
  • Set integer "mana of the power plant" current mana of your power plant (you should set your power plant as variable early)
  • set integer "mana to be added" to "mana of the power plant" / "units to be powered"
  • pick every unit in "Units to be powered group" and add "mana to be added" to the picked unit
  • set mana of the power plant to current mana of it - "mana of the power plant"
it may look messy but with few fixes and few adds you can actually make it work even MUI/MPI and to add some limitations for the mana transfer and so on.

Note this is example of the trigger way of building not the actual (working) build it may NEED fixes :thumbs_up:
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I think that I've made what you wanted...

  • There are power plants, which can transfer 20 mana to up to 4 buildings at a time
  • When you select a building twice, the mana transfer will stop.
  • Once you get over 4 connections, the first connection you had will be cut off
  • Power plants can be connected with eachother as well as with towers
  • Once a tower has full mana, the power plant won't transfer any mana (until the tower loses mana again).
  • If a power plant doesn't have any mana left, he will not transfer (much) mana to the tower.

It's still a demo-system: at the moment it doesn't feature different lightning effects and a different amount of mana transferred, but I just want to see whether you like it or not first.

Demo-map attached.
 

Attachments

  • Mana Transfer Demo.w3x
    16.2 KB · Views: 40
Level 4
Joined
Apr 27, 2009
Messages
94
I think that I've made what you wanted...

  • There are power plants, which can transfer 20 mana to up to 4 buildings at a time
  • When you select a building twice, the mana transfer will stop.
  • Once you get over 4 connections, the first connection you had will be cut off
  • Power plants can be connected with eachother as well as with towers
  • Once a tower has full mana, the power plant won't transfer any mana (until the tower loses mana again).
  • If a power plant doesn't have any mana left, he will not transfer (much) mana to the tower.

It's still a demo-system: at the moment it doesn't feature different lightning effects and a different amount of mana transferred, but I just want to see whether you like it or not first.

Demo-map attached.

You sir, are a genius.
Its indeed what I wanted, I repped you for it >:3
 
Level 4
Joined
Apr 27, 2009
Messages
94
Thanks ^^

I hope the triggers are clear enough for you to edit, so you can change them as you like.
If not, say what you want to add or edit (or perhaps I'll just add some comments in the triggers so you can understand it).

Well i dont have much experience with hashtables, but the only thing i had to modify was the amount of mana transfered which isnt an issue.
Needless to say, youve done it exactly the way I desired it to be ^_^ so not much editing is required.
 
Status
Not open for further replies.
Top