AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   bug sma (https://forums.alliedmods.net/showthread.php?t=254852)

luciaus18 01-07-2015 08:17

bug sma
 
I get this in console server..i really want help on this plugin

Code:

Displaying debug trace (plugin "cso_santa.amxx")
[AMXX] Run time error 4: index out of bounds
[AMXX]    [0] cso_santa.sma::alegem_mosul (line 95)

This is the plugin, i edited with bold and red color lines where is the problem..if someone can take a look..

Code:

#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <fun>
#include <hamsandwich>
const PEV_NADE_TYPE = pev_flTimeStepSound
const NADE_TYPE_CHRISTMAS = 1111

new bool:mosul[33], event_sync, christmas_explode, g_trail, cvar_hp, cvar_ap, set_bomb, he_exp, last_use[33];

new const g_szSoundFile[] = "christmas_2014/hohoho.wav";
new const MODEL_SANTA[] = "santa_2014";
new const model_nade_world[] = "models/christmas_2014/chr_he_w.mdl";
new const model_nade_view[] = "models/christmas_2014/chr_he.mdl";
new const model_trail[] = "sprites/laserbeam.spr";
new const christmas_mdl[] = "models/christmas_2014/tree.mdl";
new const boom_tree[] = "christmas_2014/boom_tree.wav";
new snow;

new const sounds_exp[][] =
{
        "fvox/one.wav",
        "fvox/two.wav",
        "fvox/three.wav",
        "fvox/four.wav",
        "fvox/five.wav",
        "fvox/six.wav",
        "fvox/seven.wav",
        "fvox/eight.wav",
        "fvox/nine.wav",
        "fvox/ten.wav"
};

public plugin_init()
{
        register_plugin("Mos Craciun Apaaare", "1.0", "cyby")
       
        register_logevent("alegem_mosul", 2, "1=Round_Start")
        register_event("DeathMsg", "moarte", "a")
        register_message(get_user_msgid("TextMsg"), "msg_textmsg")
        RegisterHam(Ham_Spawn, "player", "spawn_post", 1)
        register_forward(FM_SetClientKeyValue, "Block_Command_Model")
        register_event("CurWeapon", "bull_christmas", "be", "1=1", "2=4", "2=9", "2=25")
        register_forward(FM_SetModel, "forward_model")
        RegisterHam(Ham_Think, "grenade", "think_grenade")
        RegisterHam(Ham_BloodColor, "player", "blood_color")
        cvar_hp = register_cvar("santa_hp", "200")
        cvar_ap = register_cvar("santa_ap", "200")
       
        register_clcmd("drop", "use_skill")
       
        event_sync = CreateHudSyncObj()
        christmas_explode = CreateHudSyncObj()
        server_cmd("sv_skyname space")
}

public plugin_precache()
{
        engfunc(EngFunc_PrecacheModel, model_nade_world)
        precache_model(model_nade_view)
        precache_sound(g_szSoundFile)
        he_exp = precache_model("sprites/chr_he.spr")
        g_trail = engfunc(EngFunc_PrecacheModel, model_trail)
       
        new mdl_santa[50];
        formatex(mdl_santa, charsmax(mdl_santa) - 1, "models/player/%s/%s.mdl", MODEL_SANTA, MODEL_SANTA);
        precache_model(mdl_santa)
        precache_model(christmas_mdl)
        precache_sound(boom_tree)
       
        snow = precache_model("sprites/frost_gib.spr")
        create_entity("env_snow")

        for(new i = 0; i < sizeof sounds_exp; i++)
                precache_sound(sounds_exp[i])
}

public plugin_natives()
{
        register_native("get_santa", "native_get_santa", 1)
        register_native("set_santa", "native_set_santa", 1)
}

public alegem_mosul()
{
        new jucatori[32], num;
        get_players(jucatori, num, "e", "CT")
        static iPlayersnum
        iPlayersnum = get_alives()
        if(iPlayersnum < 1)
                return;
        static mos;
        mos = jucatori[random(num)]
        if(!is_user_connected(mos) || !is_user_alive(mos) || get_user_team(mos) != 2)
        {
                alegem_mosul()
                return;
        }
        new nume[32];
        get_user_name(mos, nume, charsmax(nume) - 1)
        color(0, ".e[Server].v %s.g Is Mosul. He must save Christmas.", nume)
        set_hudmessage(random(256), random(256), random(256), 0.03, 0.72, 1, 6.1, 6.0)
        ShowSyncHudMsg(0, event_sync, "%s A FOST ALES MOS!", nume)
        set_santa(mos)
}


public check_nades(id)
{
        if(!is_user_alive(id) || !mosul[id] || !is_user_connected(id))
        {
                remove_task(id)
                return PLUGIN_HANDLED;
        }
       
        if(!user_has_weapon(id, CSW_HEGRENADE))
                give_item(id, "weapon_hegrenade")
               
        new Float:fOrigin[3], iOrigin[3]
        pev(id, pev_origin, fOrigin)
        FVecIVec(fOrigin, iOrigin)
        UTIL_CreateFlares(iOrigin, snow, random_num(1, 2), 1, random_num(1, 2))
        return PLUGIN_HANDLED;
}

public set_another(id)
{
        if(!is_user_alive(id) || !mosul[id] || !is_user_connected(id))
        {
                remove_task(id)
                return PLUGIN_HANDLED;
        }
       
        set_user_rendering(id, kRenderFxGlowShell, random(256), random(256), random(256), kRenderNormal, 18)
        static origin[3]
        get_user_origin(id, origin)
       
        message_begin(MSG_PVS, SVC_TEMPENTITY, origin)
        write_byte(TE_DLIGHT) // TE id
        write_coord(origin[0]) // x
        write_coord(origin[1]) // y
        write_coord(origin[2]) // z
        write_byte(20) // radius
        write_byte(random(256)) // r
        write_byte(random(256)) // g
        write_byte(random(256)) // b
        write_byte(1) // life
        write_byte(0) // decay rate
        message_end()
        return PLUGIN_HANDLED;
}

public blood_color(id)
{
        if(mosul[id])
        {
                SetHamReturnInteger(245)
                return HAM_SUPERCEDE;
        }
        return HAM_IGNORED;
}

public client_disconnect(id)
        mosul[id] = false

public moarte()
{
        new attacker, victim;
        attacker = read_data(1)
        victim = read_data(2)
        if(victim == attacker || !is_user_connected(victim) || !is_user_connected(attacker))
                return
       
        if(mosul[victim])
        {
                new name[32];
                get_user_name(victim, name, charsmax(name) - 1)
                set_hudmessage(random(256), random(256), random(256), 0.03, 0.72, 1, 6.1, 6.0)
                ShowSyncHudMsg(0, event_sync, "%s A MURIT MOSUL!", name)
                color(0, ".v[Server].g Santa is dead:.e %s.g.", name)
                mosul[victim] = false
        }
}

public msg_textmsg()
{
        static textmsg[22]
        get_msg_arg_string(2, textmsg, charsmax(textmsg))
       
        if(equal(textmsg, "#Terrorists_Win"))
        {
                set_hudmessage(0, 50, 255, -1.0, 0.16, 1, 5.0, 5.0)
                ShowSyncHudMsg(0, event_sync, "Craciunul a fost salvat!^nMos Craciun a salvat cadourile!")
                return PLUGIN_HANDLED;
        }
       
        if(equal(textmsg, "#CTs_Win"))
        {
                set_hudmessage(0, 50, 255, -1.0, 0.16, 1, 5.0, 5.0)
                ShowSyncHudMsg(0, event_sync, "Craciunul a fost salvat!^nMos Craciun a salvat cadourile!")
                return PLUGIN_HANDLED;
        }
        return PLUGIN_CONTINUE;
}

public spawn_post(id)
{
        if(get_user_team(id) == 3 || !is_user_alive(id) || !is_user_connected(id))
                return;
       
        switch(get_user_team(id))
        {
                case 1: cs_set_user_model(id, "leet")
                case 2: cs_set_user_model(id, "gign")
        }
        set_user_rendering(id)
        mosul[id] = false
}

public Block_Command_Model(id, const infobuffer[], const key[])
{
        if(equal(key, "model"))
                return FMRES_SUPERCEDE;

        return FMRES_IGNORED;
}

public bull_christmas(id)
{
        if(mosul[id])
                set_pev(id, pev_viewmodel2, model_nade_view)
}
       
public forward_model(entity, const model[])
{
        if(!pev_valid(entity))
                return FMRES_IGNORED

        if(model[0] == 'm' && model[7] == 'w' && model[8] == '_')
        {
                switch(model[9])
                {
                        case 'h' :
                        {
                                static attacker
                                attacker = pev(entity, pev_owner)
                                if(mosul[attacker])
                                {
                                        engfunc(EngFunc_SetModel, entity, model_nade_world)
                                        fm_set_trail(entity, 255, 255, 255, 255)
                                        fm_set_rendering(entity, kRenderFxGlowShell, 255, 255, 255, kRenderNormal, 255)
                                        set_pev(entity, PEV_NADE_TYPE, NADE_TYPE_CHRISTMAS)
                                        return FMRES_SUPERCEDE
                                }
                        }
                }
        }
        return FMRES_IGNORED
}

public think_grenade(entity)
{
        if (!pev_valid(entity)) return FMRES_IGNORED;
       
        static Float:dmgtime, Float:current_time
        pev(entity, pev_dmgtime, dmgtime)
        current_time = get_gametime()
       
        if(dmgtime > current_time)
                return FMRES_IGNORED;
       
        static attacker
        attacker = pev(entity, pev_owner)
        if(mosul[attacker])
        {       
                switch(pev(entity, PEV_NADE_TYPE))
                {
                        case NADE_TYPE_CHRISTMAS:
                        {
                                christmas_effect(entity)
                                return FMRES_SUPERCEDE;
                        }
                }
        }
        return FMRES_IGNORED;
}

public christmas_effect(id)
{
        new Float:fOrigin[3];
        pev(id, pev_origin, fOrigin)
       
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(TE_EXPLOSION)
        engfunc(EngFunc_WriteCoord, fOrigin[0])
        engfunc(EngFunc_WriteCoord, fOrigin[1])
        engfunc(EngFunc_WriteCoord, fOrigin[2])
        write_short(he_exp)
        write_byte(40)
        write_byte(30)
        write_byte(TE_EXPLFLAG_NONE)
        message_end()
       
        static attacker
        attacker = pev(id, pev_owner)
       
        if(!is_user_connected(attacker))
        {
                engfunc(EngFunc_RemoveEntity, id)
                return;
        }
       
        static victim
        victim = -1
        while((victim = engfunc(EngFunc_FindEntityInSphere, victim, fOrigin, 240.0)) != 0)
        {
                if(!is_user_alive(victim) || mosul[victim] || get_user_team(attacker) == get_user_team(victim))
                        continue;
               
                new Float:flVictimOrigin[3]
                pev(victim, pev_origin, flVictimOrigin)
                new Float:flDistance = get_distance_f(fOrigin, flVictimOrigin) 
                if(flDistance <= 240.0)
                {
                        static Float:flSpeed
                        flSpeed = 800.0

                        static Float:flNewSpeed
                        flNewSpeed = flSpeed * (1.0 - (flDistance / 240.0))

                        static Float:flVelocity[3]
                        get_speed_vector(fOrigin, flVictimOrigin, flNewSpeed, flVelocity)

                        set_pev(victim, pev_velocity, flVelocity)
                }
                if(get_user_health(victim) - 5 >= 1)
                        fm_fakedamage(victim, "santa-snowball", 5.0,  DMG_BLAST);
                else
                        set_user_health(victim, 1)
                       
                ShakeScreen(victim, 3.9)
        }

        engfunc(EngFunc_RemoveEntity, id)
}

public use_skill(id)
{
        if(mosul[id] && (get_user_weapon(id) == CSW_KNIFE))
        {
                plant_tree(id)
                return PLUGIN_HANDLED;
        }
        return PLUGIN_CONTINUE;
}

plant_tree(id)
{
        if(last_use[id] > get_systime(0))
        {
                color(id, ".v[Server].g Wait.e %d.g seconds to use the power.", last_use[id] - get_systime(0))
                return
        }
       
        if(set_bomb > 0)
        {
                color(id, ".v[Server].g Already planted a tree!")
                return
        }

        new bombent
        bombent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))

        set_pev(bombent, pev_classname, "christmas_tree")
        engfunc(EngFunc_SetModel, bombent, christmas_mdl)
       
        set_task(1.0, "task_effects", bombent, _, _, "b")
       
        set_bomb = random_num(15, 25)

        new Float:PlayerOrigin[3]
        pev(id, pev_origin, PlayerOrigin)

        engfunc(EngFunc_SetSize, bombent, Float:{-4.0, -4.0, 2.0}, Float:{4.0, 4.0, 10.0})
        engfunc(EngFunc_SetOrigin, bombent, PlayerOrigin)
        set_pev(bombent, pev_solid, SOLID_NOT)
        set_pev(bombent, pev_movetype, MOVETYPE_TOSS)
        set_pev(bombent, pev_owner, id)

        emit_sound(bombent, CHAN_WEAPON, g_szSoundFile, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)

        color(0, ".v[Server].g Santa fir tree planted.")
        last_use[id] = get_systime(30)

        return
}

public set_santa(id)
{
        mosul[id] = true
        set_task(0.3, "check_nades", id, _, _, "b")
        set_task(0.1, "set_another", id, _, _, "b")
        cs_set_user_model(id, MODEL_SANTA)
        set_user_health(id, get_pcvar_num(cvar_hp))
        set_user_armor(id, get_pcvar_num(cvar_ap))
        fm_set_trail(id, random(256), random(256), random(256), 190)
        emit_sound(id, CHAN_VOICE, g_szSoundFile, 0.25, ATTN_NORM, 0, PITCH_NORM);
}       

public task_effects(ent)
{
        if(!pev_valid(ent))
        {       
                remove_task(ent)
                return PLUGIN_HANDLED;
        }
       
        if(set_bomb <= 1)
        {
                remove_task(ent)
                new Float:fOrigin[3], iOrigin[3]
                pev(ent, pev_origin, fOrigin)
                FVecIVec(fOrigin, iOrigin)
                UTIL_CreateFlares(iOrigin, snow, random_num(66, 96), 3, random_num(6, 16))
               
                static victim
                victim = -1
                while((victim = engfunc(EngFunc_FindEntityInSphere, victim, fOrigin, 270.0)) != 0)
                {
                        if(!is_user_alive(victim) || mosul[victim] || get_user_team(victim) == 2)
                                continue;
                       
                        new Float:flVictimOrigin[3]
                        pev(victim, pev_origin, flVictimOrigin)
                        new Float:flDistance = get_distance_f(fOrigin, flVictimOrigin) 
                        if(flDistance <= 270.0)
                        {
                                static Float:flSpeed
                                flSpeed = 16800.0

                                static Float:flNewSpeed
                                flNewSpeed = flSpeed * (1.0 - (flDistance / 270.0))

                                static Float:flVelocity[3]
                                get_speed_vector(fOrigin, flVictimOrigin, flNewSpeed, flVelocity)

                                set_pev(victim, pev_velocity, flVelocity)
                        }
                        if(get_user_health(victim) - 15 >= 1)
                                fm_fakedamage(victim, "christmas-three", 15.0,  DMG_BLAST);
                        else
                                set_user_health(victim, 1)
                               
                        ShakeScreen(victim, 20.9)
                }
               
                while((victim = engfunc(EngFunc_FindEntityInSphere, victim, fOrigin, 600.0)) != 0)
                {
                        if(!is_user_alive(victim))
                                continue;
                       
                        ShakeScreen(victim, 14.9)
                }
               
                set_hudmessage(random(256), random(256), random(256), -1.0, 0.0, 1, 1.1, 1.0)
                ShowSyncHudMsg(0, christmas_explode, "Pomul de craciun a explodat.")
                emit_sound(ent, CHAN_WEAPON, boom_tree, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
               
                engfunc(EngFunc_RemoveEntity, ent)
                set_bomb = 0
                return PLUGIN_HANDLED;
        }
       
        new Float:fOrigin[3], iOrigin[3];
        pev(ent, pev_origin, fOrigin)
       
        set_bomb--
        if(set_bomb <= 10 && set_bomb > 0)
        {
                new numar[32]
                num_to_word(set_bomb, numar, 31)
                client_cmd(0, "spk fvox/%s", numar)
        }
        set_hudmessage(random(256), random(256), random(256), -1.0, 0.0, 1, 1.1, 1.0)
        ShowSyncHudMsg(0, christmas_explode, "Pomul de craciun o sa explodeze in %d secund%s", set_bomb, set_bomb < 2 ? "a" : "e")
        fm_set_rendering(ent, kRenderFxGlowShell, random(256), random(256), random(256), kRenderNormal, 20)
        FVecIVec(fOrigin, iOrigin)
        UTIL_CreateFlares(iOrigin, snow, random_num(4, 6), 1, random_num(3, 4))
        return PLUGIN_HANDLED
}

get_alives()
{
        static iAlive, id
        iAlive = 0
       
        for (id = 1; id <= get_maxplayers(); id++)
        {
                if(is_user_alive(id))
                        iAlive++
        }
       
        return iAlive;
}

public ShakeScreen(id, const Float:seconds)
{
        message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("ScreenShake"), {0, 0, 0}, id)
        write_short(floatround(4096.0 * seconds, floatround_round))
        write_short(floatround(4096.0 * seconds, floatround_round))
        write_short(1<<13)
        message_end()
}

stock color(const id, const input[], any:...)
{
        new count = 1, players[32]
        static msg[191]
        vformat(msg, 190, input, 3)
       
        replace_all(msg, 190, ".v", "^4")
        replace_all(msg, 190, ".g", "^1")
        replace_all(msg, 190, ".e", "^3")
       
        if (id) players[0] = id;
        else get_players(players, count, "ch")
        {
                for (new i = 0; i < count; i++)
                {
                        if (is_user_connected(players[i]))
                        {
                                message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
                                write_byte(players[i])
                                write_string(msg)
                                message_end()
                        }
                }
        }
}

stock fm_set_trail(id, r, g, b, bright)
{
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(TE_BEAMFOLLOW)             
        write_short(id)       
        write_short(g_trail)       
        write_byte(25)             
        write_byte(5)             
        write_byte(r)           
        write_byte(g)             
        write_byte(b)               
        write_byte(bright)               
        message_end()
}

stock UTIL_CreateFlares(const iOrigin[3], const iSpriteID, const iCount, const iLife, const iScale)
{
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(TE_SPRITETRAIL);
        write_coord(iOrigin[0]);                                // start position (X)
        write_coord(iOrigin[1]);                                // start position (Y)
        write_coord(iOrigin[2]);                                // start position (Z)
        write_coord(iOrigin[0]);                                // end position (X)
        write_coord(iOrigin[1]);                                // end position (Y)
        write_coord(iOrigin[2] + random_num(40, 50));        // end position (Z)
        write_short(iSpriteID);                                // sprite index
        write_byte(iCount);                                        // numarul de bule
        write_byte(iLife);                                        // life in 0.1's
        write_byte(iScale);                                        // scale in 0.1's
        write_byte(random_num(30, 50));                                // velocity along vector in 10's
        write_byte(random_num(10, 15));                                // randomness of velocity in 10's
        message_end();
}

stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
{
        new_velocity[0] = origin2[0] - origin1[0]
        new_velocity[1] = origin2[1] - origin1[1]
        new_velocity[2] = origin2[2] - origin1[2]
        new Float:num = floatsqroot(speed*speed /  (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] +  new_velocity[2]*new_velocity[2]))
        new_velocity[0] *= num
        new_velocity[1] *= num
        new_velocity[2] *= num
        return 1;
}

stock Create_TE_LARGEFUNNEL(position[3], iSprite, flags)
{
        message_begin( MSG_BROADCAST, SVC_TEMPENTITY );   
        write_byte( TE_LARGEFUNNEL );
        write_coord( position[0] );        // origin, x
        write_coord( position[1] );        // origin, y
        write_coord( position[2] );        // origin, z
        write_short( iSprite );            // sprite (0 for none)
        write_short( flags );            // 0 for collapsing, 1 for sending outward
        message_end();
}

public native_get_santa(id)
{
        return mosul[id]
}

public native_set_santa(id)
{
        set_santa(id)
}


akcaliberg 01-07-2015 10:04

Re: bug sma
 
EDIT: I was wrong about random(num).

------------------

By the way you don't need decrement when you are using charsmax.

nume[32]

sizeof(nume) = 32
charsmax(nume) = 31

get_user_name(mos, nume, charsmax(nume) - 1)

->

get_user_name(mos, nume, charsmax(nume))

luciaus18 01-07-2015 14:19

Re: bug sma
 
I have to change only this?
Quote:

public alegem_mosul()
{
new jucatori[32], num;
get_players(jucatori, num, "e", "CT")
static iPlayersnum
iPlayersnum = get_alives()
if(iPlayersnum < 1)
return;
static mos;
mos = jucatori[random(num-1)]
if(!is_user_connected(mos) || !is_user_alive(mos) || get_user_team(mos) != 2)
{
alegem_mosul()
return;
}
new nume[32];
get_user_name(mos, nume, charsmax(nume))
color(0, ".e[Server].v %s.g Is Mosul. He must save Christmas.", nume)
set_hudmessage(random(256), random(256), random(256), 0.03, 0.72, 1, 6.1, 6.0)
ShowSyncHudMsg(0, event_sync, "%s A FOST ALES MOS!", nume)
set_santa(mos)
}
If you can show me what i have to change with bold and red color in plugin..i changed these 2 but i still get bug

akcaliberg 01-07-2015 16:19

Re: bug sma
 
Is the error same ? What is the new error messages?

luciaus18 01-07-2015 16:57

Re: bug sma
 
yes is the same error and i changed what you see with bold and red color

akcaliberg 01-08-2015 06:23

Re: bug sma
 
My bad. random(max) returns a random number between 0 and max-1.

So random(num) was actually right.

When are these messages shown exactly?

Add this
PHP Code:

client_print(0,print_chat,"num = %d",num

before this

PHP Code:

mos jucatori[random(num)] 

And tell me what is the result when the error shows up.

luciaus18 01-08-2015 08:57

Re: bug sma
 
every time when round start is this message, doesn't work :(


All times are GMT -4. The time now is 15:25.

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