| xbatista |
02-16-2009 10:33 |
Server crash when looping etc...
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
// CVAR Pointers
// -------------------------------------------------------------------------------------------------
new CVAR_RADIUS, CVAR_JUMPRADIUS, CVAR_DAMAGE, CVAR_COOLDOWN;
// Global Variables
// -------------------------------------------------------------------------------------------------
#define MAXSLOTS 32
new gSpriteLightning
new bool:gHit[33][33];
new Float: g_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 distance, closest_id = id, closest_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(id, pev_origin, origin);
new loop_count = 0, last_id = id;
while ( loop_count <= MAXSLOTS )
{
if ( !is_user_alive(closest_id) ) break;
pev(closest_id, pev_origin, origin);
if ( closest_id == id ) closest_distance = first_distance;
else closest_distance = other_distance;
for ( new i = 1; i <= MAXSLOTS; i++ )
{
if ( !is_user_alive(i) || i == id ) continue;
if ( gHit[id][i] == true ) continue;
if ( _:get_user_team(i) == team ) continue;
pev(i, pev_origin, other_origin);
distance = floatround(get_distance_f(origin, other_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_id, closest_id);
emit_sound(last_id, CHAN_AUTO, gSound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
ExecuteHam(Ham_TakeDamage, closest_id, 0, id, damage, 0);
client_print(id, print_chat, "Wait %i seconds until next fire!", CVAR_COOLDOWN)
g_LastLeap[id] = Time
last_id = closest_id;
}
}
for (new i = 0; i <= MAXSLOTS; i++) gHit[id][i] = false;
if ( closest_id == id )
{
client_print(id, print_chat, gMessage)
return;
}
}
public lightning_effect(id, target_id)
{
if ( !is_user_alive(id) || !is_user_alive(target_id) ) return;
message_begin(MSG_BROADCAST, SVC_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(25, 90)); //noise amplitude in 0.1's
write_byte(255); //red
write_byte(255); //green
write_byte(255); //blue
write_byte(random_num(100, 200)); //brightness
write_byte(0); //scroll speed in 0.1's
message_end();
message_begin(MSG_BROADCAST, SVC_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(25, 90)); //noise amplitude in 0.1's
write_byte(255); //red
write_byte(255); //green
write_byte(255); //blue
write_byte(random_num(100, 200)); //brightness
write_byte(0); //scroll speed in 0.1's
message_end();
message_begin(MSG_BROADCAST, SVC_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(25, 90)); //noise amplitude in 0.1's
write_byte(255); //red
write_byte(255); //green
write_byte(255); //blue
write_byte(random_num(100, 200)); //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 :/ :(
|