AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   If cvar is enabled, hide /custom command (https://forums.alliedmods.net/showthread.php?t=318688)

MihailoZ 09-14-2019 16:13

If cvar is enabled, hide /custom command
 
Hello,

I am creating a plugin with /custom command with cvars.

I created a cvar that can hide or display /custom command but I always get an error:

Warning: Function should return a value on line 65.


What I want to do is:

IF cvar is enabled, hide /custom command and do the action.
IF cvar is disabled, show /custom command and do the action.


Even with a warning, my plugin works. But I don't want it to display any warning.


Thank you.

MihailoZ 09-14-2019 16:18

Re: If cvar is enabled, hide /custom command
 
Okay. I solved the problem. I will write here how so I can help others.

If you have any return PLUGIN_HANDLED_MAIN; or return PLUGIN_HANDLED (I guess) as a cvar,

you MUST add return PLUGIN_CONTINUE; in the end of public blabla(id) {

MihailoZ 09-14-2019 20:24

Re: If cvar is enabled, hide /custom command
 
Another question is:

if cvar (string) has no input, if it's empty, client_print(id,print_chat,"Custom message");

but if cvar has some input I want to print just that input.

LearninG 09-15-2019 02:17

Re: If cvar is enabled, hide /custom command
 
It's useless in messages , because you can't do "space" in cvar :
Example :
"Type /menu to see game menu."
will be shown as ( in chat) :
"Type"

with cvar :
Code:
#include <amxmodx> new cvar_string public plugin_init() {         cvar_string = register_cvar("amx_message" , "Hello!")         register_clcmd("say /message" , "some_func") } public some_func(id) {         new My_Cvar[7]         get_pcvar_string(cvar_string , My_Cvar , charsmax(My_Cvar))         client_print(id , print_chat , "%s" , My_Cvar) }
another way without cvar :
Code:
#include <amxmodx> new const MESSAGE[] = "Welcome to server" public plugin_init() {         register_clcmd("say /message" , "some_func") } public some_func(id) {         client_print(id , print_chat , "%s" , MESSAGE) }

AmXDusT 09-15-2019 03:18

Re: If cvar is enabled, hide /custom command
 
Space works in cvars.

Create a big enough string in your function that can get all the cvar string and use get_pcvar_string to copy it there.

Check string's length to see if it has anything in it ( "strlen( your_string )" ) and print either the string or your custom message (through client_print, like LearninG's sample)

LearninG 09-15-2019 04:17

Re: If cvar is enabled, hide /custom command
 
Quote:

Originally Posted by AmXDusT (Post 2667026)
Space works in cvars.

yes , i did :
Code:

amx_message Type /menu to see game menu
should be :
Code:

amx_message "Type /menu to see game menu"

MihailoZ 09-15-2019 04:57

Re: If cvar is enabled, hide /custom command
 
Thank you guys. I will try that.

Is it possible to add IF cvar1 = something AND cvar2 = something { do this }

AmXDusT 09-15-2019 06:23

Re: If cvar is enabled, hide /custom command
 
https://www.amxmodx.org/api/string/equali or https://www.amxmodx.org/api/string/equal


All times are GMT -4. The time now is 17:25.

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