HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Find out, if a lightning is destroyed

12-09-2009, 01:43 AM#1
Kueken
Hey.

I would like to create a function like IsLightningDestroyed. However right now I have not found a reliable and performant possibility for such a function.

I have 2 possibilities until now:

1. DestroyLightning Hook, flag destroyed lightnings. vexorian wrote himself, hook is somewhat unreliable and i dont like to rely on it. Since almost every native which takes lightning crashes the game when the token lightning was already destroyed, most likely every fail of the hook would cause in an instant fatal error for wc3; nothing I want to risk.

2. creating new lightnings until reaching the handle id of the old lightning; if a new lightning's id is the same like the current lightning's, it was destroyed; this seems to work 100 %, lightnings always use the lowest possible handle id, so you can just count up until reaching the current id.

However
Collapse Zinc:
    lightning TempLightning[];
    function IsLightningDestroyed(lightning bolt)->boolean
    {
        integer i=GetHandleId(bolt),j=0,k=0;
        while (j<i)
        {
            k+=1;
            TempLightning[k]=AddLightning("LEAS",false,0,0,0,0);
            j=GetHandleId(TempLightning[k]);
        }
        for (k=k; k>0;k-=1)
        {
            DestroyLightning(TempLightning[k]);
        }
        return i==j;
    }


this looks performance-heavy for me, if you call it with 32 fps for every lightning you want to check... anyone knows a better possibility?
12-09-2009, 02:19 AM#2
grim001
Quote:
Originally Posted by Kueken
hook is somewhat unreliable and i dont like to rely on it.
This is just nonsense.

Quote:
Originally Posted by Kueken
this looks performance-heavy for me
It looks like a really bad idea to me. Performance-heavy is an understatement.
12-09-2009, 06:07 AM#3
DioD
create your own type lightningEX with security checks...
12-09-2009, 12:16 PM#4
Kueken
Quote:
Originally Posted by grim001
This is just nonsense.
From JassHelper Manual:
Quote:
Originally Posted by Vexorian
There are some limitations for now, if the native/bj function is called by another bj function, the hook does not work when that other bj function gets called.
If someone can proof, hook in this case works 100% and also would be accepted in a public system, I can use it. However I would still prefer another solution

Quote:
It looks like a really bad idea to me. Performance-heavy is an understatement.
Actually it is not THAT bad, usually you dont have to create more than 4-5 lightnings until the check works (until you have a worst-case scenario). I only wanted to list it, because it is the only method that actually works without crashing warcraft and without having to inject code for each DestroyLighting call.
However, I definitely do NOT want to use this, thats why I am asking for another method. Just thought, it might help some people here to think of another method to achieve this.

Quote:
create your own type lightningEX with security checks...
I need this for a public system/script for lightnings, I think it will not be accepted, if it forces you to create your lightnings using a custom create method...

But well, if there is no other, simple solution I guess, I have to use either hook or custom functions :-/
12-09-2009, 12:30 PM#5
Anachron
Use custom functions.
Hooks actually are bad, because of what you already quoted, they do not work everytime.
12-09-2009, 01:42 PM#6
grim001
Quote:
Originally Posted by Kueken
If someone can proof, hook in this case works 100% and also would be accepted in a public system, I can use it. However I would still prefer another solution
Why don't you yourself try to "proof" it? Why would you still prefer another solution?

Quote:
Originally Posted by Vexorian
There are some limitations for now, if the native/bj function is called by another bj function, the hook does not work when that other bj function gets called.
Then hook both DestroyLightning and DestroyLightningBJ; these are the only two functions capable of destroying lightnings.

Quote:
Originally Posted by Kueken
Actually it is not THAT bad, usually you dont have to create more than 4-5 lightnings until the check works (until you have a worst-case scenario).
Creating and destroying stuff IS that bad. It's very slow in JASS to do it even once, much less 4-5 times.

Quote:
Originally Posted by Kueken
and without having to inject code for each DestroyLighting call.
So if you had an actual native trigger which ran when DestroyLightning was called, it would still be "injecting code" whenever DestroyLightning is called. What is wrong with "injecting code"? Do you plan to call DestroyLightning 400 times per second?

Quote:
Originally Posted by Kueken
However, I definitely do NOT want to use this, thats why I am asking for another method. Just thought, it might help some people here to think of another method to achieve this.
Yes, something was invented exactly for things like this. They are called hooks.
12-09-2009, 01:43 PM#7
Rising_Dusk
Quote:
Originally Posted by Anachron
Hooks actually are bad, because of what you already quoted, they do not work everytime.
No, they are not, because the hook is only limited and only fails to work with BJs. Because the set of all BJs is limited, we can just hook the BJ as well. That means you should hook DestroyLightning() and any BJ that uses DestroyLightning() and you will be done.
12-09-2009, 01:46 PM#8
Rising_Dusk
I am actually just going to close this and keep all discussion within that AdvLightning thread.