Raised This Month: $ Target: $400
 0% 

UNSOLVED | Multiple ShowHudText?


Post New Thread Reply   
 
Thread Tools Display Modes
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 11-25-2014 , 10:10   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #21

I understand how to put the text on the screen. Thanks for the help.
However, im still not completely understanding the array thing.

Rephrase: I do understand how arrays work, but i dont know how to fill an array with 12 names.
__________________
SourcePawn Coding Level: Novice

Last edited by DJ Data; 11-25-2014 at 10:10.
DJ Data is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 11-25-2014 , 14:36   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #22

Take a look at GetClientName().
__________________
ddhoward is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 11-25-2014 , 16:10   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #23

Quote:
Originally Posted by ddhoward View Post
Take a look at GetClientName().
Not what i meant.
I'm gonna try stuff out, and I'll post a snippet in about 30 minutes.
__________________
SourcePawn Coding Level: Novice

Last edited by DJ Data; 11-25-2014 at 16:10.
DJ Data is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 11-25-2014 , 16:27   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #24

Working with arrays is pretty much identical to working with regular variables. You just need to specify the address (index) in the array that you want to use.

PHP Code:
new String:clientName[MAX_NAME_LENGTH];
GetClientName(clientclientNamesizeof(clientName)); 
PHP Code:
new String:clientNames[MAXPLAYERS+1][MAX_NAME_LENGTH];
GetClientName(clientclientNames[client], sizeof(clientNames[])); 
and if you want to get all players:

PHP Code:
new String:clientNames[MAXPLAYERS+1][MAX_NAME_LENGTH];
for (new 
client 1client <= MaxClientsclient++) {
    
GetClientName(clientclientNames[client], sizeof(clientNames[]));

__________________

Last edited by ddhoward; 11-25-2014 at 16:38.
ddhoward is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 11-25-2014 , 16:48   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #25

So the code above contains every client, ranging from 0-12 (since there are 13 players) ?
__________________
SourcePawn Coding Level: Novice

Last edited by DJ Data; 11-25-2014 at 16:48.
DJ Data is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-25-2014 , 16:53   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #26

Quote:
Originally Posted by DJ Data View Post
So the code above contains every client, ranging from 0-12 (since there are 13 players) ?
Players are 1-numbered... so 13 players would have indexes 1-13.

You could subtract one from the client index when storing things by client index and add one when iterating... but most people using MAXPLAYERS+1 as the array size instead and treat element 0 as a waste variable.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 11-25-2014 at 16:53.
Powerlord is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 11-25-2014 , 17:02   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #27

Ranging from 1 - 13, since there are 13 players.

(Note that if you are declaring the array globally, you need to use MAXPLAYERS rather than MaxClients in the declaration, and you should do the opposite if declaring it in an appropriate function.)

So, since there are 13 maximum players on the server, MaxClients is a variable that holds the value of 13. So we can mentally replace this:

Code:
new String:clientNames[MaxClients+1][MAX_NAME_LENGTH];
with this:

Code:
new String:clientNames[13 + 1][MAX_NAME_LENGTH];
Why 13 + 1? Why are we creating 14 slots when there are only 13 maximum players that this server can hold?

The reason is that arrays are 0 based, and player indexes are 1-based. The thirteen players are numbered 1-13, while an array with 13 indexes is numbered 0-12. So, rather than put "client-1" in the code everywhere where client indexes are used as array indexes, we simply increase the size of the array by 1 when creating the array. Much simpler.

So basically, here's a line-by-line breakdown.

PHP Code:
new String:clientNames[MaxClients+1][MAX_NAME_LENGTH]; 
This creates 14 String variables, each with a length that would be necessary to hold the longest possible name on the engine. If you are declaring this array globally rather than in a function, you should use MAXPLAYERS rather than MaxClients. (MaxClients represents the maximum connections that can be made simultaneously on that particular server, but the variable might not be given a value until it's too late. On the other hand, MAXPLAYERS represents the maximum player count supported by the engine, and is constant.)

PHP Code:
for (new client 1client <= MaxClientsclient++) { 
This begins a simple loop. When the loop begins, it creates a variable called "client" which starts out as 1. The loop is set to keep on going as long as "client" is less than or equal to MaxClients. Every time an iteration of the loop finishes, "client" goes up by 1.
PHP Code:
    GetClientName(clientclientNames[client], sizeof(clientNames[])); 
This takes the name of the player connected to the slot number represented by "client" and puts it into the clientNames array, in the index that is represented by that same "client" number.[/php]

Yes, this means that clientNames[0] is completely empty. But don't worry about it.
__________________

Last edited by ddhoward; 11-25-2014 at 17:04.
ddhoward is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 11-25-2014 , 17:03   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #28

Code:
new String:clientNames[MAXPLAYERS+1][MAX_NAME_LENGTH]; for (new client = 1; client <= MaxClients; client++) {     GetClientName(client, clientNames[client], sizeof(clientNames[])); }   new String:clientReady[MAXPLAYERS+1][MAX_NAME_LENGTH]; for (new client = 1; client <= MaxClients; client+++) {     // How do i store their isReady[client] states? } for(new i=1;i<=MaxClients;i++) {       if(!match_started)     {           SetHudTextParams(x, y, 9999.0, 0, 255, 0, 255);         ShowHudText(i, 1, "%s: %s", clientNames[1], isReady[???]) // 1 client is enough for now.     } }
__________________
SourcePawn Coding Level: Novice

Last edited by DJ Data; 11-25-2014 at 17:04.
DJ Data is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 11-25-2014 , 17:24   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #29

Isn't clientReady more suitable to be a boolean value? What strings are you planning on putting in there, and why are those strings of MAX_NAME_LENGTH length?


Quote:
// How do i store their isReady[client] states?
isReady[client] = true;

or

isReady[client] = false;

?

Or are you asking how to RETRIEVE those values, rather than store them?
__________________

Last edited by ddhoward; 11-25-2014 at 17:25.
ddhoward is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 11-25-2014 , 17:27   Re: UNSOLVED | Multiple ShowHudText?
Reply With Quote #30

Quote:
Originally Posted by ddhoward View Post
Isn't clientReady more suitable to be a boolean value? What strings are you planning on putting in there, and why are those strings of MAX_NAME_LENGTH length?
Yeah sorry didnt realize that. Bool:clientReady would be better

Quote:
Originally Posted by ddhoward View Post
isReady[client] = true;

or

isReady[client] = false;
That would just ready them up.

Quote:
Originally Posted by ddhoward View Post
Or are you asking how to RETRIEVE those values, rather than store them?
Yes.
__________________
SourcePawn Coding Level: Novice

Last edited by DJ Data; 11-25-2014 at 17:28.
DJ Data 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 01:18.


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