AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Invalid player 0 ?? (https://forums.alliedmods.net/showthread.php?t=18395)

Zenith77 09-23-2005 22:46

Invalid player 0 ??
 
i keep getting this

Code:

L 09/23/2005 - 22:41:39: Invalid player id 0
L 09/23/2005 - 22:41:39: [AMXX] Displaying debug trace (plugin "SuperSheild.amxx")
L 09/23/2005 - 22:41:39: [AMXX] Run time error 10: native error (native "get_user_origin")
L 09/23/2005 - 22:41:39: [AMXX]    [0] SuperSheild.sma::client_PreThink (line 60)

and i dont know why...

i think it may because its in public client_prethink?

and i just now added the 0 parameter to get_user_origin so dont if thats it either :/

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #define PLUGIN "Super Sheild!" #define VERSION "1.0" #define AUTHOR "Zenith77" new sheildEnabled[33] new mXBeam public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_cvar( "sheild_radius", " 500 " )         register_clcmd( "amx_sheild", "activate_sheild", ADMIN_IMMUNITY, " if you dont know, dont worry " )     register_clcmd( "amx_sheild_off", "deactivate_sheild", ADMIN_IMMUNITY, " nfkasnds " ) } public plugin_precache() {         mXBeam = precache_model( "sprites/xbeam1.spr" )         } public activate_sheild(id, level, cid) {         if( !cmd_access(id ,level ,cid, 1)) {         return PLUGIN_CONTINUE     }         sheildEnabled[id] = 1         return PLUGIN_CONTINUE } public deactivate_sheild(id, level, cid) {         if( !cmd_access(id, level, cid, 1)) {         return PLUGIN_CONTINUE     }         return PLUGIN_CONTINUE     } public client_PreThink(id) {         if( sheildEnabled[id] == 1) {         for( new i = 0; i <get_maxplayers(); i++) {                         new distance, origin[3], iOrigin[3]                         get_user_origin(id, origin, 0)             get_user_origin(i, iOrigin, 0)                         distance = get_distance(origin, iOrigin)                         if( distance <= get_cvar_num("sheild_radius") ) {                                                 new iRed = random_num(0, 255)                 new iBlue = random_num(0, 255)                 new iGreen = random_num(0, 255)                                                 message_begin(MSG_BROADCAST, SVC_TEMPENTITY)                 write_byte(1)       // TE_BEAMPOINT                 write_short(id)                 write_coord(iOrigin[0])                 write_coord(iOrigin[1])                 write_coord(iOrigin[2])                 write_short(mXBeam)                 write_byte(0)                 write_byte(10)                 write_byte(10)                 write_byte(30)                 write_byte(5)                 write_byte(iRed)                 write_byte(iBlue)                 write_byte(iGreen)                 write_byte(200)                 write_byte(15)                 message_end()                                 user_kill(i, 1)             }         }     } }

pdoubleopdawg 09-23-2005 22:47

if(!is_user_connected(i)) {
return PLUGIN_HANDLED
}

Player 0 is the server.
i is getting all of the players, including the server.

Xanimos 09-24-2005 00:25

Even better dont start with "new i = 0" use "new i = 1"
0 refers to the server so dont check that as a player.

SidLuke 09-24-2005 06:10

for( new i = 0; i <get_maxplayers(); i++)
should be
for( new i = 1; i <=get_maxplayers(); i++)

Zenith77 09-24-2005 20:30

umm ok...i added that and if id == 1 but it doesnt work. I tried changing return PLUGIN_CONTINUE to just continue but it still doesnt work....


this is what i have right now

btw, testing this with bots so dont know if thats the prob

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #define PLUGIN "Super Sheild!" #define VERSION "1.0" #define AUTHOR "Zenith77" new mXBeam public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_cvar( "sheild_radius", " 200 " )         register_clcmd( "amx_sheild", "activate_sheild", ADMIN_IMMUNITY, " if you dont know, dont worry " )     } public plugin_precache() {         mXBeam = precache_model( "sprites/xbeam1.spr" )         } public activate_sheild(id, level, cid) {         if( !cmd_access(id ,level ,cid, 1)) {         return PLUGIN_CONTINUE     }     new distance, origin[3], iOrigin[3]         get_user_origin(id, origin, 0)     for( new i = 1; i <get_maxplayers(); i++) {                 if( !is_user_connected(i) || id == i) continue                                 get_user_origin(i, iOrigin, 0)                 distance = get_distance(origin, iOrigin)                 if( distance <= get_cvar_num("sheild_radius") ) {                                     new iRed = random_num(0, 255)             new iBlue = random_num(0, 255)             new iGreen = random_num(0, 255)                         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)             write_byte(1)       // TE_BEAMPOINT             write_short(id)             write_coord(iOrigin[0])             write_coord(iOrigin[1])             write_coord(iOrigin[2])             write_short(mXBeam)             write_byte(0)             write_byte(10)             write_byte(10)             write_byte(30)             write_byte(5)             write_byte(iRed)             write_byte(iBlue)             write_byte(iGreen)             write_byte(200)             write_byte(15)             message_end()                         user_kill(i, 1) //ZOMG I GOT ELECTRICUTED!!!!!         }     }         return PLUGIN_HANDLED }

Brad 09-24-2005 20:44

Quote:

Originally Posted by SidLuke
for( new i = 0; i <get_maxplayers(); i++)
should be
for( new i = 1; i <=get_maxplayers(); i++)

Zenith, you didn't do this. Note the "<=" part.

Zenith77 09-24-2005 20:58

EDIT: nm works great :)

Xanimos 09-24-2005 23:09

Well there are some things that you did that you shouldn't do. Yes it may work but its really improper.

You should use
Code:
new Players[32] , pnum; get_players(Players , pnum , "c"); //If you want just alive players add 'a' before the 'c'             //If you want just dead players add 'b' before the 'c'             //The 'c' makes it so it doesnt return bots for(new i = 0; i < pnum; i++) {     //Then where ever you have i in your code replace with Players[i] }

Reasons.
1) Dont call get_maxplayers() in a for loop. It just requires that that function be called ever iteration.
2) This is much more precise. It wont be called for an id of a player that is not in the server. And doesnt require an if statement after the for loop.


All times are GMT -4. The time now is 07:05.

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