Raised This Month: $13 Target: $400
 3% 

Solved set_lights in cvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
chickez
Junior Member
Join Date: Jun 2020
Location: Slovakia
Old 06-28-2020 , 17:36   set_lights in cvar
Reply With Quote #1

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!

Last edited by chickez; 06-29-2020 at 00:07. Reason: solved
chickez is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2020 , 21:49   Re: set_lights in cvar
Reply With Quote #2

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?
__________________
fysiks is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-28-2020 , 22:29   Re: set_lights in cvar
Reply With Quote #3

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);

__________________
Contact! || Discord:
Mr_Boopsy_#2066
supertrio17 is offline
chickez
Junior Member
Join Date: Jun 2020
Location: Slovakia
Old 06-28-2020 , 23:48   Re: set_lights in cvar
Reply With Quote #4

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!
chickez is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-29-2020 , 02:51   Re: set_lights in cvar
Reply With Quote #5

Well because it was a letter it needs to have a string, everything you want to know is here.
__________________
Contact! || Discord:
Mr_Boopsy_#2066
supertrio17 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-29-2020 , 04:01   Re: set_lights in cvar
Reply With Quote #6

Quote:
Originally Posted by chickez View Post
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.
__________________

Last edited by HamletEagle; 06-29-2020 at 04:01.
HamletEagle is online now
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-29-2020 , 23:34   Re: set_lights in cvar
Reply With Quote #7

Quote:
Originally Posted by supertrio17 View Post
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.
__________________
fysiks is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Location: Muslim and proud!
Old 06-30-2020 , 05:33   Re: set_lights in cvar
Reply With Quote #8

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.
__________________
@Jailbreak MOD [Alot of features + API] 100% done !
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-30-2020 , 06:08   Re: set_lights in cvar
Reply With Quote #9

Quote:
Originally Posted by Natsheh View Post
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
__________________
HamletEagle is online now
chickez
Junior Member
Join Date: Jun 2020
Location: Slovakia
Old 06-30-2020 , 06:20   Re: set_lights in cvar
Reply With Quote #10

Ye, it's 1.8.2, the latest.

Quote:
Originally Posted by HamletEagle View Post
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?
chickez is offline
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 13:03.


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