Raised This Month: $ Target: $400
 0% 

Need Help - Newbie Scripter dont expect much


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eXist
Member
Join Date: Apr 2005
Old 04-17-2005 , 13:29   Need Help - Newbie Scripter dont expect much
Reply With Quote #1

I'm working on my first plugin, and its desiged to stack multiple people on the admin that gave the command. Heres my product, it compiles fine but the problem is it just does work, plain and simple. I have a feeling its a problem with the loop more than anything, but I'm stumped. Help is much appriciated.

Also 1 more question. I'm having trouble figuring out the difference between the commands
Code:
cmd_access(id,level,cid,1)
and
Code:
cmd_access(id,level,cid,0)

Thanks for all your help eXist.

Code:
#include <amxmodx> #include <fun> #include <amxmisc> #define PLUGIN_NAME "Stack X" #define PLUGIN_VERSION "1.0" #define PLUGIN_AUTHOR "eXist`" public plugin_init()     {         register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR) register_concmd("amx_stackall", "stack_all", ADMIN_KICK, "user All Players in the server will be stacked upon the admin.") public stack_all(id,level,cid)     {         if (!cmd_access(id,level,cid,1))             {                 return PLUGIN_HANDLED             }         new players[32], origin[3], playercount, player, a         get_user_origin(id, origin, 0)         get_players(players, playercount, "a")         for (a=0; a<playercount, a++; )             {                   player = players[a]                 origin[2] = origin[2] + 50                 set_user_origin(player, origin)         }                         return PLUGIN_HANDLED }
eXist is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 04-17-2005 , 14:40  
Reply With Quote #2

There is no difference, the last parameter specifies the minimal amount of arguments, but every command has at least one argument (namely the command name itself), so 0 and 1 will have the same effect. I think.

You should learn how to indent code properly ;)

Code:
#include <amxmodx> #include <fun> #include <amxmisc> #define PLUGIN_NAME "Stack X" #define PLUGIN_VERSION "1.0" #define PLUGIN_AUTHOR "eXist`" public plugin_init() {    register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)    register_concmd("amx_stackall", "stack_all", ADMIN_KICK, "user All Players in the server will be stacked upon the admin.") } public stack_all(id,level,cid) {    if (!cmd_access(id,level,cid,1))       return PLUGIN_HANDLED    new players[32], origin[3], playercount, player, a    get_user_origin(id, origin, 0)    get_players(players, playercount, "a")    for (a=0; a<playercount; a++)    {           player = players[a]       origin[2] += 50       set_user_origin(player, origin)    }    return PLUGIN_HANDLED }

Your problem was in the loop control structure.
You had:
Code:
for (a=0; a<playercount,a++;)

The program will do this on the for loop:
Code:
for (initializer; condition; increment) {    loop body }

1) Execute the initializer
2) Check condition; if it's false, don't continue
3) Execute the loop body
4) Execute the increment part
5) Jump to 2

In your case, it will do this:
1) Execute the initializer: set a to 0
2) Check condition:
Firstly, you'll need to know something about the comma operator:
If you write:
a,b
a will be evaluated first, and the value of the expression will be b, which will be evaluated second
So, you have this condition:
a<playercount,a++
a<playercount will be evaluated first, but it's value gets lost, so it doesn't matter
Then, a++ will be evaluated. The value of the whole a<playercount,a++ expression will be the value of a++ (as it's the right part of the comma operator). a++ increments a, but its value is still a (as opposed to ++a, which increments a, and its value is the already incremented a). So, a will be set to 1, and the value of a++ will be the original a, which is 0, so that the value of a<playercount,a++ will be also 0. 0 means false, so the loop is not continued, because the condition is false. So your loop body is never entered.

When you change it to:
Code:
for (a=0; a<playercount;a++)
it should work :D
__________________
hello, i am pm
PM is offline
eXist
Member
Join Date: Apr 2005
Old 04-17-2005 , 14:55  
Reply With Quote #3

Thank you very much for the complete and thurough reply. It is working correctly now and the funny thing is I meant to put a semi colen there, but hit comma by accident and at that point I didnt know what a comma was, finally in the end I learned what is was from you post. (sorry i ramble alot)

Thanks alot eXist`
eXist is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-17-2005 , 15:35  
Reply With Quote #4

Code:
cmd_access(id,level,cid,4)
amx_command <2> <3> <4>
The first is the command itself.
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
eXist
Member
Join Date: Apr 2005
Old 04-17-2005 , 16:26  
Reply With Quote #5

Good work V3x
thanks
eXist is offline
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 10:00.


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