Raised This Month: $51 Target: $400
 12% 

Revive plugin - some problem with compiling.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AdrianK69
Junior Member
Join Date: Apr 2020
Old 04-04-2020 , 23:41   Revive plugin - some problem with compiling.
Reply With Quote #1

Hello, guys

So I am a bit new to scripting but I'm a fast learner. So i found a Revive plugin that basically revives a player when he types in chat /revive. And he has only 3 attempts per round to do that. Ok I am trying to compile it but i get this error :" cupdr.sma(99) : error 032: array index out of bounds (variable "iPlayers")"

I will post the code:
Code:
#include <amxmodx>
#include <hamsandwich>
#include <colorchat>

#define MAX_PLAYERS 31

#pragma semicolon 1

new const g_Info[][] =

{

"Revive x",

"0.1.rel",

"eNd.",

"skitaila03"

};

enum _:g_Cvars

{

cvar_tag,

cvar_uses,

cvar_flags

};

new const cvar_name[g_Cvars][] =

{

"cvar_tag",

"cvar_uses",

"cvar_flags"

};

new const cvar_value[g_Cvars][] =

{

"Revive|",

"3",

"o"

};

new g_Cvar[g_Cvars];

new g_Use[MAX_PLAYERS+1];

public plugin_cfg()

{

for(new x = 0; x < g_Cvars; x++)

g_Cvar[x] = register_cvar(cvar_name[x] , cvar_value[x]);

}

public plugin_init()

{

register_plugin(g_Info[0], g_Info[1], g_Info[random_num(2,3)] );

register_clcmd("say", "hook_say");

register_clcmd("say_team", "hook_say");

register_logevent("EventRoundEnd", 2, "1=Round_End");

}

public EventRoundEnd()

{

static iPlayers[32], iNum, i, iPlayer;

get_players( iPlayers, iNum, "a" );

for( i=0; i < iNum; i++)

{

iPlayer = iPlayers[32];

if(g_Use[iPlayer] >= 0)

g_Use[iPlayer] = 0;

}

return PLUGIN_HANDLED;

}

public hook_say(iPlayer) {

static SaiPlayer[ 192 ];

read_args( SaiPlayer, sizeof ( SaiPlayer ) -1 );

if( !SaiPlayer[ 0 ] )

return 0;

remove_quotes( SaiPlayer );

if(equal( SaiPlayer, "revive", 5) || equal( SaiPlayer, "/revive", 10) )

{

if( ! ( get_user_flags(iPlayer) & read_flags(g_sCvar( cvar_flags )) ) )

{

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 this command is available only for^4 vip^1.", g_sCvar( cvar_tag ), szName(iPlayer));

return PLUGIN_HANDLED;

}

if(is_user_alive(iPlayer))

{

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 can be used only when you are^4 dead^1.", g_sCvar( cvar_tag ), szName(iPlayer));

return PLUGIN_HANDLED;

}

if(g_Use[iPlayer] >= g_nCvar(cvar_uses))

{

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 you have only^4 %i^3/^4%i^3 revives per round.^1.", g_sCvar( cvar_tag ),g_Use[iPlayer], g_nCvar(cvar_uses), szName(iPlayer));

return PLUGIN_HANDLED;

}

if(g_Use[iPlayer] <= g_nCvar(cvar_uses))

{

++g_Use[iPlayer];

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 you revived ^4 successfully.^1.", g_sCvar( cvar_tag ), szName(iPlayer));

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 ai^4 %i^3/^4%i^3 attempts.^1.", g_sCvar( cvar_tag ),g_Use[iPlayer], g_nCvar(cvar_uses), szName(iPlayer));

ExecuteHamB(Ham_CS_RoundRespawn, iPlayer);

}

}

return PLUGIN_CONTINUE;

}

stock szName(iPlayer)

{

new sz_Name[MAX_PLAYERS];

get_user_name(iPlayer, sz_Name, charsmax(sz_Name));

return sz_Name;

}

stock g_nCvar( cvar )

{

new nCvar = get_pcvar_num( g_Cvar[ cvar ] );

return nCvar;

}

stock g_sCvar( cvar )

{

new sCvar[ 24 ];

get_pcvar_string( g_Cvar[ cvar ], sCvar, charsmax( sCvar ));

return sCvar;

}
So the problem might be somehow here in this part of the code I guess:

Code:
static iPlayers[32], iNum, i, iPlayer;

get_players( iPlayers, iNum, "a" );

for( i=0; i < iNum; i++)

{

iPlayer = iPlayers[32];

if(g_Use[iPlayer] >= 0)

g_Use[iPlayer] = 0;

}
If you have time and you can help me with this I gonna thank you in advance.

Regards,
Adrian.
AdrianK69 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-04-2020 , 23:47   Re: Revive plugin - some problem with compiling.
Reply With Quote #2

If you have an array sized as iPlayer[ 32 ], you will get an out of bounds error trying to use iPLayer[ 32 ] since the valid range is iPlayer[ 0 ] to iPlayer[ 31 ].

Try this
PHP Code:
for( i=iNum i++ )
{
     
iPlayer iPlayers];

     if ( 
g_UseiPlayer  ] >= )
        
g_UseiPlayer ] = 0;

__________________
Bugsy is online now
AdrianK69
Junior Member
Join Date: Apr 2020
Old 04-05-2020 , 00:20   Re: Revive plugin - some problem with compiling.
Reply With Quote #3

@Bugsy : Thank you so much the problem fixed no errors at compiling but....
Here we go...there are bugs in the game.

So I tested it and the /revive command it works good but there are 3 problems from what I saw:

First one is that when I hit revive it appears in chat that "Revive you have 3/100 attempts and the limit is 3 revive per round.

The second problem is that after I hit that 3 revives it appears you have only 3/101 attempts, aaand I have tested it on my account with all the flags like abcdefghijklmnopqrstu and after that I have tried to test it on a account that have only the revive FLAG like "bo". When I try that on the different account it says the same error "you have only 3/101 attempts." so it seems like if a player hits that 3 revive it applies for every other account with that flag I guess.

Problem number 3: I have tried to restart the server by amx_cvar sv_restart 1 to see if it's working, it seems like it's the same message you have only 3/101 attemps. and it passed like 5 rounds from that first 3 revive that I had applied from my main account...

I think there's something messed up in the code...it seems like is a lot of work or it is just a simple catch... if you can help me that will be wonderful, thank you in advance
AdrianK69 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-05-2020 , 00:25   Re: Revive plugin - some problem with compiling.
Reply With Quote #4

Instead of us trying to reverse engineer what you changed, can you show specifically what you changed in the original plugin?
__________________
Bugsy is online now
AdrianK69
Junior Member
Join Date: Apr 2020
Old 04-05-2020 , 00:30   Re: Revive plugin - some problem with compiling.
Reply With Quote #5

Code:
#include
#include

#pragma semicolon 1

new const g_Info[][] =

{

"Revive x",

"0.1.rel",

"eNd.",

"skitaila03"

};

enum _:g_Cvars

{

cvar_tag,

cvar_uses,

cvar_flags

};

new const cvar_name[g_Cvars][] =

{

"cvar_tag",

"cvar_uses",

"cvar_flags"

};

new const cvar_value[g_Cvars][] =

{

"Revive|",

"3",

"x"

};

new g_Cvar[g_Cvars];

new g_Use[MAX_PLAYERS+1];

public plugin_cfg()

{

for(new x = 0; x < g_Cvars; x++)

g_Cvar[x] = register_cvar(cvar_name[x] , cvar_value[x]);

}

public plugin_init()

{

register_plugin(g_Info[0], g_Info[1], g_Info[random_num(2,3)] );

register_clcmd("say", "hook_say");

register_clcmd("say_team", "hook_say");

register_logevent("EventRoundEnd", 2, "1=Round_End");

}

public EventRoundEnd()

{

static iPlayers[32], iNum, i, iPlayer;

get_players( iPlayers, iNum, "a" );

for( i=0; i

{

iPlayer = iPlayers;

if(g_Use[iPlayer] >= 0)

g_Use[iPlayer] = 0;

}

return PLUGIN_HANDLED;

}

public hook_say(iPlayer) {

static SaiPlayer[ 192 ];

read_args( SaiPlayer, sizeof ( SaiPlayer ) -1 );

if( !SaiPlayer[ 0 ] )

return 0;

remove_quotes( SaiPlayer );

if(equal( SaiPlayer, "revive", 5) || equal( SaiPlayer, "/revive", 10) )

{

if( ! ( get_user_flags(iPlayer) & read_flags(g_sCvar( cvar_flags )) ) )

{

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 poti esti^4 vip^1.", g_sCvar( cvar_tag ), szName(iPlayer));

return PLUGIN_HANDLED;

}

if(is_user_alive(iPlayer))

{

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 poti folosi doar cand esti^4 mort^1.", g_sCvar( cvar_tag ), szName(iPlayer));

return PLUGIN_HANDLED;

}

if(g_Use[iPlayer] <= g_nCvar(cvar_uses))

{

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 ai^4 %i^3/^4%i^3 incercari^1.", g_sCvar( cvar_tag ),g_Use[iPlayer], g_nCvar(cvar_uses), szName(iPlayer));

return PLUGIN_HANDLED;

}

if(g_Use[iPlayer] <= g_nCvar(cvar_uses))

{

++g_Use[iPlayer];

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 te-ai inviat cu^4 succes^1.", g_sCvar( cvar_tag ), szName(iPlayer));

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 ai^4 %i^3/^4%i^3 incercari^1.", g_sCvar( cvar_tag ),g_Use[iPlayer], g_nCvar(cvar_uses), szName(iPlayer));

ExecuteHamB(Ham_CS_RoundRespawn, iPlayer);

}

}

return PLUGIN_CONTINUE;

}

stock szName(iPlayer)

{

new sz_Name[MAX_PLAYERS];

get_user_name(iPlayer, sz_Name, charsmax(sz_Name));

return sz_Name;

}

stock g_nCvar( cvar )

{

new nCvar = get_pcvar_num( g_Cvar[ cvar ] );

return nCvar;

}

stock g_sCvar( cvar )

{

new sCvar[ 24 ];

get_pcvar_string( g_Cvar[ cvar ], sCvar, charsmax( sCvar ));

return sCvar;

}
Oh sorry for that this is the original code.

Code:
static iPlayers[32], iNum, i, iPlayer;

get_players( iPlayers, iNum, "a" );

for( i=0; i

{

iPlayer = iPlayers;

if(g_Use[iPlayer] >= 0)

g_Use[iPlayer] = 0;

}

return PLUGIN_HANDLED;

}
Here I made the first change because it gaves me some error in the console
and the second one is that I added #define MAX_PLAYERS 31 at the beginning of the code
AdrianK69 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-05-2020 , 00:38   Re: Revive plugin - some problem with compiling.
Reply With Quote #6

That doesn't help. What I was asking is for you to tell me specifically what you changed in the original code that is now causing you errors. This would allow for me to easily tell you what is wrong. I dont want to read every line of code to try to figure out what you broke.

And it should be this, unless you really use a max players of 31 for your server:
#define MAX_PLAYERS 32
__________________
Bugsy is online now
AdrianK69
Junior Member
Join Date: Apr 2020
Old 04-05-2020 , 01:01   Re: Revive plugin - some problem with compiling.
Reply With Quote #7

So here is the original CODE and I showed you what I have changed:
Code:
#include <amxmodx>
#include <hamsandwich>
#include <colorchat>

#pragma semicolon 1

new const g_Info[][] =

{

"Revive x",

"0.1.rel",

"eNd.",

"skitaila03"

};

enum _:g_Cvars

{

cvar_tag,

cvar_uses,

cvar_flags

};

new const cvar_name[g_Cvars][] =

{

"cvar_tag",

"cvar_uses",

"cvar_flags"

};

new const cvar_value[g_Cvars][] =

{

"Revive|",

"3",

"x"

};

new g_Cvar[g_Cvars];

new g_Use[MAX_PLAYERS+1];

public plugin_cfg()

{

for(new x = 0; x < g_Cvars; x++)

g_Cvar[x] = register_cvar(cvar_name[x] , cvar_value[x]);

}

public plugin_init()

{

register_plugin(g_Info[0], g_Info[1], g_Info[random_num(2,3)] );

register_clcmd("say", "hook_say");

register_clcmd("say_team", "hook_say");

register_logevent("EventRoundEnd", 2, "1=Round_End");

}

public EventRoundEnd()

{

static iPlayers[32], iNum, i, iPlayer;

get_players( iPlayers, iNum, "a" );

for( i=0; i

{

iPlayer = iPlayers;

if(g_Use[iPlayer] >= 0)

g_Use[iPlayer] = 0;

}

return PLUGIN_HANDLED;

}

public hook_say(iPlayer) {

static SaiPlayer[ 192 ];

read_args( SaiPlayer, sizeof ( SaiPlayer ) -1 );

if( !SaiPlayer[ 0 ] )

return 0;

remove_quotes( SaiPlayer );

if(equal( SaiPlayer, "revive", 5) || equal( SaiPlayer, "/revive", 10) )

{

if( ! ( get_user_flags(iPlayer) & read_flags(g_sCvar( cvar_flags )) ) )

{

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 poti esti^4 vip^1.", g_sCvar( cvar_tag ), szName(iPlayer));

return PLUGIN_HANDLED;

}

if(is_user_alive(iPlayer))

{

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 poti folosi doar cand esti^4 mort^1.", g_sCvar( cvar_tag ), szName(iPlayer));

return PLUGIN_HANDLED;

}

if(g_Use[iPlayer] <= g_nCvar(cvar_uses))

{

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 ai^4 %i^3/^4%i^3 incercari^1.", g_sCvar( cvar_tag ),g_Use[iPlayer], g_nCvar(cvar_uses), szName(iPlayer));

return PLUGIN_HANDLED;

}

if(g_Use[iPlayer] <= g_nCvar(cvar_uses))

{

++g_Use[iPlayer];

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 te-ai inviat cu^4 succes^1.", g_sCvar( cvar_tag ), szName(iPlayer));

client_print_color(iPlayer, print_team_default, "^4%s ^3%s^1 ai^4 %i^3/^4%i^3 incercari^1.", g_sCvar( cvar_tag ),g_Use[iPlayer], g_nCvar(cvar_uses), szName(iPlayer));

ExecuteHamB(Ham_CS_RoundRespawn, iPlayer);

}

}

return PLUGIN_CONTINUE;

}

stock szName(iPlayer)

{

new sz_Name[MAX_PLAYERS];

get_user_name(iPlayer, sz_Name, charsmax(sz_Name));

return sz_Name;

}

stock g_nCvar( cvar )

{

new nCvar = get_pcvar_num( g_Cvar[ cvar ] );

return nCvar;

}

stock g_sCvar( cvar )

{

new sCvar[ 24 ];

get_pcvar_string( g_Cvar[ cvar ], sCvar, charsmax( sCvar ));

return sCvar;

}
So with the original code from below I get these error messages in the console when I try to compile it:

Code:
Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team

cupdr.sma(59) : error 017: undefined symbol "MAX_PLAYERS"
cupdr.sma(59) : error 009: invalid array size (negative or zero)
cupdr.sma(95) : error 028: invalid subscript (not an array or too many subscripts): "i"
cupdr.sma(97) : error 001: expected token: "}", but found "-identifier-"
cupdr.sma(97) : error 006: must be assigned to an array
cupdr.sma(97) : error 036: empty statement
cupdr.sma(97) : fatal error 107: too many error messages on one line

Compilation aborted.
7 Errors.
Could not locate output file cupdr.amx (compile failed).
And from this original these part was the one with the errors so I have changed from this one:
Code:
static iPlayers[32], iNum, i, iPlayer;

get_players( iPlayers, iNum, "a" );

for( i=0; i

{

iPlayer = iPlayers;

if(g_Use[iPlayer] >= 0)

g_Use[iPlayer] = 0;

}

return PLUGIN_HANDLED;

}
to this one:
Code:
static iPlayers[32], iNum, i, iPlayer;

get_players( iPlayers, iNum, "a" );

for( i=0; i < iNum; i++)

{

iPlayer = iPlayers[32];

if(g_Use[iPlayer] >= 0)

g_Use[iPlayer] = 0;

}
And now it works compiling but it in-game it has that 3 problems that I mentioned earlier.
AdrianK69 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-05-2020 , 01:08   Re: Revive plugin - some problem with compiling.
Reply With Quote #8

This is the problem with modifying other peoples plugins, a minor change can and usually does result in bugs that are sometimes hard to find.

How about you explain exactly what you want the plugin to do and we can help you make it. Is the functionality limited to allowing 3 /revive commands per round?
__________________
Bugsy is online now
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-05-2020 , 01:17   Re: Revive plugin - some problem with compiling.
Reply With Quote #9

Here, work with this. Untested
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>

new const Version[] = "0.1";

new 
g_NumRevivesMAX_PLAYERS ];
new 
g_pTotalRevives g_pRequiredFlags;

public 
plugin_init() 
{
    
register_plugin"Revive" Version "bugsy" );
    
    
g_pTotalRevives register_cvar"allowed_revives" "3" );
    
g_pRequiredFlags register_cvar"revive_flags" "o" );
    
    
register_event"HLTV" "NewRound" "a" "1=0" "2=0" );
    
    
register_clcmd"say /revive" "Revive" );
    
register_clcmd"say_team /revive" "Revive" );
}

public 
NewRound()
{
    
arraysetg_NumRevives sizeofg_NumRevives ) );
}

public 
Reviveid )
{    
    new 
iTotalRevives szFlags26 ] , iFlags;
    
    
iTotalRevives get_pcvar_numg_pTotalRevives );
    
get_pcvar_stringg_pRequiredFlags szFlags charsmaxszFlags ) );
    
iFlags read_flagsszFlags );
    
    if ( ( ( 
get_user_flagsid ) & iFlags ) == iFlags ) && ( cs_get_user_teamid ) == CS_TEAM_CT ) )
    {
        if ( 
g_NumRevivesid ] < iTotalRevives )
        {
            if ( !
is_user_aliveid ) )
            {
                
ExecuteHamBHam_CS_RoundRespawn id );
                
g_NumRevivesid ]++;
                
                
client_printid print_chat "* You have now used %d of %d allowed revives" g_NumRevivesid ] , iTotalRevives );
            }
        }
        else
        {
            
client_printid print_chat "* You have already used %d of %d revives" iTotalRevives iTotalRevives );
        }
    }
    
    return 
PLUGIN_HANDLED;

__________________

Last edited by Bugsy; 04-05-2020 at 16:35.
Bugsy is online now
AdrianK69
Junior Member
Join Date: Apr 2020
Old 04-05-2020 , 01:17   Re: Revive plugin - some problem with compiling.
Reply With Quote #10

So I want the plugin to do exactly this:

When a player with the flag "o" types in the chat /revive: he is respawned.
And this command to be limited at 3 uses per round.
Need to mention that this is for the Deathrun Mode.

So /revive : 3 times per round.
And only dead people can use this command and revive only themself and TERRO should not be able to use it.
Thank you so much for your patience.
AdrianK69 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 11:04.


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