if someone has the time to go over this it would be aprecieated.
I have been having problems with it, and I can't figure out what is causing it.
It tends to just crash randomly. Sometimes at round end, and sometimes in the middle of the round. I don't know what I did wrong, and I haven't been able to get an error message.
Code:
#include <amxmod>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <fun>
#define resetcrap_offset 100
#define setweap_offset 200
#define checkspawn_offset 300
#define find_ent_by_class(%1,%2) engfunc(EngFunc_FindEntityByString, %1, "classname", %2)
new bool:Spawned[33]
new bool:brndStart
new bool:NVGOn[33]
new flashlight[33]
// pcvars
new s_bDlMax
new s_bSpeed
new s_bHealth
new s_bGravity
new s_bFlashR
new s_bFlashG
new s_bFlashB
new s_bFlashRAD
new s_bFlashDEC
new s_bFlashLIF
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//++++++++++ Client_ Events ++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
public client_connect(id)
{
Spawned[id] = false
flashlight[id] = 0
client_cmd(id,"cl_forwardspeed 1000;cl_sidespeed 1000;cl_backspeed 1000;cl_dlmax %i", get_pcvar_num(s_bDlMax))
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//++++++++++ Functions ++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
public startjump(id)
{
new Float:new_gravity = (get_pcvar_float(s_bGravity) / 800)
set_user_gravity(id,new_gravity)
return FMRES_SUPERCEDE
}
public stopjump(id)
{
set_user_gravity(id)
return FMRES_SUPERCEDE
}
public fullupdate(id)
{
new authid[35], name[32], team[32]
new userid = get_user_userid(id)
get_user_name(id,name,31)
get_user_authid(id,authid,34)
get_user_team(id,team,31)
client_print(0,print_chat,"%s<%d><%s><%s> - Possible Exploit Attempt.",name,userid,authid,team)
return FMRES_SUPERCEDE
}
public GatherResetCrap(id)
{
id -= resetcrap_offset
if (!is_user_alive(id) || !is_user_connected(id)) return FMRES_SUPERCEDE
if (get_user_team(id) == 1) {
cs_set_user_model(id,"zombie2")
NVGOn[id] = true
message_begin(MSG_ONE, get_user_msgid("NVGToggle"), {0,0,0}, id)
write_byte(1)
message_end()
set_pev(id,pev_health,get_pcvar_float(s_bHealth))
} else if (get_user_team(id) == 2) {
cs_reset_user_model(id)
NVGOn[id] = false
}
if (!task_exists(id + setweap_offset)) set_task(1.0,"SetWeaponModel",id + setweap_offset)
return FMRES_SUPERCEDE
}
public SetWeaponModel(id)
{
if (!brndStart) return FMRES_SUPERCEDE
id -= setweap_offset
if (!is_user_alive(id) || !is_user_connected(id) || get_user_team(id) != 1) return FMRES_SUPERCEDE
engclient_cmd(id,"weapon_knife")
set_pev(id,pev_maxspeed,get_pcvar_float(s_bSpeed))
set_pev(id, pev_viewmodel, engfunc(EngFunc_AllocString, "models/zombie/v_knife3.mdl"))
set_pev(id, pev_weaponmodel, engfunc(EngFunc_AllocString, ""))
return FMRES_SUPERCEDE
}
public checkspawn(id)
{
id -= checkspawn_offset
if (Spawned[id] == false && is_user_alive(id)) {
user_kill (id, 1)
client_print(id,print_chat,"Sorry. You spawned late.")
}
return FMRES_SUPERCEDE
}
public Remove_C4(id) {
if(!is_user_alive(id) || !is_user_connected(id)) return FMRES_IGNORED
engclient_cmd(id, "drop", "weapon_c4")
new ent
while ((ent = find_ent_by_class(get_maxplayers(), "weaponbox")) > 0) {
new model[33]
entity_get_string(ent, EV_SZ_model, model, 32)
if (equali(model, "models/w_backpack.mdl")) {
engfunc(EngFunc_RemoveEntity,ent)
server_print("Removed weapon_c4. Eid: %i",ent)
}
}
return FMRES_SUPERCEDE
}
public Remove_Hostages()
{
new ent
while ((ent = find_ent_by_class(get_maxplayers(), "hostage_entity")) > 0) {
engfunc(EngFunc_RemoveEntity,ent)
server_print("Removed hostage_entity. Eid: %i",ent)
}
return FMRES_SUPERCEDE
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//++++++++++ Forwards ++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
public Forward_PreThink(id)
{
if(!is_user_alive(id) || !is_user_connected(id) || is_user_bot(id)) return FMRES_IGNORED
if (get_user_team(id) == 1)
{
new button = pev(id,pev_button)
new oldbutton = pev(id,pev_oldbuttons)
new flags = pev(id,pev_flags)
// Low Grav Jump
if ((button & IN_JUMP) && !(oldbutton & IN_JUMP) && (is_user_alive(id)) && (flags & FL_ONGROUND)) {
startjump(id)
} else if(!(button & IN_JUMP) && (oldbutton & IN_JUMP)) {
stopjump(id)
}
// Show Health
set_hudmessage(200,0,0,0.01,0.18,0,1.0,2.0,0.5,0.15,1)
show_hudmessage(id,"Health: %i",get_user_health(id))
} else {
// CT Flashlight
if(flashlight[id])
{
new origin[3]
get_user_origin(id,origin,3)
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
write_byte(27) // TE_DLIGHT
write_coord(origin[0]) // X
write_coord(origin[1]) // Y
write_coord(origin[2]) // Z
write_byte(get_pcvar_num(s_bFlashRAD)) // radius
write_byte(get_pcvar_num(s_bFlashR)) // R
write_byte(get_pcvar_num(s_bFlashG)) // G
write_byte(get_pcvar_num(s_bFlashB)) // B
write_byte(get_pcvar_num(s_bFlashLIF)) // life
write_byte(get_pcvar_num(s_bFlashDEC)) // decay rate
message_end()
}
}
return FMRES_IGNORED
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//++++++++++ Events ++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
public event_resethud(id)
{
if (!task_exists(id + checkspawn_offset)) set_task(4.0,"checkspawn",id + checkspawn_offset)
}
public event_roundend()
{
brndStart = false
new players[32], player, num, i
get_players(players,num,"a")
for(i=0;i<num;i++) {
player = players[i]
Spawned[player] = false
}
}
public event_roundstart() // End of freeze time.
{
new players[32], player, num, i
get_players(players,num,"a")
for(i=0;i<num;i++) {
player = players[i]
if (is_user_alive(player) && is_user_connected(player)) {
Spawned[player] = true
if (!task_exists(player + resetcrap_offset) && player) {
new Float:task_delay = float((player / 5))
set_task(task_delay,"GatherResetCrap",player + resetcrap_offset)
}
if (get_user_team(player) == 1) {
client_print(player,print_chat,"Go kill all the Humans!")
} else if (get_user_team(player) == 2) {
client_print(player,print_chat,"Go kill all the Zombies!")
}
}
}
Remove_Hostages()
engfunc(EngFunc_LightStyle,0,"a")
brndStart = true
return FMRES_IGNORED
}
public event_curweapon(id)
{
SetWeaponModel(id + setweap_offset)
return FMRES_IGNORED
}
public event_flashlight(id)
{
if (!is_user_connected(id) || !is_user_alive(id)) return FMRES_SUPERCEDE
if (get_user_team(id) == 1) {
new Float:fHealthTest
pev(id,pev_health,fHealthTest)
switch(floatround(fHealthTest))
{
case 256,512,768,1024,1280,1536,1792,2048,1304,2560,2816,3072,3328,3584,3840:
{
set_pev(id,pev_health,fHealthTest + 1.0)
client_print(id,print_center,"**Fixed controls**")
}
default: client_print(id,print_center,"**If your controls are messed up, you can use this key to fix them**")
}
if (flashlight[id] != 0) flashlight[id] = 0
} else if (get_user_team(id) == 2) {
if (flashlight[id]) {
flashlight[id] = 0
} else {
flashlight[id] = 1
}
}
message_begin(MSG_ONE,get_user_msgid("Flashlight"),{0,0,0},id)
write_byte(flashlight[id])
write_byte(100)
message_end()
entity_set_int(id,EV_INT_effects,entity_get_int(id,EV_INT_effects) & ~EF_DIMLIGHT)
return FMRES_SUPERCEDE
}
public event_togglenvg(id)
{
if (!is_user_alive(id) || !is_user_connected(id)) return PLUGIN_HANDLED
if (NVGOn[id] == false && get_user_team(id) != 2 || !is_user_alive(id)) {
NVGOn[id] = true
message_begin(MSG_ONE, get_user_msgid("NVGToggle"), {0,0,0}, id)
write_byte(1)
message_end()
} else {
NVGOn[id] = false
message_begin(MSG_ONE, get_user_msgid("NVGToggle"), {0,0,0}, id)
write_byte(0)
message_end()
}
return FMRES_SUPERCEDE
}
public event_deathmsg()
{
new victim = read_data(2)
if (!is_user_connected(victim)) return FMRES_IGNORED
Spawned[victim] = false
flashlight[victim] = 0
return FMRES_IGNORED
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//++++++++++ Init and Precache ++++++++++//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
public plugin_init()
{
register_plugin("Zombie Mod Reborn","1.0","SgtBane")
// Forwards
register_forward(FM_PlayerPreThink,"Forward_PreThink")
// Events
register_logevent("event_roundstart", 2, "1=Round_Start")
register_logevent("event_roundend", 2, "1=Round_End")
register_event("DeathMsg","event_deathmsg","a")
register_event("CurWeapon","event_curweapon","be","1=1")
register_event("Flashlight","event_flashlight","b")
register_event("ResetHUD","event_resethud","be")
register_event("StatusIcon", "Remove_C4", "be", "1=1", "1=2", "2=c4")
register_clcmd("nightvision","event_togglenvg",0,"Toggles Night Vision")
// Hooks
register_clcmd("fullupdate","fullupdate")
s_bDlMax = register_cvar("sv_cl_dlmax","80")
s_bSpeed = register_cvar("zomb_speed","450")
s_bHealth = register_cvar("zomb_health","800")
s_bGravity = register_cvar("zomb_gravity","400")
s_bFlashR = register_cvar("zomb_flashlight_r","250")
s_bFlashG = register_cvar("zomb_flashlight_g","250")
s_bFlashB = register_cvar("zomb_flashlight_b","250")
s_bFlashRAD = register_cvar("zomb_flashlight_radius","8")
s_bFlashDEC = register_cvar("zomb_flashlight_decay","1")
s_bFlashLIF = register_cvar("zomb_flashlight_life","2")
server_cmd("sv_skycolor_r 0;sv_skycolor_g 0;sv_skycolor_b 0;mp_freezetime 3;mp_flashlight 1")
server_cmd("sv_maxspeed %i",get_pcvar_num(s_bSpeed))
return FMRES_IGNORED
}
public plugin_precache()
{
// Player Models
precache_model("models/player/zombie2/zombie2.mdl")
// Weapon Models
precache_model("models/zombie/v_knife3.mdl")
return FMRES_IGNORED
}
I know that fakemeta is tricky to work with, and that it will crash for prety much anything...
If anyone sees something I did wrong, or knows of a way I can optomize my code, then please feel free to post.
Ive tried to sort things... Its not the best though.
Thankyou anyone who helps.