Raised This Month: $ Target: $400
 0% 

Server crash when looping etc...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 02-16-2009 , 10:33   Server crash when looping etc...
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

// CVAR Pointers
// -------------------------------------------------------------------------------------------------
new CVAR_RADIUSCVAR_JUMPRADIUSCVAR_DAMAGECVAR_COOLDOWN;

// Global Variables
// -------------------------------------------------------------------------------------------------
#define MAXSLOTS 32
new gSpriteLightning
new bool:gHit[33][33];

new 
Floatg_LastLeap[33]
new const 
gMessage[] = "No valid targets!";
new const 
gSound[] = "ambience/steamburst1.wav";

// Initialization
// -------------------------------------------------------------------------------------------------
public plugin_init()
{
    
// Plugin Info
    
register_plugin("xxx""1.0""xxx");
    
    
CVAR_RADIUS register_cvar("shaman_radius""400");
    
CVAR_JUMPRADIUS register_cvar("shaman_jumpradius""400");
    
CVAR_DAMAGE register_cvar("shaman_damage""500");
    
CVAR_COOLDOWN register_cvar("shaman_cooldown""30");

    
register_clcmd("+lightning""lightning")
}

public 
plugin_precache()
{
    
precache_sound(gSound);
    
gSpriteLightning precache_model("sprites/lgtning.spr");
}

// Events and Forwards
// -------------------------------------------------------------------------------------------------
// Custom Functions
// -------------------------------------------------------------------------------------------------
public lightning(id)
{
    if ( !
is_user_alive(id) ) return;
    
    new 
team _:get_user_team(id);
    new 
Float:origin[3], Float:other_origin[3];
    new 
distanceclosest_id idclosest_distance;
    
    static 
Float:Time
    Time 
get_gametime()
    static 
Float:cooldown
    cooldown 
get_pcvar_float(CVAR_COOLDOWN)
    
    new 
first_distance get_pcvar_num(CVAR_RADIUS);
    new 
other_distance get_pcvar_num(CVAR_JUMPRADIUS);
    new 
Float:damage get_pcvar_float(CVAR_DAMAGE)
    
    
pev(idpev_originorigin);
    
    new 
loop_count 0last_id id;
    while ( 
loop_count <= MAXSLOTS )
    {
        if ( !
is_user_alive(closest_id) ) break;
        
        
pev(closest_idpev_originorigin);
        
        if ( 
closest_id == id closest_distance first_distance;
        else 
closest_distance other_distance;
        
        for ( new 
1<= MAXSLOTSi++ )
        {
            if ( !
is_user_alive(i) || == id ) continue;
            if ( 
gHit[id][i] == true ) continue;
            if ( 
_:get_user_team(i) == team ) continue;
            
            
pev(ipev_originother_origin);
            
distance floatround(get_distance_f(originother_origin));
            
            if ( 
distance <= closest_distance )
            {
                
closest_id i;
                
closest_distance distance;
            }
        }
        
        if ( 
closest_id == last_id ) break;
        
gHit[id][closest_id] = true;

        if (
Time cooldown g_LastLeap[id])
        {
        
loop_count++;
        
lightning_effect(last_idclosest_id);
        
emit_sound(last_idCHAN_AUTOgSoundVOL_NORMATTN_NORM0,  PITCH_NORM);
        
ExecuteHam(Ham_TakeDamageclosest_id0iddamage0);
        
client_print(idprint_chat"Wait %i seconds until next fire!"CVAR_COOLDOWN)
        
g_LastLeap[id] = Time
        last_id 
closest_id;
        }
    }
    
    for (new 
0<= MAXSLOTSi++) gHit[id][i] = false;
    
    if ( 
closest_id == id )
    {
        
client_print(idprint_chatgMessage)
        return;
    }
}

public 
lightning_effect(idtarget_id)
{
    if ( !
is_user_alive(id) || !is_user_alive(target_id) ) return;
    
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY);
    
write_byte(TE_BEAMENTS);
    
write_short(id);            //start entity
    
write_short(target_id);            //end entity
    
write_short(gSpriteLightning);        //sprite index
    
write_byte(0);                //starting frame
    
write_byte(1);                //frame rate in 0.1's
    
write_byte(5);                //life in 0.1's
    
write_byte(25);                //line width in 0.1's
    
write_byte(random_num(2590));        //noise amplitude in 0.1's
    
write_byte(255);            //red
    
write_byte(255);            //green
    
write_byte(255);            //blue
    
write_byte(random_num(100200));    //brightness
    
write_byte(0);                //scroll speed in 0.1's
    
message_end();
    
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY);
    
write_byte(TE_BEAMENTS);
    
write_short(id);            //start entity
    
write_short(target_id);            //end entity
    
write_short(gSpriteLightning);        //sprite index
    
write_byte(0);                //starting frame
    
write_byte(1);                //frame rate in 0.1's
    
write_byte(5);                //life in 0.1's
    
write_byte(25);                //line width in 0.1's
    
write_byte(random_num(2590));        //noise amplitude in 0.1's
    
write_byte(255);            //red
    
write_byte(255);            //green
    
write_byte(255);            //blue
    
write_byte(random_num(100200));    //brightness
    
write_byte(0);                //scroll speed in 0.1's
    
message_end();
    
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY);
    
write_byte(TE_BEAMENTS);
    
write_short(id);            //start entity
    
write_short(target_id);            //end entity
    
write_short(gSpriteLightning);        //sprite index
    
write_byte(0);                //starting frame
    
write_byte(1);                //frame rate in 0.1's
    
write_byte(5);                //life in 0.1's
    
write_byte(25);                //line width in 0.1's
    
write_byte(random_num(2590));        //noise amplitude in 0.1's
    
write_byte(255);            //red
    
write_byte(255);            //green
    
write_byte(255);            //blue
    
write_byte(random_num(100200));    //brightness
    
write_byte(0);                //scroll speed in 0.1's
    
message_end();

Problem with "loop_count++;" when it in:
PHP Code:
        if (Time cooldown g_LastLeap[id])
        { 
Then server crash when binded button and used power.
Triyed to do it without:
PHP Code:
if (Time cooldown g_LastLeap[id])
        { 
But I need a cooldown so...I'm missed... I've no ideas how to correct :/

Last edited by xbatista; 02-16-2009 at 11:06.
xbatista is offline
Send a message via Skype™ to xbatista
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:00.


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