• 🏆 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!

[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?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
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