Raised This Month: $ Target: $400
 0% 

Run Time Error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nick
Senior Member
Join Date: Apr 2004
Location: Canada, Alberta, Cal
Old 03-10-2005 , 23:49   Run Time Error
Reply With Quote #1

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").
__________________
Nick is offline
Send a message via MSN to Nick
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 03-11-2005 , 00:12  
Reply With Quote #2

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 }
xeroblood is offline
Send a message via MSN to xeroblood
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 03-11-2005 , 00:35  
Reply With Quote #3

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.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Nick
Senior Member
Join Date: Apr 2004
Location: Canada, Alberta, Cal
Old 03-11-2005 , 01:19  
Reply With Quote #4

ah, I see what I did wrong. xero, avalanche, ty.
__________________
Nick is offline
Send a message via MSN to Nick
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 16:58.


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