Raised This Month: $51 Target: $400
 12% 

GetPlayers()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-24-2016 , 20:13   GetPlayers()
Reply With Quote #1

Hello guys

So i'm trying to code a stock wich doing basicaly what get_players is doing, i wanne made to avoid making a loop,creating new variables, do all the process all the time in all my plugins.

My no.1 problems is that i cannot test it because i don't know how to install bots and i don't have an server wich players playing in, so here's the code, i hope it has sense for you:

Code:
/*     RETURN_TYPE:         "1" - > Return all players indexes found.         "0" - > Return the total number of users founded */ GetPlayers( RETURN_TYPE = 1 , flags[] = "" , team[]= "" ) {     new Players[32], PlayersCount, PlayerBits;       if( contain( flags, "e" ) > -1 )         get_players( Players, PlayersCount, flags, team)     else         get_players( Players, PlayersCount , flags );     for( new i = 0 ; i < PlayersCount  ; i++ )         PlayerBits |= ( 1 << Players[i] );             if( RETURN_TYPE >= 1 )         return PlayerBits;     return PlayersCount;        }
__________________
Project: Among Us

Last edited by Craxor; 09-24-2016 at 20:14.
Craxor is offline
Send a message via ICQ to Craxor
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-24-2016 , 20:27   Re: GetPlayers()
Reply With Quote #2

I suppose will work, i do some tests with the following code and and give me the answers i want to:
PHP Code:
#include <amxmodx>

const Checker 8;

public 
plugin_init( )
{
    
register_srvcmd"test""ptest" );
    
register_srvcmd"check""pcheck" );
}

public 
pcheck( )
{
    new 
Bits Printex( );

    if( 
Bits & ( << Checker ) )
    {
        
server_print" bits contain also number 8" );
    }
}

public 
ptest( )
{
    
server_print(" Bits output: %i"Printex() );
    
}

Printex()
{
    new 
bits;

    for( new 
i=0<= 10i++ )
    {
        
server_print(" Loop time: %i");
        
bits |= ( << );
        
    }

    return 
bits;

When i write "check" in server console:

] check
Loop time: 0
Loop time: 1
Loop time: 2
Loop time: 3
Loop time: 4
Loop time: 5
Loop time: 6
Loop time: 7
Loop time: 8
Loop time: 9
Loop time: 10
bits contain also number 8

So GetPlayers() should work, anyway, if someone else have something to say to the code or have the posibility to test with real players, regards!
__________________
Project: Among Us

Last edited by Craxor; 09-24-2016 at 20:28.
Craxor is offline
Send a message via ICQ to Craxor
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-24-2016 , 20:51   Re: GetPlayers()
Reply With Quote #3

If you will give me 15 mins i will explain to you how it works
__________________
Depresie is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-24-2016 , 21:15   Re: GetPlayers()
Reply With Quote #4

Okay, first, let me explain to you what is an array and what is a variable

This is a variable, it can hold only one value
PHP Code:
new variable 
This is an array, The number 32 is the size of the array, it can hold as many values as it's size, so in our case it can hold 32 different variables
variable[0] can hold one value, variable[1] can hold a different variable and so on until variable[31], not variable[32] because in an array the order starts from 0 and ends at the size - 1
PHP Code:
new variable[32

Now we have the get_players native
PHP Code:
get_players(param 1param 2flags
in param 1 it will store the indexes of the players from the server, but we have 32 players, so 32 different values, that means we need an array to be able to store them all
PHP Code:
new PlayerIndexes[32
in param 2 it will store the total number of players on the server, so since it is a single value, we can use a variable
PHP Code:
new PlayerNumber 
So we will have
PHP Code:
get_players(PlayerIndexesPlayerNumberflags
Now the get_players native will store the indexes of all the players into the PlayerIndexes and the total number of the players on the server in the PlayerNumber variable
So PlayerNumber = the total number of players on the server, that means you don't need to loop anymore to count them, the get_players native already did that

Now here comes the part with the loop, the loop you use to execute something for every player
Now i know you want to make a get_players stock to not write it in every function, but the truth is that it is not efficient to do that for various reasons which i am too bored to explain
__________________

Last edited by Depresie; 09-24-2016 at 21:19.
Depresie is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-24-2016 , 21:47   Re: GetPlayers()
Reply With Quote #5

You should go too sleep

I'm happy that you understand thesee but where in the post did i say i don't understand my own code?

I was just wondering if i made correctly the bit-field, and yes is corect if you can see my second reply i do something similiar to check.

Anyway, the only and only reason that is not efficient it is because you would need to use two times the stock for getting the count and for retrieve player indexes, i will find a method in future.
But that's all, in rest is not more or less eficiently like get_players, not only that, it is exactly get_players() ) ... but anyway...
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-24-2016 , 21:53   Re: GetPlayers()
Reply With Quote #6

You cannot return the player indexes using a variable, you will need an array, and i don't think you can return from the stock 32 values, only 1

But you could declare a global array and use that to store the player indexes, but again, it will be more efficient to do it in the function that use a stock
You can do the same with the player number, store it in a global variable, not a local one, so you won't need to call the stock twice or w/e

anyway, good nite, i will take a better look tomorow at this, i'm burned atm
__________________

Last edited by Depresie; 09-24-2016 at 21:57.
Depresie is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-24-2016 , 21:57   Re: GetPlayers()
Reply With Quote #7

Quote:
Originally Posted by Depresie View Post
You cannot return the player indexes using a variable, you will need an array, and i don't think you can return from the stock 32 values, only 1

But you could declare a global array and use that to store the player indexes, but again, it will be more efficient to do it in the function that use a stock
It is a bit-field, man do you even look at the code before talking? Also did you look at my code-test to check if is working? on the second reply?

DId you make some checks with the codes i posted above or you just look 3 seconds and start over-thinking bullshits? Sorry for my exageration but you realy annoyng me...
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-24-2016 , 23:08   Re: GetPlayers()
Reply With Quote #8

Quote:
Originally Posted by Craxor View Post
So i'm trying to code a stock wich doing basicaly what get_players is doing, i wanne made to avoid making a loop,creating new variables, do all the process all the time in all my plugins.
Using get_players() is essentially trivial so there is no real need to obfuscate it further by trying to do what you are doing. That is why get_players() exists as it is and has been there for many many years without any major changes.

Regarding your stock, returning two entirely different types of data from a single function is illogical. Also, having the players in a bit-field just makes other code need to be more complex.

So, I think you are over complicating things and ultimately making it harder for yourself instead of learning how to do it normally.
__________________

Last edited by fysiks; 09-24-2016 at 23:09.
fysiks is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-24-2016 , 23:25   Re: GetPlayers()
Reply With Quote #9

fysiks , yes you are totaly true ...

And also is returning just the Bits so i can use them just to check if that 'id' is inside of result and that's realy usesless, because i would need again to take players and check each one in part to see if they are inside of the bits, and thats realy stupid not just useles, i will just do it normaly, anyway, until now i reach this point:
( even if it has no sense ).

PHP Code:
#include <amxmodx>


public plugin_init( )
{
    
register_clcmd"say /test""test" );
}

public 
testid )
{
    new 
TeroAliveBits GetPlayers1"ae""TERRORIST" );

    if( 
TeroAliveBits & ( << id ) )
    {
        
// very good, lot of sense ...
        
client_printidprint_chat"You are one of the alive terrorists!" );
    }

    

}
GetPlayerstypoflags[] = "" team[]= "" )
{
    new 
Players[32], PlayersCountbitsPlayersID;
 
    if( 
containflags"e" ) > -)
        
get_playersPlayersPlayersCountflagsteam)
    else
        
get_playersPlayersPlayersCount flags );

    for( new 
PlayersCount  i++ ) 
        
bitsPlayersID |= ( << Players[i] );
        
    return 
typo bitsPlayersID PlayersCount;
             

I can't find a way to transfer the Bits in Id ... anyway ..
__________________
Project: Among Us

Last edited by Craxor; 09-25-2016 at 03:17.
Craxor is offline
Send a message via ICQ to Craxor
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-25-2016 , 06:37   Re: GetPlayers()
Reply With Quote #10

Here is what you can do to create a stock how you want, but there are many reasons why this is stupid..

First, even if you create this stock, you will still need to loop in the function not in the stock
So you will have a stock holding just the get_players native
Then, in order to get the indexes of the players and the number of the players from the stock you will need to use global variable and array, not local, which uses more memory

But here you have an example, but as i said you will need to do the loop inside the function, ofc you can make a stock for looping, but it gets very complicated
Also creating a stock for a loop is like creating a stock for an if
PHP Code:
new ArrayPlayers[32]
new 
NumPlayers

stock your_get_players_stock
()
{
         
get_players(ArrayPlayersNumPlayersflags)

__________________

Last edited by Depresie; 09-25-2016 at 06:37.
Depresie 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 13:32.


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