little help
some why this code dont work
can anyone fix it Code:
#include <amxmodx> |
Re: little help
Don't need a plugin :
Quote:
|
Re: little help
Because szID is the string array holding the player's Steam ID. The value in your server_cmd() line should instead be get_user_userid( client ).
Also your loop should be checking size of array not size of array - 1 Otherwise it will not check the last string. Forgot to mention that every player who joins your server is going to be kicked unless their Steam ID matches the first one in the array. Quote:
|
Re: little help
Quote:
|
Re: little help
Code:
#include <amxmodx>if(!(equali( szID , SteamIds[ i ] ) ) ) its kicks all |
Re: little help
Put ! in front of equali
Like this PHP Code:
|
Re: little help
The problem with the code is the loop is badly written.
The only reason it would let anyone in the server is if the SteamIds array contains one or more of the same SteamId. Let me explain further. Let's say you have these steamids stored in that array: STEAM_0:0:1234567 STEAM_0:0:2345678 STEAM_0:0:4567890 Now, the player with the id STEAM_0:0:2345678 joins. At the first run of the loop it would compare the steamid. Since STEAM_0:0:2345678 is not equal to STEAM_0:0:1234567 ( first in loop ) it kicks immediately. Now let's say the person who's first in the array joins. The first run will be fine because STEAM_0:0:1234567 does equal to STEAM_0:0:1234567. The problem is the loop doesn't know this is a point to break, so it would continue to the second steamid. And because STEAM_0:0:12345678 does not equal to STEAM_0:0:2345678 the person will then be kicked even though the first run of the loop was a success. Basically you have to do something like this: In the first two examples you can continue adding code after the loop for both statements (if or if not the player was found) The first example is using a variable called match_found. This will add readability and make it easier for people to understand. You, of course, are using one more variable, but that's not really any problem. Code:
The second example can be a bit more confusing for beginners. This is how it works: The loop increments after every finished loop. It will run as long as the statement (i < sizeof SteamIds) is true. If there's a match, the variable i will always be lower than sizeof SteamIds because we break the function before it increments the variable i. If there's no match it will run the loop, incrementing the variable i until it no longer matches condition. I.e. the variable i is equal to or larger than sizeof SteamIds. Because it's incrementing in steps of 1, it will always equal to sizeof SteamIds. Code:
The third differs that it will return upon match, making all the code under the loop unreachable for players found in the array of SteamIds. Code:
So which one should you use? The two first is all about coding style and personal preference. The third option is the most simple one, not requiring any variables or double-checking. But it has the least amount of flexibility. It depends on if you want to do anything to the actual matching players. If you want to learn more, here's how a for loop works (more or less): Code:
Code:
i is set to 0Code:
Code:
i is set to 0So basically, a for loop constructed like this: Code:
0, 1, 2, 3 1, 2, 3 1, 2, 3 and so further It's the same as writing a while loop like this: Code:
|
Re: little help
Quote:
|
| All times are GMT -4. The time now is 19:00. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.