|
Senior Member
|

04-10-2017
, 04:36
server crash because of precache
|
#1
|
hello, my server crashes because it doesn't precache the sound files, I think.
Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <xs>
#include <cstrike>
#include <gunxpmod>
#define NAME "tttt"
#define VERSION "1.0"
#define AUTHOR "ruslik1229"
#define KNIFE_GRAVITY 0.80
#define KNIFE_SPEED 310.0
#define SEC_DMG 2.0
#define PRIM_DMG 5.0
#define SEC_HEAD_DMG 6.0
#define PRIM_HEAD_DMG 10.0
#define KNIFE_KNOCK 4
#define BLOOD 3
new const v_knife[] = "models/v_katana.mdl"
new const p_knife[] = "models/p_katana.mdl"
new const SoundList[6][] =
{
"weapons/k_deploy1.wav", // 0
"weapons/k_hwall.wav", // 1
"weapons/k_slash1.wav", // 2
"weapons/k_stab.wav", // 3
"weapons/katana1.wav", // 4
"weapons/katana2.wav" // 5
}
new const Blood[][] =
{
"sprites/blood.spr",
"sprites/bloodspray.spr"
}
new g_Blood[sizeof Blood]
new bool:Knife[33]
public plugin_init()
{
register_plugin(NAME, VERSION, AUTHOR)
register_gxm_item("Katana", "Heat seeking grenade", 75, 10, 1, 0, CSW_KNIFE)
register_event("CurWeapon", "ChangeModel", "be", "1=1")
RegisterHam(Ham_TakeDamage, "player", "TakeDamage_Pre", 0)
RegisterHam(Ham_TakeDamage, "player", "TakeDamage_Post", 1)
RegisterHam(Ham_Player_PreThink, "player", "PreThink")
register_forward(FM_EmitSound, "KnifeSound")
}
public plugin_precache()
{
precache_model(v_knife)
precache_model(p_knife)
for(new i = 0; i < sizeof(SoundList); i++)
engfunc(EngFunc_PrecacheSound, SoundList[i])
for(new i = 0; i <= charsmax(Blood); i++)
g_Blood[i] = precache_model(Blood[i])
}
public gxm_item_enabled(id)
{
Knife[id] = true
}
public client_connect(id)
{
Knife[id] = false
}
public ChangeModel(id)
{
if(!is_user_alive(id) || cs_get_user_team(id) == CS_TEAM_T)
return
static weaponid
weaponid = read_data(2)
if(!Knife[id] || weaponid != CSW_KNIFE)
return
set_pev(id, pev_viewmodel2, v_knife)
set_pev(id, pev_weaponmodel2, p_knife)
}
public KnifeSound(id, channel, sample[], Float:volume, Float:attn, flags, pitch)
{
if(!equal(sample, "weapons/knife_", 14) || !Knife[id])
return FMRES_IGNORED
if(equal(sample[8], "knife_hitwall", 13))
emit_sound(id, channel, SoundList[1], volume, attn, flags, pitch)
else
if(equal(sample[8], "knife_hit", 9))
switch(random(2))
{
case 0: emit_sound(id, channel, SoundList[4], volume, attn, flags, pitch)
case 1: emit_sound(id, channel, SoundList[5], volume, attn, flags, pitch)
}
if(equal(sample[8], "knife_slash", 11)) { emit_sound(id, channel, SoundList[2], volume, attn, flags, pitch); }
if(equal(sample[8], "knife_stab", 10)) { emit_sound(id, channel, SoundList[3], volume, attn, flags, pitch); }
if(equal(sample[8], "knife_deploy", 12)) { emit_sound(id, channel, SoundList[0], volume, attn, flags, pitch); }
return FMRES_SUPERCEDE
}
public TakeDamage_Pre(victim, inflictor, attacker, Float:damage, damagetype)
{
if(!is_user_alive(attacker))
return HAM_IGNORED
if(!Knife[attacker] || get_user_weapon(attacker) != CSW_KNIFE)
return HAM_IGNORED
if(cs_get_user_team(attacker) == CS_TEAM_T)
return HAM_IGNORED
new hit, target
get_user_aiming(attacker, target, hit)
new bool:head = (hit == HIT_HEAD)
new Float:mult_dmg = 1.0
if(pev(attacker, pev_button, IN_ATTACK))
mult_dmg = head ? PRIM_HEAD_DMG : PRIM_DMG
else
mult_dmg = head ? SEC_HEAD_DMG : SEC_DMG
SetHamParamFloat(4, damage * mult_dmg)
return HAM_HANDLED
}
public TakeDamage_Post(victim, inflictor, attacker, Float:damage, damagetype)
{
if(!is_user_alive(attacker) || !is_user_alive(victim))
return HAM_IGNORED
if(!Knife[attacker] || get_user_weapon(attacker) != CSW_KNIFE)
return HAM_IGNORED
if(cs_get_user_team(attacker) == CS_TEAM_T)
return HAM_IGNORED
new Float:Origin[3], Float:Origin2[3], Float:Velocity[3]
pev(attacker, pev_origin, Origin)
pev(victim, pev_origin, Origin2)
xs_vec_sub(Origin2, Origin, Velocity)
xs_vec_normalize(Velocity, Velocity)
xs_vec_mul_scalar(Velocity, (KNIFE_KNOCK * 100.0), Velocity)
if(Velocity[2] <= 100.0)
Velocity[2] = random_float(150.0, 250.0)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
write_byte(TE_BLOODSPRITE);
engfunc(EngFunc_WriteCoord, Origin2[0])
engfunc(EngFunc_WriteCoord, Origin2[1])
engfunc(EngFunc_WriteCoord, Origin2[2])
write_short(g_Blood[0])
write_short(g_Blood[1])
write_byte(77)
write_byte(BLOOD)
message_end()
set_pev(victim, pev_velocity, Velocity)
return HAM_HANDLED
}
public PreThink(id)
{
if(!is_user_alive(id)) return HAM_IGNORED
if(!Knife[id]) return HAM_IGNORED
if(cs_get_user_team(id) == CS_TEAM_T) return HAM_IGNORED
set_pev(id, pev_gravity, KNIFE_GRAVITY)
set_pev(id, pev_maxspeed, KNIFE_SPEED)
return HAM_HANDLED
}
but when I remove this:
Code:
for(new i = 0; i < sizeof(SoundList); i++)
engfunc(EngFunc_PrecacheSound, SoundList[i])
then the plugin doesn't crash the server, but then the sounds wouldn't work. what's the problem here? :s
|
|