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

Setting a string for each client


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 02-04-2016 , 11:36   Setting a string for each client
Reply With Quote #1

Is this the correct way to make a string for each client. Sorry, if the question sound a little stupid
PHP Code:
new btime[33][64], breason[33][64];

public 
client_putinserver(id)
{
    
formatex(btime[id], charsmax(btime[]), "1440");
    
formatex(breason[id], charsmax(breason[]), "hack");

KiLLeR. is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-04-2016 , 11:47   Re: Setting a string for each client
Reply With Quote #2

That looks okay. What exactly are you trying to accomplish?
klippy is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 02-04-2016 , 12:10   Re: Setting a string for each client
Reply With Quote #3

I made a custom ban menu, where the admins can change the time and reason from the options, but I need to set a something by default. By the way, thanks for the reply.

Sorry for my English!

Last edited by KiLLeR.; 02-04-2016 at 12:11.
KiLLeR. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-04-2016 , 20:42   Re: Setting a string for each client
Reply With Quote #4

formatex() should only be used when you are actually FORMATTING the string. In your example, you are only copying a string to a string variable so you should use copy() instead.

copy() takes the same parameters and in the same order as formatex():
PHP Code:
new btime[33][64], breason[33][64];

public 
client_putinserver(id)
{
    
copy(btime[id], charsmax(btime[]), "1440");
    
copy(breason[id], charsmax(breason[]), "hack");
}  

//This is an example of when formatex() should be used:
public client_putinserver(id)
{
    
formatex(btime[id], charsmax(btime[]), "hello %s it is %d oclock" "bugsy" 10 );
    
formatex(breason[id], charsmax(breason[]), "hack %s" "stuff" );

__________________

Last edited by Bugsy; 02-04-2016 at 20:43.
Bugsy is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 02-07-2016 , 10:52   Re: Setting a string for each client
Reply With Quote #5

hahaha. lol. why u are setting the same strung for all players, just make a cvar for default time and reason and then set task for cvar parse or use get_pcvar_string on ban and done.
siriusmd99 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-07-2016 , 11:45   Re: Setting a string for each client
Reply With Quote #6

Quote:
Originally Posted by siriusmd99 View Post
hahaha. lol. why u are setting the same strung for all players, just make a cvar for default time and reason and then set task for cvar parse or use get_pcvar_string on ban and done.
"hahaha" "lol" ? What is so funny about his question?

I don't think someone can tell exactly what he is doing based on what he posted. Many times people post snippets like that when they are trying to figure something out.
__________________
Bugsy is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 02-07-2016 , 12:03   Re: Setting a string for each client
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
"hahaha" "lol" ? What is so funny about his question?

I don't think someone can tell exactly what he is doing based on what he posted. Many times people post snippets like that when they are trying to figure something out.
That's why I laughed , I tried to make him pay attention to what he said maybe he is trying to do something else, but there is no sense to add the same string to every player. He can add 2 string constants at the top of the plugin or cvars.

By the way, can you look on my recent topic I have also a funny question? I can't solve it, thanks.

Last edited by siriusmd99; 02-07-2016 at 12:05.
siriusmd99 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-07-2016 , 12:19   Re: Setting a string for each client
Reply With Quote #8

I don't get it, but ok.
__________________
Bugsy is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 02-07-2016 , 15:57   Re: Setting a string for each client
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
formatex() should only be used when you are actually FORMATTING the string. In your example, you are only copying a string to a string variable so you should use copy() instead.

copy() takes the same parameters and in the same order as formatex():
PHP Code:
new btime[33][64], breason[33][64];

public 
client_putinserver(id)
{
    
copy(btime[id], charsmax(btime[]), "1440");
    
copy(breason[id], charsmax(breason[]), "hack");
}  

//This is an example of when formatex() should be used:
public client_putinserver(id)
{
    
formatex(btime[id], charsmax(btime[]), "hello %s it is %d oclock" "bugsy" 10 );
    
formatex(breason[id], charsmax(breason[]), "hack %s" "stuff" );

Thanks for your correction. That's the right thing that I wanted to hear. It crossed my mind to use 'copy(...)', just I wasn't sure and decided to ask. The thing what I trying to do is already done and works.

P.S. @siriusmd99: The btime holds a time for bans, where each admin can change it as he decide. So if I use CVARs, if one admin change the time, it will be changed for all admins. Same for breason!

Last edited by KiLLeR.; 02-07-2016 at 16:10.
KiLLeR. is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 02-07-2016 , 16:23   Re: Setting a string for each client
Reply With Quote #10

aha, i thought it was bantime for players.my wrong, sorry.
siriusmd99 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 08:24.


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