See here what iam talking about.
i use this code but not working properly. Please help me
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#define PLUGIN "Weather Effects"
#define VERSION "1.0"
#define AUTHOR "Alka"
#define CLASS_WEATHER_EFFECTS "weather_effects"
#define ZOMBIE_THUNDER_1 "ambience/thunder_clap.wav"
#define ZOMBIE_THUNDER_2 "de_torn/torn_thndrstrike.wav"
#define MAX_LIGHT_POINTS 4
new lightStyleChar[3][] = { "b", "c", "n" };
new lightStyleNum;
new lightCounter;
new flashNum;
new bool:isFlashing;
new lightPoints[MAX_LIGHT_POINTS];
new lightBeam;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
new iEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "ambient_generic"));
if(iEnt)
{
dllfunc(DLLFunc_Think, iEnt);
set_pev(iEnt, pev_classname, CLASS_WEATHER_EFFECTS);
set_keyvalue(iEnt, "message", ZOMBIE_THUNDER_1);
set_keyvalue(iEnt, "targetname", "wather");
set_keyvalue(iEnt, "pitchstart", "100");
set_keyvalue(iEnt, "pitch", "100");
set_keyvalue(iEnt, "health", "10");
set_keyvalue(iEnt, "spawnflags", "49");
dllfunc(DLLFunc_Spawn, iEnt);
set_pev(iEnt, pev_nextthink, get_gametime() + 2.0);
register_forward(FM_Think, "Fwd_Think", 1);
}
}
public plugin_precache()
{
precache_sound(ZOMBIE_THUNDER_1);
precache_sound(ZOMBIE_THUNDER_2);
lightBeam = precache_model("sprites/laserbeam.spr");
server_cmd("sv_skyname space");
engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_rain"));
new Fog = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_fog"));
set_keyvalue(Fog, "density", "0.001");
set_keyvalue(Fog, "rendercolor", "0 0 0");
}
public client_connect(id)
client_cmd(id, "cl_weather 1");
public Fwd_Think(iEnt)
{
if(!pev_valid(iEnt))
return FMRES_IGNORED;
static className[32];
pev(iEnt, pev_classname, className, 31);
if(equal(className, CLASS_WEATHER_EFFECTS))
{
static thinkReturn, randNum;
if(!isFlashing)
{
randNum = random_num(0, 1);
if(randNum)
set_pev(iEnt, pev_message, ZOMBIE_THUNDER_1);
else
set_pev(iEnt, pev_message, ZOMBIE_THUNDER_2);
isFlashing = true;
flashNum = random_num(1, 3);
dllfunc(DLLFunc_Use, iEnt, 0);
static Victim;
Victim = get_random_player();
if(Victim)
CreateLightningPoints(Victim);
}
thinkReturn = LightsEffect();
if(thinkReturn)
set_pev(iEnt, pev_nextthink, get_gametime() + random_float(2.5, 12.5));
else
set_pev(iEnt, pev_nextthink, get_gametime() + 0.1);
}
return FMRES_HANDLED;
}
stock LightsEffect()
{
switch(flashNum)
{
case 1:
{
lightCounter += 1;
switch(lightCounter)
{
case 1: { lightStyleNum = 1; }
case 2: { lightStyleNum = 2; }
case 3: { lightStyleNum = 1; }
case 4: { lightStyleNum = 0; }
}
engfunc(EngFunc_LightStyle, 0, lightStyleChar[lightStyleNum]);
if(lightCounter == 4)
{
lightCounter = 0;
isFlashing = false;
return 1;
}
else
return 0;
}
case 2:
{
lightCounter += 1;
switch(lightCounter)
{
case 1: { lightStyleNum = 1; }
case 2: { lightStyleNum = 2; }
case 3: { lightStyleNum = 1; }
case 4: { lightStyleNum = 2; }
case 5: { lightStyleNum = 1; }
case 6: { lightStyleNum = 0; }
}
engfunc(EngFunc_LightStyle, 0, lightStyleChar[lightStyleNum]);
if(lightCounter == 6)
{
lightCounter = 0;
isFlashing = false;
return 1;
}
else
return 0;
}
case 3:
{
lightCounter += 1;
switch(lightCounter)
{
case 1: { lightStyleNum = 1; }
case 2: { lightStyleNum = 2; }
case 3: { lightStyleNum = 1; }
case 4: { lightStyleNum = 2; }
case 5: { lightStyleNum = 1; }
case 6: { lightStyleNum = 2; }
case 7: { lightStyleNum = 1; }
case 8: { lightStyleNum = 0; }
}
engfunc(EngFunc_LightStyle, 0, lightStyleChar[lightStyleNum]);
if(lightCounter == 8)
{
lightCounter = 0;
isFlashing = false;
return 1;
}
else
return 0;
}
}
return 1;
}
public CreateLightningPoints(id)
{
static Ent, x, Float:Vel[3], Float:Origin[3];
static Float:Mins[3] = { -1.0, -1.0, -1.0 };
static Float:Maxs[3] = { 1.0, 1.0, 1.0 };
new Float:Dist = is_user_outside(id) - 5.0;
pev(id, pev_origin, Origin);
if(Dist > 700.0)
Dist = 700.0;
Origin[2] += Dist;
for(x = 0 ; x < MAX_LIGHT_POINTS ; x++)
{
Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"));
set_pev(Ent, pev_movetype, MOVETYPE_FLY);
set_pev(Ent, pev_solid, SOLID_TRIGGER);
set_pev(Ent, pev_renderamt, 0.0);
set_pev(Ent, pev_rendermode, kRenderTransAlpha);
engfunc(EngFunc_SetModel, Ent, "models/w_usp.mdl");
set_pev(Ent, pev_mins, Mins);
set_pev(Ent, pev_maxs, Maxs);
Vel[0] = random_float(-500.0, 500.0);
Vel[1] = random_float(-500.0, 500.0);
Vel[2] = random_float((Dist <= 700.0 ? 0.0 : -100.0), (Dist <= 700.0 ? 0.0 : 50.0));
set_pev(Ent, pev_origin, Origin);
set_pev(Ent, pev_velocity, Vel);
lightPoints[x] = Ent;
}
set_task(0.3, "Lightning", id);
return 1;
}
public Lightning(id)
{
new x, a, b, Rand;
static Endpoint = MAX_LIGHT_POINTS - 1;
while(x < Endpoint)
{
a = lightPoints[x];
b = lightPoints[x + 1];
x++;
if(x == Endpoint)
{
Rand = random(100);
if(Rand == 1)
b = id;
}
CreateBeam(a, b);
}
for(x = 0 ; x < MAX_LIGHT_POINTS ; x++)
{
if(pev_valid(lightPoints[x]))
engfunc(EngFunc_RemoveEntity, lightPoints[x]);
}
}
stock set_keyvalue(ent, key[], value[])
{
new classname[32];
pev(ent, pev_classname, classname, 31);
set_kvd(0, KV_ClassName, classname);
set_kvd(0, KV_KeyName, key);
set_kvd(0, KV_Value, value);
set_kvd(0, KV_fHandled, 0);
dllfunc(DLLFunc_KeyValue, ent, 0);
}
stock get_random_player()
{
new Cnt, Total[33];
new Players[32], Num, id;
get_players(Players, Num);
for(new i = 0 ; i < Num ; i++)
{
id = Players[i];
if(!is_user_alive(id))
continue;
if(is_user_outside(id))
Total[Cnt++] = id;
}
if(Cnt)
return Total[random(Cnt)];
return 0;
}
stock Float:is_user_outside(id)
{
new Float:origin[3], Float:dist;
pev(id, pev_origin, origin);
dist = origin[2];
while(engfunc(EngFunc_PointContents, origin) == -1)
origin[2] += 5.0;
if(engfunc(EngFunc_PointContents, origin) == -6)
return (origin[2] - dist);
return 0.0;
}
stock CreateBeam(id, Ent)
{
message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
write_byte(8);
write_short(id);
write_short(Ent);
write_short(lightBeam);
write_byte(0);
write_byte(10);
write_byte(5);
write_byte(8);
write_byte(100);
write_byte(200); //R
write_byte(200); //G
write_byte(255); //B
write_byte(255);
write_byte(10);
message_end();
}