AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved set_lights in cvar (https://forums.alliedmods.net/showthread.php?t=325599)

chickez 06-28-2020 17:36

set_lights in cvar
 
Hey.

I'm beginner in scripting.
I want to create cvar, which will change the light.

Example: server_light "b"
Then set_lights is set to "b".

But doesn't work.

PHP Code:

#include <amxmodx>
#include <engine>

#define PLUGIN "serverLight"
#define VERSION "0.1"
#define AUTHOR "chicken"

new lights[2]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_cvar("server_light"lights)
}

public 
setServerLights() {
    
set_lights(lights)


Any help? Thank you!

fysiks 06-28-2020 21:49

Re: set_lights in cvar
 
You need to read the cvar at some point and use it when you call set_lights(). When do you want this action to occur?

supertrio17 06-28-2020 22:29

Re: set_lights in cvar
 
I believe that this is what you want:
PHP Code:

#include <amxmodx>
#include <engine>

#define PLUGIN "serverLight"
#define VERSION "0.2"
#define AUTHOR "chicken"

new g_lights

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_lights register_cvar"amxx_lights""a" ); //default value would be a
    
register_event("HLTV""setServerLights""a""1=0""2=0"//every new round cvar gets updated
}

public 
setServerLights() 
{
    new 
lights[2];
    
get_pcvar_string(g_lightslights2);
    
set_lights(lights);



chickez 06-28-2020 23:48

Re: set_lights in cvar
 
Yes, that is, what i want.

PHP Code:

new lights[2];
get_pcvar_string(g_lightslights2); 

So, get_pcvar_string works like this ye? I understood this command otherwise.


Thank you for help! :)

supertrio17 06-29-2020 02:51

Re: set_lights in cvar
 
Well because it was a letter it needs to have a string, everything you want to know is here.

HamletEagle 06-29-2020 04:01

Re: set_lights in cvar
 
Quote:

Originally Posted by chickez (Post 2707752)
Yes, that is, what i want.

PHP Code:

new lights[2];
get_pcvar_string(g_lightslights2); 

So, get_pcvar_string works like this ye? I understood this command otherwise.

Thank you for help! :)

This looks like a potential buffer overflow. Use charsmax to ensure the proper size is passed and to avoid hardcoding.

fysiks 06-29-2020 23:34

Re: set_lights in cvar
 
Quote:

Originally Posted by supertrio17 (Post 2707748)
I believe that this is what you want:
PHP Code:

#include <amxmodx>
#include <engine>

#define PLUGIN "serverLight"
#define VERSION "0.2"
#define AUTHOR "chicken"

new g_lights

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_lights register_cvar"amxx_lights""a" ); //default value would be a
    
register_event("HLTV""setServerLights""a""1=0""2=0"//every new round cvar gets updated
}

public 
setServerLights() 
{
    new 
lights[2];
    
get_pcvar_string(g_lightslights2);
    
set_lights(lights);



You'll need to learn how strings work in Pawn.

Natsheh 06-30-2020 05:33

Re: set_lights in cvar
 
Which amxx version are you using ?

If you're using amxx version 183 or latter which most recommended vers is the latest you can hook cvar change and change the lights instantly rather than waiting for round HLTV event to be called.

HamletEagle 06-30-2020 06:08

Re: set_lights in cvar
 
Quote:

Originally Posted by Natsheh (Post 2707943)
Which amxx version are you using ?

If you're using amxx version 183 or latter which most recommended vers is the latest you can hook cvar change and change the lights instantly rather than waiting for round HLTV event to be called.

The latest version is 1.8.2

chickez 06-30-2020 06:20

Re: set_lights in cvar
 
Ye, it's 1.8.2, the latest.

Quote:

Originally Posted by HamletEagle (Post 2707772)
This looks like a potential buffer overflow. Use charsmax to ensure the proper size is passed and to avoid hardcoding.

Charsmax inside the get_pcvar_string()?

PHP Code:

public setServerLights() 
{
    new 
lights[];
    
get_pcvar_string(g_lightslightscharsmax(2));
    
set_lights(lights);


Can I write it like this?


All times are GMT -4. The time now is 03:53.

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