Raised This Month: $32 Target: $400
 8% 

Two question about sp syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
WilliamDG
Junior Member
Join Date: Oct 2016
Location: Italy
Old 05-17-2017 , 11:45   Two question about sp syntax
Reply With Quote #1

Hi guys,

1)can someone tell me how can i manage the server chat?
In my CSGO server if i change the convar "sv_password" it print on the chat the following message:

Server cvar 'sv_password' changed to ***PROTECTED***

So is possible to manage it? (With manage i mean modify or better: remove it with a "return Plugin_Stop;" instead the callback but how can i do that function? Is present on sourcepawn/sourcemod?)


2)Dynamic arrays...
Suppose that i want to create an array size with a convar (sm_myArraySize = 5) and i put it on array declaration:

PHP Code:
ConVar myConvar;


myConvar CreateConVar("sm_myArraySize" etc etc...)
char myArray[GetConVarInt(myConvar)];     //Obviously on this line compiler generate an error. 
How can i do something like that?

Thankyou in advance for help!

Last edited by WilliamDG; 05-17-2017 at 11:52.
WilliamDG is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 05-17-2017 , 14:24   Re: Two question about sp syntax
Reply With Quote #2

1)I have no idea, what kind of user message the server sends to tell a client a cvar value changed, but try by starting hooking those 3:
Code:
HookUserMessage(GetUserMessageId("SayText2"), Hook_BlockUserMessage, true); HookUserMessage(GetUserMessageId("SayText"), Hook_BlockUserMessage, true); HookUserMessage(GetUserMessageId("TextMsg"), Hook_BlockUserMessage, true);

Edit: See asherkin's post.

2)
If you want to use dynamic array, you must set it up like this:
Code:
char[] myArray = new char[myConvar.IntValue];
__________________

Last edited by Benoist3012; 05-17-2017 at 15:16.
Benoist3012 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-17-2017 , 14:50   Re: Two question about sp syntax
Reply With Quote #3

If you're changing sv_password in a plugin, just remove FCVAR_NOTIFY from it before setting it, and add it back afterwards.
__________________
asherkin is offline
WilliamDG
Junior Member
Join Date: Oct 2016
Location: Italy
Old 05-17-2017 , 20:50   Re: Two question about sp syntax
Reply With Quote #4

1) I had time only to test the ConVar thing, thank you guys for the help and for the quick reply!!!

i solved it in this way:
PHP Code:
SetConVarFlags(FindConVar("sv_password"), FCVAR_NEVER_AS_STRING);
ServerCommand("sv_password %s"string); 
2) For dynamic array i will test it tomorrow and i will write here the feedback!

Thank you again

Last edited by WilliamDG; 05-17-2017 at 20:51.
WilliamDG is offline
WilliamDG
Junior Member
Join Date: Oct 2016
Location: Italy
Old 05-19-2017 , 13:22   Re: Two question about sp syntax
Reply With Quote #5

Quote:
Originally Posted by Benoist3012 View Post
2)
If you want to use dynamic array, you must set it up like this:
Code:
char[] myArray = new char[myConvar.IntValue];
Ok, i have tested the dynamic array thing.
It work perfectly and i thank you for quick reply!

Only a little question, if i'm in this situation:

PHP Code:
ConVar myConvar;


myConvar CreateConVar("sm_myArraySize" etc etc...)
char[] myArray = new char[myConvar.IntValue]; 
and after i want use the sizeoff command to get the length it give me an error so i supposed to use again the myConvar.IntValue

My question is: There is another way to get the sizeoff or this is the only way to get the dynamic array length?

Thank you again guys!!!
WilliamDG is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-19-2017 , 15:54   Re: Two question about sp syntax
Reply With Quote #6

sizeof is evaluated at compile-time, you can't use it on dynamic arrays.
__________________
asherkin is offline
Byte
Senior Member
Join Date: Jun 2010
Location: 📦 CCSPlayer
Old 05-20-2017 , 01:51   Re: Two question about sp syntax
Reply With Quote #7

Quote:
Originally Posted by asherkin View Post
If you're changing sv_password in a plugin, just remove FCVAR_NOTIFY from it before setting it, and add it back afterwards.
Alternatively:

PHP Code:
public void OnPluginStart()
{
  
HookEvent("server_cvar"Event_ServerCvarEventHookMode_Pre);
}

public 
Action Event_ServerCvar(Event event, const char[] namebool dontBroadcast)
{
  
char cvarName[128];
  
event.GetString("cvarname"cvarNamesizeof(cvarName));
  
  if (
StrEqual(cvarName"sv_password")) {
    return 
Plugin_Handled;
  }

  return 
Plugin_Continue;  

Another similar way:
PHP Code:
public void OnPluginStart()
{
  
HookEvent("server_cvar"Event_ServerCvarEventHookMode_Pre);
}

public 
Action Event_ServerCvar(Event event, const char[] namebool dontBroadcast)
{
  
char cvarName[128];
  
event.GetString("cvarname"cvarNamesizeof(cvarName));
  
  if (
StrEqual(cvarName"sv_password")) {
    
event.BroadcastDisabled true;
  }

  return 
Plugin_Continue;  

__________________
STEAM: /id/invexbyte | Github: Mo Beigi | Discord: Byte#0017
Community: Invex Gaming | My Plugins: Click Me!


Last edited by Byte; 05-20-2017 at 01:54.
Byte is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 05-20-2017 , 08:26   Re: Two question about sp syntax
Reply With Quote #8

Quote:
Originally Posted by WilliamDG View Post
Ok, i have tested the dynamic array thing.
It work perfectly and i thank you for quick reply!

Only a little question, if i'm in this situation:

PHP Code:
ConVar myConvar;


myConvar CreateConVar("sm_myArraySize" etc etc...)
char[] myArray = new char[myConvar.IntValue]; 
and after i want use the sizeoff command to get the length it give me an error so i supposed to use again the myConvar.IntValue

My question is: There is another way to get the sizeoff or this is the only way to get the dynamic array length?

Thank you again guys!!!
You have no choice but do:
Code:
int iSize = myConvar.IntValue; char[] myArray = new char[iSize]; Format(myArray, iSize, "%s%s",something, something2);
__________________
Benoist3012 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 05-21-2017 , 18:07   Re: Two question about sp syntax
Reply With Quote #9

Have a look at Dynamic.
__________________
Neuro Toxin is offline
WilliamDG
Junior Member
Join Date: Oct 2016
Location: Italy
Old 05-22-2017 , 07:05   Re: Two question about sp syntax
Reply With Quote #10

Thank you for all help guys!!
WilliamDG 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 22:50.


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