Raised This Month: $ Target: $400
 0% 

Two Dimensional Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 09-23-2011 , 10:18   Two Dimensional Array
Reply With Quote #1

Code:
new g_playername[33][33]

public client_putinserver(id)
{
	if(is_user_bot(id) || is_user_hltv(id))
		return;
		
	set_task(5.0, "LoadDataClient", id);
}

public client_disconnect(id)
	g_playername[id][0] = 0;

public LoadDataClient(id)
{
	if(!is_user_connected(id))
		return;

	get_user_name(id, g_playername[id], charsmax(g_playername))
	set_task(1.0, "ForwardCheck", id)
}

public ForwardCheck(id)
{	
	client_cmd(id, "name ^"%s^"", g_playername[id])
	g_playername[id][0] = 0
}
this is simple example, and my question is:
do i need to use two dimensional array? :S

Last edited by OvidiuS; 09-23-2011 at 10:20.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 09-23-2011 , 10:22   Re: Two Dimensional Array
Reply With Quote #2

You could pass the name to task.
PHP Code:
new name[32];
get_user_name(idnamecharsmax(name));
set_task(1.0"ForwardCheck"idnamesizeof name); 
PHP Code:
public ForwardCheck(name[], id)
    
client_cmd(id"name ^"%s^""name); 
__________________
hleV is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 09-23-2011 , 10:23   Re: Two Dimensional Array
Reply With Quote #3

Quote:
Originally Posted by hleV View Post
You could pass the name to task.
PHP Code:
new name[32];
get_user_name(idnamecharsmax(name));
set_task(1.0"ForwardCheck"idnamesizeof name); 
PHP Code:
public ForwardCheck(name[], id)
    
client_cmd(id"name ^"%s^""name); 
i didn't know that is possible, thanks a lot
OvidiuS is offline
Send a message via Skype™ to OvidiuS
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-23-2011 , 12:15   Re: Two Dimensional Array
Reply With Quote #4

Or just get the name only when you need it. Also, use set_user_info(id, "name", namvarhere). Also, your code makes no sense.
__________________
fysiks is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 09-23-2011 , 12:18   Re: Two Dimensional Array
Reply With Quote #5

Can i pass 2 arguments in set_task and how?
fysiks it's poor example and not fully written, just a part xD

what if name changes while doing the function? i need to restore it.

Last edited by OvidiuS; 09-23-2011 at 12:24.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-23-2011 , 12:23   Re: Two Dimensional Array
Reply With Quote #6

Yes, you can pack as much data as you need in the array.

new iData[ 35 ];

iData[ 0 ] = 55; //random integer
iData[ 1 ] = 99; //random integer
get_user_name( id , iData[ 2 ] , charsmax( iData ) - 2 );

You can also do multiple strings but you need to space them properly in the array so they can be retrieved in the called function.

That's just an example, if you can't figure it out show exactly what data you want passed to the function.

Edit: If you are worried about data changing between when set_task() is called and the task function you should just use global arrays or monitor the change and remove_task() then set_task() with corrected data.
__________________

Last edited by Bugsy; 09-23-2011 at 12:31.
Bugsy is online now
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 09-23-2011 , 12:39   Re: Two Dimensional Array
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
Yes, you can pack as much data as you need in the array.

new iData[ 35 ];

iData[ 0 ] = 55; //random integer
iData[ 1 ] = 99; //random integer
get_user_name( id , iData[ 2 ] , charsmax( iData ) - 2 );

You can also do multiple strings but you need to space them properly in the array so they can be retrieved in the called function.

That's just an example, if you can't figure it out show exactly what data you want passed to the function.

Edit: If you are worried about data changing between when set_task() is called and the task function you should just use global arrays or monitor the change and remove_task() then set_task() with corrected data.
that's what i'm worried about, how can i be sure that data won't change?
Only way is to pass it with the task, or use global array.
I can use global array, but like in the case i posted above, it need's to be two dimensional (or does it?), and i think that is wasting of resource, for such a task.

edit: by the way thanks everyone for helping

Last edited by OvidiuS; 09-23-2011 at 12:41.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-23-2011 , 12:57   Re: Two Dimensional Array
Reply With Quote #8

Your first code looks ok (youre already using a 2d array), should be charsmax( g_playername[] ) though.

You will need to hook name changes and update g_playername[] if name gets changed or just get name in the task function.
__________________
Bugsy is online now
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 09-23-2011 , 13:04   Re: Two Dimensional Array
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
Your first code looks ok (youre already using a 2d array), should be charsmax( g_playername[] ) though.

You will need to hook name changes and update g_playername[] if name gets changed or just get name in the task function.
i decided to pass arguments in set_task, i managed to do it, thank you
OvidiuS is offline
Send a message via Skype™ to OvidiuS
Reply


Thread Tools
Display Modes

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 19:39.


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