AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Run Time Error (https://forums.alliedmods.net/showthread.php?t=11146)

Nick 03-10-2005 23:49

Run Time Error
 
Well I'm trying to make a command where any player in the server can open the console and type 'mslap <number of slaps >' and it will slap them according to the amount of slaps they output.

Code :
Code:
#include <amxmodx> #include <amxmisc> new pName[] = "Mult Self Slap" new pVersion[] = "v0.1" new pAuthor[] = "Nicholas Glistak" new msSlaps[33] = 0 public plugin_init ( ) {     register_plugin ( pName, pVersion, pAuthor )     register_clcmd ( "mslap", "MultSelfSlap", -0, " < Usage : mslap |Number Of Slaps| > " )         register_cvar ( "aios_msSlaps", "1" )     register_cvar ( "aios_msLimit", "2" )     register_event ( "ResetHUD", "msSlaps_Reset", "a" ) } public client_connect ( id ) {     msSlaps[id] = 0 } public msSlaps_Reset () {     new Players[32], iPlayers     get_players ( Players, iPlayers, "a" )     for ( new x = 0; x <= iPlayers; x++ )     {         msSlaps[x] = 0     } } public MultSelfSlap ( ids[] ) {     new id = ids[0]     new name[32]     get_user_name ( id, name, 31 )     new argv[32]     read_argv ( 1, argv, 31 )     new msNum     msNum = str_to_num ( argv )     if ( get_cvar_num ( "aios_msSlaps" ) != 1 ) {         client_print ( id, print_console, "[AIOS] Sorry this function is turned OFF" )         return PLUGIN_HANDLED     }     if ( msNum > 100 ) {         client_print ( id, print_console, "[AIOS] You cannot slap yourself more than 100 times" )         return PLUGIN_HANDLED     }     new MAX_SLAPS = get_cvar_num ( "aios_msLimit" )     if ( msSlaps[id] > MAX_SLAPS ) {         client_print ( id, print_console, "[AIOS] Sorry %s : You have used this function too many times this round", name )         return PLUGIN_HANDLED     } else {         new SlapDmg = get_cvar_num ( "aios_SlapDmg" )         for ( new i = 0; i < msNum; i++ )         {             user_slap ( id, SlapDmg )         }         msSlaps[id]++     }     new r = random ( 256 )     new g = random ( 256 )     new b = random ( 256 )         set_hudmessage ( r, g, b, 0.03, 0.62, 2, 0.02, 6.0, 0.01, 0.1, 1 )     show_hudmessage ( 0, "[AIOS] %s : Has slapped himself %d times", name, msNum )     console_print ( 0, "[AIOS] Client %s : Has slapped himself %d times", name, msNum )     return PLUGIN_HANDLED }

Compiles with no errors or warnings.
but I do get a run time error on this line :
Code:
if ( msSlaps[id] > MAX_SLAPS ) {
and the error is :
Code:

L 03/10/2005 - 20:42:19: [AMXX] Run time error 4 (index out of bounds) on line 59 (file "mult_self_slap.sma").

xeroblood 03-11-2005 00:12

Code:
public MultSelfSlap ( id ) {     if ( get_cvar_num ( "aios_msSlaps" ) != 1 ) {         client_print ( id, print_console, "[AIOS] Sorry this function is turned OFF" )         return PLUGIN_HANDLED     }     new name[32]     get_user_name ( id, name, 31 )     new argv[32]     read_argv ( 1, argv, 31 )     new msNum     msNum = str_to_num ( argv )     if ( msNum > 100 ) {         client_print ( id, print_console, "[AIOS] You cannot slap yourself more than 100 times" )         return PLUGIN_HANDLED     }     new MAX_SLAPS = get_cvar_num ( "aios_msLimit" )     if ( msSlaps[id] > MAX_SLAPS ) {         client_print ( id, print_console, "[AIOS] Sorry %s : You have used this function too many times this round", name )         return PLUGIN_HANDLED     }     new SlapDmg = get_cvar_num ( "aios_SlapDmg" )     for ( new i = 0; i < msNum; i++ )     {         user_slap ( id, SlapDmg )     }     msSlaps[id]++     new r = random ( 256 )     new g = random ( 256 )     new b = random ( 256 )         set_hudmessage ( r, g, b, 0.03, 0.62, 2, 0.02, 6.0, 0.01, 0.1, 1 )     show_hudmessage ( 0, "[AIOS] %s : Has slapped himself %d times", name, msNum )     console_print ( 0, "[AIOS] Client %s : Has slapped himself %d times", name, msNum )     return PLUGIN_HANDLED }

XxAvalanchexX 03-11-2005 00:35

Just had to comment on this one: "-0" -- rofl.

Xeroblood gave you the fixed code, I just thought I'd tell you why it didn't work. When the user runs the command it sends one integer parameter to the function which is the ID of the player. However, you designed your function to accept an array and then you attempt to get the ID of the player from the first array index. Obviously this wouldn't work.

It looks like the function you had had been intended for set_task passing an array.

Nick 03-11-2005 01:19

ah, I see what I did wrong. xero, avalanche, ty.


All times are GMT -4. The time now is 13:59.

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