AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   server crash because of precache (https://forums.alliedmods.net/showthread.php?t=296004)

Adomaz1 04-10-2017 04:36

server crash because of precache
 
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

Krtola 04-10-2017 11:06

Re: server crash because of precache
 
PHP Code:

for(new 0sizeof(SoundList); i++)
    
engfunc(EngFunc_PrecacheSoundSoundList[i]) 

Delete this and add this:
PHP Code:

for(new 0sizeof SoundListi++)
    
precache_sound(SoundList[i]) 

And this:
PHP Code:

new const SoundList[6][] 

:arrow:
PHP Code:

new const SoundList[][] 


EFFx 04-10-2017 11:29

Re: server crash because of precache
 
@Krtola

Quote:

Originally Posted by Krtola (Post 2510934)
And this:
PHP Code:

new const SoundList[6][] 

:arrow:
PHP Code:

new const SoundList[][] 


It's ok.

Code:
    for(new i = 0; i <= charsmax(Blood); i++)         g_Blood[i] = precache_model(Blood[i])

->

Code:
    for(new i = 0; i < sizeof (Blood); i++)         g_Blood[i] = precache_model(Blood[i])

D3XT3R 04-10-2017 14:47

Re: server crash because of precache
 
as i know server never crached if ther is no sounds.... should be prechase of models/sprites crached it.

EFFx 04-10-2017 14:54

Re: server crash because of precache
 
Read his post before say something. He already told what's causing the error.

Adomaz1 04-11-2017 10:55

Re: server crash because of precache
 
it's still the same. i tried checking the second time if the sounds are causing the problem. when I remove the precache, everything, except the sounds, work.

found out that 3 .wav files cause this, so what could be the problem with them?

DarthMan 04-11-2017 13:39

Re: server crash because of precache
 
Quote:

Originally Posted by Adomaz1 (Post 2511251)
it's still the same. i tried checking the second time if the sounds are causing the problem. when I remove the precache, everything, except the sounds, work.

found out that 3 .wav files cause this, so what could be the problem with them?

I usually don't answer to threads because I am so busy scripting, but I guess that the real reason behind all that is because the map you are testing the plugin on is already precaching about 512 sounds, so precaching mroe will basically go over the 512 limit that will crash the server.


All times are GMT -4. The time now is 18:04.

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