AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ent Thinking (https://forums.alliedmods.net/showthread.php?t=65378)

Mini_Midget 01-07-2008 05:16

Ent Thinking
 
I'm trying to elminate the need for set_tasks in my mod and read
http://forums.alliedmods.net/showthread.php?t=43049

And now I ended up with this in my mod.

PHP Code:

plugin_init()
{
//...
new iEnt fm_create_entity("info_target")
    if (
iEnt)
    {
        
set_pev(iEntpev_classname"zswarm_lights")
        
fm_DispatchSpawn(iEnt)
        
set_pev(iEntpev_nextthink2.0)
        
register_forward(FM_Think"lightning_effects")
    }
}


public 
lightning_effects(iEnt
{
    if(!
get_pcvar_num(zomb_switch))
        return 
set_pev(iEntpev_nextthink10.0)

    if (
get_pcvar_num(zomb_lightning) == 0)
    {    
        
engfunc(EngFunc_LightStyle0"m")
        
remove_task(12175)
        
set_pev(iEntpev_nextthink10.0)
    }
    else if (
get_pcvar_num(zomb_lightning) == 1)
    {
        
engfunc(EngFunc_LightStyle0"a")
        
set_task(random_float(10.0,17.0),"thunder_clap",12175)
    }
    else if (
get_pcvar_num(zomb_lightning) == 2)
    {    
        
engfunc(EngFunc_LightStyle0"b")
        
remove_task(12175)
        
set_pev(iEntpev_nextthink10.0)
    }
    
    return 
FMRES_IGNORED
}

public 
thunder_clap() 
{
    if(!
get_pcvar_num(zomb_switch))
        return
    
    
engfunc(EngFunc_LightStyle0"p")
    
client_cmd(0,"speak %s"ZOMBIE_THUNDER)
    
    
//set_task(1.25, "lightning_effects", 12175)


Compiles with no errors and works ingame.
But the problem is that it changes the lights too fast and spams the wave file and just overloads the server.

hlstriker 01-07-2008 05:24

Re: Ent Thinking
 
Check to see if the classname is equal to "zswarm_lights" in the lightning_effects function. If it is equal, then do your thunder claps.

The reason it is spamming the server is because all the other entities using the think are activating the thunder.

Mini_Midget 01-07-2008 06:43

Re: Ent Thinking
 
Okay

I did what you said and got this now

PHP Code:


public lightning_effects(iEnt
{
    if(!
get_pcvar_num(zomb_switch))
        return 
set_pev(iEntpev_nextthink10.0)

    if (
get_pcvar_num(zomb_lightning) == 0)
    {    
        
engfunc(EngFunc_LightStyle0"m")
        
remove_task(12175)
        
//set_pev(iEnt, pev_nextthink, 10.0)
    
}
    else if (
get_pcvar_num(zomb_lightning) == 1)
    {
        static 
classname[33]
        
pev(iEntpev_classnameclassname,32)
        
        if (
equal classnameg_entlight ) )
        {
            
engfunc(EngFunc_LightStyle0"a")
            
set_task(random_float(10.0,17.0),"thunder_clap",12175)
        }
    }
    else if (
get_pcvar_num(zomb_lightning) == 2)
    {    
        
engfunc(EngFunc_LightStyle0"b")
        
remove_task(12175)
        
//set_pev(iEnt, pev_nextthink, 10.0)
    
}
    return 
FMRES_IGNORED
}

public 
thunder_clap() 
{
    if(!
get_pcvar_num(zomb_switch))
        return
    
    
engfunc(EngFunc_LightStyle0"p")
    
client_cmd(0,"speak %s"ZOMBIE_THUNDER)
    
    
//set_task(1.25, "lightning_effects", 12175)


I also made the classname a global just in case if I ever to typos.

This time it doesn't do anything if I set the cvar to 1.
The lighting stays the same as the cvar before it.
But one thing I accomplished with this is that it changes the lighting instantly which was one of my goals...
I change the cvar to 0 and it goes to normal lightning.
Then I try to change it to 1 but it stays the same as normal lighting and I wait for 20 seconds but nothing changed.
Then I changed to cvar 2 and it went to lighting b.
Tried to change it to cvar 1 again but stayed on lighting b.

hlstriker 01-07-2008 13:55

Re: Ent Thinking
 
I really didn't understand 100% what your code was trying to do. I assumed it was trying to make a lightning effect with the lights and a thunder clap sound.

If that is what you want then compile the following code to see what it does, then modify your plugin from there.

I had a lot of fun writing this :P It started as me editing your code to work, but I got carried away, heh.

Note: The way I set it up you can easily add more lightning flash effects.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define PLUGIN "Weather Effects"
#define VERSION "1.0"
#define AUTHOR "hlstriker"

#define CLASS_WEATHER_EFFECTS "zswarm_lights"
#define ZOMBIE_THUNDER_1 "ambience/thunder_clap.wav"
#define ZOMBIE_THUNDER_2 "de_torn/torn_thndrstrike.wav"
new lightStyleChar[3][2] = { "a""b""m" };
new 
lightStyleNum;
new 
lightCounter;
new 
flashNum;
new 
bool:isFlashing;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    new 
iEnt engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"ambient_generic"));
    if(
iEnt)
    {
        
dllfunc(DLLFunc_ThinkiEnt);
        
set_pev(iEntpev_classnameCLASS_WEATHER_EFFECTS);
        
        
set_keyvalue(iEnt"message"ZOMBIE_THUNDER_1); // WAV name
        
set_keyvalue(iEnt"targetname""boom"); // Name
        
set_keyvalue(iEnt"pitchstart""100"); // Start Pitch
        
set_keyvalue(iEnt"pitch""100"); // Pitch (> 100 = higher)
        
set_keyvalue(iEnt"health""10"); // Volume (10 = loudest)
        
set_keyvalue(iEnt"spawnflags""49"); // Play Everywhere, Start Silent, Not Toggled
        
        
dllfunc(DLLFunc_SpawniEnt);
        
set_pev(iEntpev_nextthinkget_gametime() + 2.0);
        
        
register_forward(FM_Think"fwd_Think"1);
    }
}

public 
plugin_precache()
{
    
precache_sound(ZOMBIE_THUNDER_1);
    
precache_sound(ZOMBIE_THUNDER_2);
}

public 
fwd_Think(iEnt)
{
    if(!
pev_valid(iEnt))
        return 
FMRES_IGNORED;
    
    static 
className[32];
    
pev(iEntpev_classnameclassName31);
    
    if(
equal(classNameCLASS_WEATHER_EFFECTS))
    {
        static 
thinkReturnrandNum;
        if(!
isFlashing)
        {
            
randNum random_num(01);
            if(
randNum)
                
set_pev(iEntpev_messageZOMBIE_THUNDER_1);
            else
                
set_pev(iEntpev_messageZOMBIE_THUNDER_2);
            
isFlashing true;
            
flashNum random_num(13);
            
dllfunc(DLLFunc_UseiEnt0);
        }
        
thinkReturn lightning();
        
        if(
thinkReturn)
            
set_pev(iEntpev_nextthinkget_gametime() + random_float(2.512.5));
        else
            
set_pev(iEntpev_nextthinkget_gametime() + 0.1);
    }
    
    return 
FMRES_HANDLED;
}

stock lightning()
{
    switch(
flashNum)
    {
        
// Flash 1 time
        
case 1:
        {
            
lightCounter += 1;
            switch(
lightCounter)
            {
                case 
1lightStyleNum 1;
                case 
2lightStyleNum 2;
                case 
3lightStyleNum 1;
                case 
4lightStyleNum 0;
            }
            
engfunc(EngFunc_LightStyle0lightStyleChar[lightStyleNum]);
            
            if(
lightCounter == 4)
            {
                
lightCounter 0;
                
isFlashing false;
                return 
1;
            }
            else
                return 
0;
        }
        
// Flash 2 times
        
case 2:
        {
            
lightCounter += 1;
            switch(
lightCounter)
            {
                case 
1lightStyleNum 1;
                case 
2lightStyleNum 2;
                case 
3lightStyleNum 1;
                case 
4lightStyleNum 2;
                case 
5lightStyleNum 1;
                case 
6lightStyleNum 0;
            }
            
engfunc(EngFunc_LightStyle0lightStyleChar[lightStyleNum]);
            
            if(
lightCounter == 6)
            {
                
lightCounter 0;
                
isFlashing false;
                return 
1;
            }
            else
                return 
0;
        }
        
// Flash 3 times
        
case 3:
        {
            
lightCounter += 1;
            switch(
lightCounter)
            {
                case 
1lightStyleNum 1;
                case 
2lightStyleNum 2;
                case 
3lightStyleNum 1;
                case 
4lightStyleNum 2;
                case 
5lightStyleNum 1;
                case 
6lightStyleNum 2;
                case 
7lightStyleNum 1;
                case 
8lightStyleNum 0;
            }
            
engfunc(EngFunc_LightStyle0lightStyleChar[lightStyleNum]);
            
            if(
lightCounter == 8)
            {
                
lightCounter 0;
                
isFlashing false;
                return 
1;
            }
            else
                return 
0;
        }
    }
    return 
1;
}

stock set_keyvalue(entkey[], value[])
{
    new 
classname[32];
    
    
pev(entpev_classnameclassname31);
    
set_kvd(0KV_ClassNameclassname);
    
set_kvd(0KV_KeyNamekey);
    
set_kvd(0KV_Valuevalue);
    
set_kvd(0KV_fHandled0);
    
    
dllfunc(DLLFunc_KeyValueent0);



Alka 01-07-2008 14:18

Re: Ent Thinking
 
Huh, this is awsome. Works fine...the effect is cool :D

Mini_Midget 01-08-2008 06:19

Re: Ent Thinking
 
Just tested and WOW factor is like 10/10 for me.
Thats like the real thing!

I would love to use this for my mod as this is a lot more better than my original one! So can I hlstriker?

hlstriker 01-08-2008 17:33

Re: Ent Thinking
 
Why couldn't you? I made it for you :)

EDIT:

Note that you might want to change...
new lightStyleChar[3][2] = { "a", "b", "m" };

to...
new lightStyleChar[3][2] = { "a", "b", "c" };

I like that better so it doesn't make it so bright.

kp_uparrow 01-09-2008 00:15

Re: Ent Thinking
 
the problem is set_pev(iEnt, pev_nextthink, 10.0), its gonna think every frame after 10.0, lol hawk

needs to be set_pev(iEnt, pev_nextthink, halflife_time()+10.0)

hlstriker 01-09-2008 00:23

Re: Ent Thinking
 
That wasn't the only problem. I think by the code I posted he can figure out what was wrong with his.


All times are GMT -4. The time now is 11:09.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.