Raised This Month: $ Target: $400
 0% 

[SOLVED] Index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chihuahuax
Senior Member
Join Date: Oct 2014
Location: Malaysia
Old 09-21-2015 , 05:33   [SOLVED] Index out of bounds
Reply With Quote #1

I used public zp_round_started(gamemode, id) to prevent players from buying modes if the last & last 2 round was not normal infection

and I succeed. But now I get errors if I buy it on the first 1 or 2 rounds "Index out of bounds" i guess i couldnt get the 'last mode played' as it is Invalid

how do i get this fixed?

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#include <zombie_plague_advance>


#define PLUGIN "[ZP] Pack Assasin,Survivor,Nemesis,Sniper"
#define VERSION "2.1"
#define AUTHOR "Ghost95V"

#define ZP_TEAM_HUMAN (1<<1)
new const g_item_nem_name[] = "Buy Nemesis"
new const g_item_sur_name[] = "Buy Survivor"
new const g_item_assassin_name[] = "Buy Assassin"
new const g_item_sniper_name[] = "Buy Sniper"
new const g_costnemesis 155
new const g_costsurvivor 300
new const g_costsniper 300
new const g_costassassin 155

new g_maxplayersg_msgSayText
new g_nemesisg_survivorg_assassing_sniper
new g_buyableg_endround
new has_moded[33]
new 
g_can
new g_rounds[512]
new 
g_curround 0

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("HLTV""event_round_start""a""1=0""2=0")
    
register_logevent("logevent_round_end"2"1=Round_End")
    
    
g_nemesis zp_register_extra_item(g_item_nem_nameg_costnemesisZP_TEAM_HUMAN)
    
g_survivor zp_register_extra_item(g_item_sur_nameg_costsurvivorZP_TEAM_HUMAN)
    
g_assassin zp_register_extra_item(g_item_assassin_nameg_costassassinZP_TEAM_HUMAN)
    
g_sniper zp_register_extra_item(g_item_sniper_nameg_costsniperZP_TEAM_HUMAN
    
    
g_maxplayers get_maxplayers()
    
g_msgSayText get_user_msgid("SayText")
}

public 
zp_round_started(gamemodeid)
{
    
g_rounds[g_curround++] = gamemode
}

public 
zp_extra_item_selected(playeritemid)
{
    if(
itemid == g_nemesis)
    {
        if (!
g_can)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait for atleast^x03 3 seconds^x01!")
            
            return 
ZP_PLUGIN_HANDLED;
        }
        
        if (
zp_has_round_started() == || g_endround)
        {
            
zp_colored_print(player"^x04[ZP]^x01 This item can only be bought before the round mode starts")
            return 
ZP_PLUGIN_HANDLED;
        }
        
        if (
has_moded[player])
        {
            
zp_colored_print(player"^x04[ZP]^x01 You only can buy mode^x04 once^x01 in a map")
            
            return 
ZP_PLUGIN_HANDLED;
        }
        
    if (
g_rounds[g_curround 1] != MODE_INFECTION)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait 2 more rounds.")
            return 
ZP_PLUGIN_HANDLED;
        }
        if (
g_rounds[g_curround 2] != MODE_INFECTION)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait 1 more round.")
            return 
ZP_PLUGIN_HANDLED;
        }

        
zp_make_user_nemesis(player)
        
        new 
name[32]
        
get_user_name(playernamecharsmax(name))
        
zp_colored_print(0"^x04[ReverseZM]^x03 %s^x01 has bought^x04 Nemesis"name)
        
        
has_moded[player] = true
        
        g_buyable 
false
    
}
    else if(
itemid == g_survivor)
    {    
        if (!
g_can)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait for atleast^x03 3 seconds^x01!")
            
            return 
ZP_PLUGIN_HANDLED;
        }
        
        if (
zp_has_round_started() == || g_endround)
        {
            
zp_colored_print(player"^x04[ZP]^x01 This item can only be bought before the round mode starts")
            return 
ZP_PLUGIN_HANDLED;
        }
        if (
has_moded[player])
        {
            
zp_colored_print(player"^x04[ZP]^x01 You only can buy mode^x04 once^x01 in a map")
            
            return 
ZP_PLUGIN_HANDLED;
        }
    if (
g_rounds[g_curround 1] != MODE_INFECTION)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait 2 more rounds.")
            return 
ZP_PLUGIN_HANDLED;
        }
        if (
g_rounds[g_curround 2] != MODE_INFECTION)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait 1 more round.")
            return 
ZP_PLUGIN_HANDLED;
        }
        
        
zp_make_user_survivor(player)
        
        new 
name[32]
        
get_user_name(playernamecharsmax(name))
        
zp_colored_print(0"^x04[ReverseZM]^x03 %s^x01 has bought^x04 Survivor"name)  
        
        
has_moded[player] = true
        
        g_buyable 
false
    
}   
    else if(
itemid == g_assassin)
    {
        if (!
g_can)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait for atleast^x03 3 seconds^x01!")
            
            return 
ZP_PLUGIN_HANDLED;
        }
        
        if (
zp_has_round_started() == || g_endround)
        {
            
zp_colored_print(player"^x04[ZP]^x01 This item can only be bought before the round mode starts")
            return 
ZP_PLUGIN_HANDLED;
        }
        if (
has_moded[player])
        {
            
zp_colored_print(player"^x04[ZP]^x01 You only can buy mode^x04 once^x01 in a map")
            
            return 
ZP_PLUGIN_HANDLED;
        }

    if (
g_rounds[g_curround 1] != MODE_INFECTION)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait 2 more rounds.")
            return 
ZP_PLUGIN_HANDLED;
        }
        if (
g_rounds[g_curround 2] != MODE_INFECTION)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait 1 more round.")
            return 
ZP_PLUGIN_HANDLED;
        }
        
        
zp_make_user_assassin(player)
        
        new 
name[32]
        
get_user_name(playernamecharsmax(name))
        
zp_colored_print(0"^x04[ReverseZM]^x03 %s^x01 has bought^x04 Assassin"name)  
        
        
has_moded[player] = true
        
        g_buyable 
false
    
}   
    else if(
itemid == g_sniper)
    {
        if (!
g_can)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait for atleast^x03 3 seconds^x01!")
            
            return 
ZP_PLUGIN_HANDLED;
        }
        
        if (
zp_has_round_started() == || g_endround)
        {
            
zp_colored_print(player"^x04[ZP]^x01 This item can only be bought before the round mode starts")
            return 
ZP_PLUGIN_HANDLED;
        }
        if (
has_moded[player])
        {
            
zp_colored_print(player"^x04[ZP]^x01 You only can buy mode^x04 once^x01 in a map")
            
            return 
ZP_PLUGIN_HANDLED;
        }
        
    if (
g_rounds[g_curround 1] != MODE_INFECTION)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait 2 more rounds.")
            return 
ZP_PLUGIN_HANDLED;
        }
        if (
g_rounds[g_curround 2] != MODE_INFECTION)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You must wait 1 more round.")
            return 
ZP_PLUGIN_HANDLED;
        }

        
zp_make_user_sniper(player)
        
        new 
name[32]
        
get_user_name(playernamecharsmax(name))
        
zp_colored_print(0"^x04[ReverseZM]^x03 %s^x01 has bought^x04 Sniper"name)  
        
        
has_moded[player] = true
        
        g_buyable 
false
    
}   
    return 
PLUGIN_CONTINUE
}

public 
event_round_start()
{
    
g_can false
    g_endround 
false
    g_buyable 
true
    
    set_task
(3.0"enable")
}

public 
logevent_round_end()
{
    
g_endround true
    
    
if (g_buyable)
        return;
}

public 
enable()
{
    
g_can true
}

zp_colored_print(target, const message[], any:...)
{
static 
buffer[512], iargscount
argscount 
numargs()

// Send to everyone
if (!target)
{
    static 
player
    
for (player 1player <= g_maxplayersplayer++)
    {
        
// Not connected
        
if (!is_user_connected(player))
            continue;
            
            
// Remember changed arguments
            
static changed[5], changedcount // [5] = max LANG_PLAYER occurencies
            
changedcount 0
            
            
// Replace LANG_PLAYER with player id
            
for (2argscounti++)
            {
                if (
getarg(i) == LANG_PLAYER)
                {
                    
setarg(i0player)
                    
changed[changedcount] = i
                    changedcount
++
                }
            }
            
            
// Format message for player
            
vformat(buffercharsmax(buffer), message3)
            
            
// Send it
            
message_begin(MSG_ONE_UNRELIABLEg_msgSayText_player)
            
write_byte(player)
            
write_string(buffer)
            
message_end()
            
            
// Replace back player id's with LANG_PLAYER
            
for (0changedcounti++)
                
setarg(changed[i], 0LANG_PLAYER)
        }
    }
    
// Send to specific target
    
else
    {
        
// Format message for player
        
vformat(buffercharsmax(buffer), message3)
        
        
// Send it
        
message_begin(MSG_ONEg_msgSayText_target)
        
write_byte(target)
        
write_string(buffer)
        
message_end()
    }

If (g_curround < 0)
return plugin_handled ?

SOLVED:
PHP Code:
if (g_curround 4)
        {
            
zp_colored_print(player"^x04[ZP]^x01 You cant buy mode now!")
            return 
ZP_PLUGIN_HANDLED;
        } 

Last edited by Chihuahuax; 09-22-2015 at 01:59.
Chihuahuax is offline
Send a message via Skype™ to Chihuahuax
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 18:51.


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