Raised This Month: $ Target: $400
 0% 

Whats with index out of bounds in my array!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 02-05-2005 , 14:47   Whats with index out of bounds in my array!
Reply With Quote #1

I don't get it... its like impossible for this line of code to be out of bounds...
fakecivorigin[0] = fakecivX[npcid];

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #include <fun> new Float:fakecivX[14] = {2959.0,2753.0,2129.0,2129.0,2129.0,2006.0,1064.0,65.0,65.0,-1633.0,-1633.0,-2256.0,-2221.0,-1568.0} new Float:fakecivY[14] = {-515.0,72.0,120.0,120.0,120.0,-1849.0,-2220.0,-1655.0,-1655.0,-89.0,-89.0,-1577.0,-2036.0,-1431.0} new Float:fakecivZ[14] = {-284.0,-264.0,-252.0,-252.0,-252.0,-172.0,-252.0,-284.0,-284.0,-268.0,-268.0,-292.0,-236.0,-284.0} new fakecivvoice[14] = {1,1,1,2,2,1,2,1,2,2,2,1,1,1} new fakecivnames[14] new npcid = 0 //new usedcivs[14] //new nextusedciv = 0 public plugin_init() {     register_plugin("FakeCiv","0.1","-Snort- Leader")     register_clcmd("spawnthemmofos","spawnfakecivs")     } public spawnfakecivs(id) {           format(fakecivnames[0],16,"Bob Thompson")     format(fakecivnames[1],16,"Paul O Connor")     format(fakecivnames[2],16,"Big Smoke")     format(fakecivnames[3],16,"Snoop Dogg")     format(fakecivnames[4],16,"Mr. Woot")     format(fakecivnames[5],16,"Sonni")     format(fakecivnames[6],16,"Dan Ackroid")     format(fakecivnames[7],16,"Fomerly Known as Prince")     format(fakecivnames[8],16,"Cesar Hernadez")     format(fakecivnames[9],16,"Howard Stern")     format(fakecivnames[10],16,"Jack Black")     format(fakecivnames[11],16,"Tom Clancy")     format(fakecivnames[12],16,"Ben Dover")     format(fakecivnames[13],16,"Inspector Gadget")           if ( npcid == 14 ) {         client_print(id,print_chat,"OMG OMG OMG npcid == 14")             return PLUGIN_HANDLED         }     new fakecivcreateent[14]         //new randomnumber         //randomnumber = (random_num(0,14))         new Float:fakecivorigin[3];         fakecivorigin[0] = fakecivX[npcid];         fakecivorigin[1] = fakecivY[npcid];         fakecivorigin[2] = fakecivZ[npcid];         new entclassname[18]         format(entclassname[npcid],17,"fake_civilian%i",npcid)         fakecivcreateent[npcid] = create_entity("info_target")         entity_set_string(fakecivcreateent[npcid],EV_SZ_classname,entclassname[npcid]);         entity_set_model(fakecivcreateent[npcid],"models/barry.mdl");         entity_set_origin(fakecivcreateent[npcid],fakecivorigin)         DispatchSpawn(fakecivcreateent[npcid])         client_print(id,print_chat,"Civlian %s has been spawned!",fakecivnames[npcid])         npcid = npcid + 1           return PLUGIN_HANDLED } public pfn_touch(ptr,ptd) {     new i     if(ptr < 1 || ptd < 1 || ptd > 32 || !is_user_alive(ptd) || !is_user_connected(ptd)) {         return PLUGIN_CONTINUE;           }      new classname[33];      entity_get_string(ptr,EV_SZ_classname,classname,32);         for (i=0; i<sizeof(fakecivX); i++ ) {             new entclassname[18]             format(entclassname[i],16,"fake_civilian%i",i)                 if(equal(classname,entclassname[i]) == 1) {                     new fakecivphrase[14]                         if (fakecivvoice[i] == 1) {                             format(fakecivphrase[i],64,"%s says, ^"Stop breathing on me!^"",fakecivnames[i])                             client_print(ptd,print_chat,"%s",fakecivphrase)                             client_cmd(ptd,"speak fakeciv/stopbreathingonme.wav")                             return PLUGIN_HANDLED                         }                         if (fakecivvoice[i] == 2) {                             format(fakecivphrase[i],64,"%s says, ^"Back off homie!^"",fakecivnames[i])                             client_print(ptd,print_chat,"%s",fakecivphrase)                             client_cmd(ptd,"speak fakeciv/backhomie.wav")                             return PLUGIN_HANDLED                         }                     }                 }             return PLUGIN_CONTINUE         }                           public plugin_precache() {     precache_sound("fakeciv/backhomie.wav")     precache_sound("fakeciv/stopbreathingonme.wav")     precache_model("models/barry.mdl") }
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 02-05-2005 , 15:45  
Reply With Quote #2

*Bump*

Also, there are some arrays with [18] so I could expand later easier.
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 02-05-2005 , 17:43  
Reply With Quote #3

apparently no one can figure this out, or is this code just acting ghey?
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
BAILOPAN
Join Date: Jan 2004
Old 02-05-2005 , 17:49  
Reply With Quote #4

Perhaps you should check if it's out of bounds before hand (>=14, not == 14)
__________________
egg
BAILOPAN is offline
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 02-05-2005 , 17:53  
Reply With Quote #5

great... it is >= 14, but how?
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 02-05-2005 , 17:57  
Reply With Quote #6

Did you try what BAILOPAN said anyway? How do you call the function? Do you call it multiple times? At what point do you change the npcid variable?
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 02-05-2005 , 18:00  
Reply With Quote #7

that post said hold on... but u posted anyway...

Yes i did, it is >= to 14. I called it by typing spawnthemmofos in console, using register_clcmd. I am calling it multiple times because I havent made a set_task function yet (to avoid the ed_alloc error.) When i do the command 15 times, then it should start saying its >= to 14. npcid gets changed ocne it spawns the first civ. It should spawn the first civ because it is declared as 0, and I'm pretty sure that arrays have a slot of [0].

edit: im now using npcid++ instead of npcid = npcid + 1, if that makes a difference.
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 02-05-2005 , 18:25  
Reply With Quote #8

OMG!!!!!!!! I made the plugin assign npcid to = 0 in 2 different locations, so it was impossible to be anythign but 0... but when i made a client_print to tell me what npcid was, it said it was 108. (The client_print that told me the npcid was in if npcid >=0, the locatiosn where i assigned it to = 0 was when it was declared, and inside the plugin_init. )

edit: sry for all the multiple posting, but every post i make has some other thing i found out...

Edit: Edit: i changed the name from npcid to omgwtf to make sure npcid wasnt some other varible somehow... its still 108.
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
BAILOPAN
Join Date: Jan 2004
Old 02-05-2005 , 19:31  
Reply With Quote #9

You're doing crazy stuff like this:
Code:
                new fakecivphrase[14]                         if (fakecivvoice[i] == 1) {                             format(fakecivphrase[i], 64

You've created an array with 14 slots. Then in slot i, you're trying to store a 64cell length string in. A string is an array, and you can't do this.

new fakecivphrase[14][64] would work, but that's an expensive operation, and I have no idea what you're trying to do.

Anyway, the code you have is riddled with things like this that will overflow the stack and give random values all over the place.
__________________
egg
BAILOPAN is offline
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 02-05-2005 , 20:26  
Reply With Quote #10

well, i really diddnt know what the second [] was for after the arrayname[14][64], now it puts everything into perspective... it works now, its just that now its trying to precache mmmodels/barry.mdl. Gotta find out where it gets those mm's.
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
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 19:27.


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