Raised This Month: $32 Target: $400
 8% 

Run time error 4: index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-02-2020 , 14:31   Re: Run time error 4: index out of bounds
Reply With Quote #11

Again, you're not gonna get the best answer without the relevant code but I would say just remove them without the check.
Code:
remove_task(task-taskid); remove_task(task-taskid1);
But it should probably be like this...
Code:
remove_task(task); remove_task(task-taskid+taskid1);
...or for readability...
Code:
new id = task - taskid; remove_task(id + taskid); remove_task(id + taskid1);

It's kind of weird removing a task without any preconditions though. It seems like you're using the "b" flag without any reason. If you're not using the "a" or "b" flag then it's already removed once it's executed.
__________________

Last edited by Black Rose; 08-02-2020 at 14:34.
Black Rose is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 08-02-2020 , 15:02   Re: Run time error 4: index out of bounds
Reply With Quote #12

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <hamsandwich>
#include <zombieplague>

#define PLUGIN "Regular Zombie CSO-LIKE"
#define VERSION "1.0"
#define AUTHOR "DeclineD"

#define countdowntimer 20.0
#define countdown2timer 10.0
#define countdownover 20
#define countdown2over 10
#define countdown 10
#define countdowntwo 5
#define abilityend 10.0

//TaskIds//
#define taskhud 32135
#define taskhud1 23124
#define taskhud2 42151
#define taskhud3 29311
#define taskability 31276
#define taskability1 5132
#define taskend 62343
#define taskready 77345
#define taskready1 482731

const hp 15000
const speed 240
new Float:gravity 0.300
new Float:knockback 1.0
new Ready[33]
new 
Ready2[33]
new 
abilityended[33]
new 
abilitystarted[33]

new 
g_ent_playermodel[33
new 
regular
new saytext
new const zombieh[] = { "v_regular.mdl" }
new const 
zombiemodel1[] = { "regularzombie" }
new const 
zombiemodel2[] = { "regularzombiehost"}
new const 
bothmodels[] = { "regularzombie""regularzombiehost" }
new const 
ability1start[] = { "csolike/zombiepressure.wav" }
new const 
ability1pre[] = { "csolike/pre1.wav" }
new const 
ability1end[] = { "csolike/pre2.wav" }
new const 
infectsound[] = { "csolike/regularinfect.wav" }
new const 
hit[] = { "csolike/hit1.wav""csolike/hit2.wav"}
new const 
deathsound[] = { "csolike/death1.wav""csolike/death2.wav" }
new const 
health[] = {
    
2000,
    
3000,
    
4000,
    
5000
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("+drop","ability1")
    
register_clcmd("+reload","ability2")
    
register_concmd("+drop","ability1")
    
register_concmd("+reload","ability2")
    
regular zp_register_zombie_class("\r[\yCSO-LIKE\r]Regular Zombie","\r[\yBerserk\r|\yReproduce\r]",bothmodels ,zombieh,hp,speed,gravity,knockback)
    
RegisterHam(Ham_TakeDamage,"player","dmg")
    
saytext get_user_msgid("SayText")
    
register_event("DeathMsg","death","a")
    
}
public 
plugin_precache()
{
    
precache_sound(ability1start)
    
precache_sound(ability1end)
    
precache_sound(ability1pre)
    
precache_sound(infectsound)
    
precache_sound(hit)
    
precache_sound(deathsound)
    
precache_model("models/player/regularzombiehost/regularzombiehost.mdl")
    
precache_model("models/player/regularzombie/regularzombie.mdl")
}
public 
death(id)
{
    if(!
zp_get_user_zombie(id) && zp_get_user_zombie_class(id) != regular && zp_get_user_nemesis(id))
    return 
PLUGIN_CONTINUE;
    
    
emit_sound(idCHAN_VOICEdeathsound1.0ATTN_NORM0PITCH_NORM)
    
    return 
PLUGIN_HANDLED
}
    
public 
zp_user_infected_post(id)
{
    if((
zp_get_user_zombie_class(id) == regular) && zp_get_user_zombie(id) && !zp_get_user_nemesis(id))
    return

    if(
zp_get_user_first_zombie(id))
    {
        
fm_set_playermodel_ent(id,zombiemodel2,0)
        
emit_sound(id,CHAN_VOICE,infectsound,1.0,ATTN_NORM,0,PITCH_NORM)
        
Ready[id] = 1
        Ready2
[id] = 1
        set_task
(1.0,"hudready",id taskready,_,_,"b")
        
set_task(1.0,"hudready1",id taskready1,_,_,"b")
    }
    else {
            
        
fm_set_playermodel_ent(id,zombiemodel1,0)
        
emit_sound(id,CHAN_VOICE,infectsound,1.0,ATTN_NORM,0,PITCH_NORM)
        
Ready[id] = 1
        Ready2
[id] = 1
        set_task
(1.0,"hudready",id taskready,_,_,"b")
        
set_task(1.0,"hudready1",id taskready1,_,_,"b")
    }
}

public 
zp_user_humanized_post(task)
{
    new 
id task taskhud
    
new id1 task taskhud1
    
new id2 task taskhud2
    
new id3 task taskhud3
    
new id4 task taskability
    
new id5 task taskend
    
new id6 task taskready
    
new id7 task taskability1
    
    remove_task
(id)
    
remove_task(id1)
    
remove_task(id2)
    
remove_task(id3)
    
remove_task(id4)
    
remove_task(id5)
    
remove_task(id6)
    
remove_task(id7)
}
public 
hudready(id)
{
    
set_hudmessage(12725585, -1.00.8306.00.9)
    
show_hudmessage(id"[Berserk - Ready] [G]")
}
public 
hudready1(id)
{
    
set_hudmessage(12725585, -1.00.8306.00.9)
    
show_hudmessage(id"^n[Reproduce - Ready] [R]")
}
public 
hudrecharge(id)
{
    new 
cooldown = (countdownover 1)
    
    
set_hudmessage(12725585, -1.00.8306.00.9)
    
show_hudmessage(id"[Berserk - %d] [G]",cooldown 1)
}
public 
hudrecharge1(id)
{
    new 
cooldown2 = (countdown2over 1)
    
    
set_hudmessage(12725585, -1.00.8306.00.9)
    
show_hudmessage(id"^n[Reproduce - %d] [R]",cooldown2 1)
}
public 
ability1(id)
{
    new 
fov 130
    
new uspeed 700

    
switch(Ready[id])
    {
        case 
1:{
            
fm_set_rendering(idkRenderFxGlowShell,255,0,0,kRenderNormal,20)
            
set_pev(id,pev_fovfov)
            
set_pev(id,pev_maxspeeduspeed)

            
set_task(abilityend,"abend",id taskend)
            
set_task(countdowntimer,"ready",id taskready)
            
set_task(1.0,"hudrecharge",id taskhud2,_,_,"b")

            
abilityended[id] = 0
            abilitystarted
[id] = 1
            Ready
[id] = 0
            
            emit_sound
(id,CHAN_VOICE,ability1start,1.0,ATTN_NORM,0,PITCH_NORM)
        }
        case 
0: {
            
message_begin(MSG_ONE,saytext,{0,0,0},id)
            
write_byte(id)
            
write_string("^x04[ZOMBIE]^x01Wait 'till Berserk is available")
            
message_end()
        }
    }
    return 
PLUGIN_CONTINUE
}

public 
abend(id)
{
    
abilityended[id] = 1
    abilitystarted
[id] = 0
    
new fovn 110
    set_pev
(id,pev_fovfovn)
    
set_pev(id,pev_maxspeedspeed)
}
public 
ready(id)
{
    
Ready[id] = 1
    set_task
(1.0,"hudready",id taskhud,_,_,"b")
}
public 
ready2(id)
{
    
Ready2[id] = 1
    set_task
(1.0,"hudready1",id taskhud1,_,_,"b")
}
    
public 
ability2(id)
{
    if(!
zp_get_user_zombie(id) && zp_get_user_zombie_class(id) != regular && zp_get_user_nemesis(id))
    return 
PLUGIN_CONTINUE;

    switch(
Ready2[id])
    {
        case 
1:{
                new 
healthnum

                healthnum 
random_num(0,charsmax(health))
                new 
userhealth[33
                
userhealth[id] = get_user_health(id)
                
                
set_user_health(id,userhealth[id] + health[healthnum])
                
set_task(countdown2timer,"hudrecharge1",id taskready1,_,_,"b")
                
                
emit_sound(id,CHAN_VOICE,ability1pre,1.0,ATTN_NORM,0,PITCH_NORM)
                
Ready2[id] = 0
        
}
        case 
0: {
                
message_begin(MSG_ONE,saytext,{0,0,0},id)
                
write_byte(id)
                
write_string("^x04[ZOMBIE]^x01Wait 'till Reproduce is available")
                
message_end()
        }
    }
    return 
PLUGIN_CONTINUE
}

public 
dmg(victiminflictoridFloat:damagedamagebits)
{
    new 
Human[33]
    
Human[inflictor] = !zp_get_user_zombie(inflictor)
    new class[
33]
    class[
inflictor] = zp_get_user_zombie_class(inflictor) == regular
    
    
if(!Human[inflictor] && class[inflictor])
    {
        switch(
abilityended[id])
        {
            case 
0: {
                
SetHamParamFloat(4,damage 2.0)
            }
            case 
1: {
                
SetHamParamFloat(4,damage 1.0)
            }
        }
        
    }
    
    if(
Human[inflictor])
    {    
            
emit_sound(id,CHAN_VOICE,hit,1.0,ATTN_NORM,0,PITCH_NORM)
    }
}

stock fm_set_rendering(entityfx kRenderFxNone255255255render kRenderNormalamount 16)
{
    static 
Float:color[3]
    
color[0] = float(r)
    
color[1] = float(g)
    
color[2] = float(b)
    
    
set_pev(entitypev_renderfxfx)
    
set_pev(entitypev_rendercolorcolor)
    
set_pev(entitypev_rendermoderender)
    
set_pev(entitypev_renderamtfloat(amount))
}
stock fm_set_playermodel_ent(id, const modelname[],anim

    
fm_set_rendering(idkRenderFxNone255255255kRenderTransTexture1)
    
    static 
modelpath[100
    
formatex(modelpathsizeof modelpath 1"models/player/%s/%s.mdl"modelnamemodelname
    
    if (!
pev_valid(g_ent_playermodel[id]))
    { 
        
g_ent_playermodel[id] = engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target")) 
        
        if (!
pev_valid(g_ent_playermodel[id])) return
        
        
set_pev(g_ent_playermodel[id], pev_classname"finger_classname"
        
set_pev(g_ent_playermodel[id], pev_movetypeMOVETYPE_FOLLOW
        
set_pev(g_ent_playermodel[id], pev_aimentid)
        
set_pev(g_ent_playermodel[id], pev_animtimeget_gametime()+0.1)
        
set_pev(g_ent_playermodel[id], pev_framerate1.0)
        
set_pev(g_ent_playermodel[id], pev_sequenceanim)
        
set_pev(g_ent_playermodel[id], pev_ownerid
        
    } 
    
    
engfunc(EngFunc_SetModelg_ent_playermodel[id], modelpath

That s the full code of what i did , the last 2 stocks i copied from another plugin.
My tasks aren t working.... , it s always confuzing the id with the taskid , im using amxx 1.8.1 and looking better at my codei wrote something bad at dmg and going to solve it

!IMPORTANT!
I want to tank everyone bcs wanted to help me

Last edited by AnimalMonster; 08-02-2020 at 15:07.
AnimalMonster is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 08-02-2020 , 15:35   Re: Run time error 4: index out of bounds
Reply With Quote #13

what the hell is this

youre setting the task in both if() and else statements, just remove it from there and put it under the else statement with the Ready[id], Ready2[id]

hudready and hudready1 are the task callbacks, what are you doing in zp_user_humanized_post.....
you have no idea what youre doing ._.
ZaX is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 08-02-2020 , 15:46   Re: Run time error 4: index out of bounds
Reply With Quote #14

Quote:
Originally Posted by ZaX View Post
what the hell is this

youre setting the task in both if() and else statements, just remove it from there and put it under the else statement with the Ready[id], Ready2[id]

hudready and hudready1 are the task callbacks, what are you doing in zp_user_humanized_post.....
you have no idea what youre doing ._.
1. I did that because the player will have different skin.
2.whar hudready do you see in zp_user_humanize_post? There i just tried to delete all the tasks without veryfing if they exist...

+ if i remember good , i did the set_task with id - taskid and wanted with + but when the plugin starts the plugin uses the id of the player + the task id as the player id.

Last edited by AnimalMonster; 08-02-2020 at 15:49.
AnimalMonster is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 08-02-2020 , 16:07   Re: Run time error 4: index out of bounds
Reply With Quote #15

I mean if it is like this i can do:
PHP Code:
set_task(1.0"hudready"id taskid taskid,_,_,"b"
And could be better?, i don t think so
AnimalMonster is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 08-02-2020 , 16:40   Re: Run time error 4: index out of bounds
Reply With Quote #16

Search for tutorials, or existing threads. youre doing it wrong.
took me 10 seconds https://forums.alliedmods.net/showthread.php?t=125638

Last edited by ZaX; 08-02-2020 at 16:40.
ZaX is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 08-02-2020 , 16:48   Re: Run time error 4: index out of bounds
Reply With Quote #17

Nvm man i think i got it , i was putting task in () at every function and the id of the player wasn t putted on the simbol task and was on id still so was doing a - b = b, so i did put (id), made new playerid = id - taskx.
I think that the problem it s solved i go test
Cuz it had so be a - b = c , not = b if you know what im saying and telling about

Last edited by AnimalMonster; 08-02-2020 at 16:50.
AnimalMonster is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 08-02-2020 , 16:49   Re: Run time error 4: index out of bounds
Reply With Quote #18

Quote:
Originally Posted by ZaX View Post
Search for tutorials, or existing threads. youre doing it wrong.
took me 10 seconds https://forums.alliedmods.net/showthread.php?t=125638
I really got it wrong man ....
You helped me a little more than i thinked , you told me something about humanize post and gone off to go and look at it , it took me 10 mins to understand what i did wrong


Edit: GUYS I GOT IT , was because of the zp_humanize_post, bcs i was doing new playerid or new id at every function made this number duplicate , i mean taskhud was duplicated but didn t got the id.
So i made just new playerid and that was

Last edited by AnimalMonster; 08-02-2020 at 17:02.
AnimalMonster is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-02-2020 , 17:17   Re: Run time error 4: index out of bounds
Reply With Quote #19

I won't dive down too deep in the code at this point since it's not clear what you have added, what you want and what could just be removed.

Here's an example of a problem that i encounter when trying to fix the code:
Code:
new const ability1end[] = { "csolike/pre2.wav" } // ... public plugin_precache() {     // ...     precache_sound(ability1end)     // ... }
This sound is defined and precached but not actually used. The variable is named end but the sound file named pre.
So I don't know if this is:
1. ...something to be removed since it's not used
2. ...supposed to be pre sound for ability 2
3. ...end sound for ability 1.





Tasks are pretty simple.

Basically if you want multiple tasks that you want to actually remove at different times (otherwise you just use they player ID) you need to set an ID just to tell them apart so you don't remove the wrong one.

Since player id's are 0-32 you need task ID's that are at least 32 apart. Also, good practice is to avoid 0-32 since you usually use them for tasks that aren't removed but they will be removed as well.

taskid1 = 32 (range 32-63)
taskid2 = 64 (range 64-95)

Example for player id = 5
set_task(x.x, "x", taskid1 + id) // 32 + 5 = 37

public x(id) {
id -= taskid1; // 37 - 32 = 5, back to the player ID
}



In your case, you cancel all the tasks at once and not anywhere else in the code. I would say, scrap the whole taskid system and just use the player id.

You only need to use remove_task(id) once to remove all tasks with the same id.
__________________
Black Rose is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 08-02-2020 , 18:15   Re: Run time error 4: index out of bounds
Reply With Quote #20

Quote:
Originally Posted by Black Rose View Post
I won't dive down too deep in the code at this point since it's not clear what you have added, what you want and what could just be removed.

Here's an example of a problem that i encounter when trying to fix the code:
Code:
new const ability1end[] = { "csolike/pre2.wav" } // ... public plugin_precache() {     // ...     precache_sound(ability1end)     // ... }
This sound is defined and precached but not actually used. The variable is named end but the sound file named pre.
So I don't know if this is:
1. ...something to be removed since it's not used
2. ...supposed to be pre sound for ability 2
3. ...end sound for ability 1.





Tasks are pretty simple.

Basically if you want multiple tasks that you want to actually remove at different times (otherwise you just use they player ID) you need to set an ID just to tell them apart so you don't remove the wrong one.

Since player id's are 0-32 you need task ID's that are at least 32 apart. Also, good practice is to avoid 0-32 since you usually use them for tasks that aren't removed but they will be removed as well.

taskid1 = 32 (range 32-63)
taskid2 = 64 (range 64-95)

Example for player id = 5
set_task(x.x, "x", taskid1 + id) // 32 + 5 = 37

public x(id) {
id -= taskid1; // 37 - 32 = 5, back to the player ID
}



In your case, you cancel all the tasks at once and not anywhere else in the code. I would say, scrap the whole taskid system and just use the player id.

You only need to use remove_task(id) once to remove all tasks with the same id.
It s used for the first ability but yeah, im going to remake the plugin because the ability doesn t work from reasons

Edit: i will be keeping what i really need from that plugin but imms remake the abilities , the zp_user_humanize_post event doings and huds

Last edited by AnimalMonster; 08-02-2020 at 18:36.
AnimalMonster is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:00.


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