AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Keeps spawning ents at XYZ (0,0,0) (https://forums.alliedmods.net/showthread.php?t=9938)

TotalNoobScripter 02-04-2005 09:30

Keeps spawning ents at XYZ (0,0,0)
 
..., around 4 or 5 entities of this code get stacked on 0,0,0 (XYZ) and 4 or 5 otheres are stacked upon 0,0,300. There are also 2,3 civs stacked at around 0,500,300.... why?
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 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")             new fakecivcreateent[14]     for (new i = 0; i<3; i++ ) {         //new randomnumber         //randomnumber = (random_num(0,14))         new Float:fakecivorigin[3];         fakecivorigin[0] = fakecivX[i];         fakecivorigin[1] = fakecivY[i];         fakecivorigin[2] = fakecivZ[i];         new entclassname[14]         format(entclassname[i],16,"fake_civilian%i",i)         fakecivcreateent[i] = create_entity("info_target")         entity_set_string(fakecivcreateent[i],EV_SZ_classname,entclassname[i]);         entity_set_model(fakecivcreateent[i],"models/barry.mdl");         entity_set_origin(fakecivcreateent[i],fakecivorigin)         DispatchSpawn(fakecivcreateent[i])     }     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[14]             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") }

XxAvalanchexX 02-04-2005 15:52

I'm not sure, maybe the same day I get rich, messing up memory positions could screw something up. Notice this:

Code:
new entclassname[14] format(entclassname[i],16,"fake_civilian%i",i)

This appears twice throughout your code. Your create the array with a size of 14, and format it with a size of 16. Change the 16 to a 13 or the 14 to a 17 and that should help possible memory errors.

Additionally, going through a big loop (okay, well it's not really THAT big) every touch really shouldn't be done. Just see if the classname contains the string "fake_civilian".

TotalNoobScripter 02-04-2005 19:09

oh.. hehe oops... typo. Actually it was a double typo :D

TotalNoobScripter 02-04-2005 20:09

great......... now when i spawnthemmofos... ED_Alloc: No Free Adicts. Does that mean i spawn too many or I spawn too much at one time? What if i were to merge it with another plugin, would that work? I do not think its too many in total as I tried only spawning 2, and it stll crashed. *MAXPLAYERS = 32 if that has any effect*

XxAvalanchexX 02-04-2005 20:37

It's probably spawning them too fast. When I send too many messages at once without I delay I get a "no free somethings" error. Perhaps create a "createnpc(npc)" function, and use set task to put a half second or so in between, and then send the id parameter for the set_task as the id of the NPC.

TotalNoobScripter 02-04-2005 21:34

moved to another topic.


All times are GMT -4. The time now is 19:26.

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