• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] How to prevent lag when casting spell

Status
Not open for further replies.
Level 16
Joined
Dec 15, 2011
Messages
1,423
Something along these lines.

Event Elapsed game time is 0.00
Actions
Create a dummy unit for Player 1
Set Dummy = Last created unit
Add Ability 1 to Dummy
Add Ability 2 to Dummy
...
Create a footman for Neutral Hostile
Order Dummy to cast Ability 1 on Last created unit
Remove Last created unit
Remove Dummy

I am on a phone so only pseudocode. Sorry.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Basically, preloading abilities is a technique used to avoid the first-cast lag problem.

What you need to do:
1. Create a dummy unit anywhere on the map (make sure to clean the location leak, etc)
2. Add the ability (that causes the first-cast lag) to the dummy
3. Remove the dummy

As simple as that.

And remember, if you have a spell that spawns dummy unit, and that unit casts spell(s) too, preload the dummy's abilities too.

It's basically anything associated with the spell should be preloaded.

You can either choose to do this in Map Initialization OR Time Elapsed (or when Player chooses the Hero).

Map Initialization
This will increase the loading time of the game (Loading Screen)

Time Elapsed
You will notice a slight lag/spike early in the game

Player Chooses Hero
If your map is Hero Arena-based map, you should do this, because, it would be crazy to preload all 100++ heroes in your map, that would eat your memory so fast and the lag is tremendous.

So, only preload abilities that the Player Chooses - such as in DotA.

Have you ever noticed that when you pick a Hero, we will get a slight lag ?
Yes, that's the preloading occurs for that Heroes with all his spells being preloaded to the dummy.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
It has nothing to do with poor coding. It is the computer's specs. Not everybody has an i7 for goodness' sake.

Just use /fps and check for yourself whether the framerate drops during preload, no matter how you code it.

Btw 10000 levels is crazy. What do you use them for?
 
just to give an option. i have a spell system were a player can pick the spells they want to use no matter wat hero they pick. there are spells in groups. so if u pick a spell from a group u cant use the others in that group. the limit on spells is 6 or 7 lol.

poor coding can have a huge thing to deal with spells. if it only happens the first time it is due to preloading. if it happens everytime its either to much eye candy or poor coding.
 
Status
Not open for further replies.
Top