Raised This Month: $ Target: $400
 0% 

Permanent user variables handler


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 07-15-2009 , 02:26   Permanent user variables handler
Reply With Quote #1

I had the need of having a main plugin to provide a way of handling variables per client permanently so I can use one database to control every variable of my plugins. Something like when you do set_user_info(id,"x",3) but stored in a db, and unique. Its a really useful concept for me, and Arkshine also had the idea. This should be made for every kind of var (int,float,string). I made it only for int (for enums more specifically). Please tell me what you think about the implementation.

It provides a native:
PHP Code:
native Array:registerVar(varLabel[],Array:varValuesLabels
That can be used as follow:
PHP Code:
#include <amxmodx>

#define PLUGIN    "New Plugin"
#define AUTHOR    "Unknown"
#define VERSION    "1.0"

native Array:registerVar(varLabel[],Array:varValuesLabels)

new Array:
option

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    new Array:
optionLabels ArrayCreate(10)

    
ArrayPushString(optionLabels,"Off")
    
ArrayPushString(optionLabels,"On")

    Array:
option registerVar("myOption",optionLabels)
    
    
register_clcmd("changeOption","cmdChangeOption")
}

public 
userSpawn(id)
{
    if(
ArrayGetCell(option,id))
    {
        
// User has the option enabled
    
}
}

public 
cmdChangeOption(id)
{
    
// Changing the option
    
ArraySetCell(option,id,!ArrayGetCell(option,id))

Attached Files
File Type: sma Get Plugin or Get Source (persistentUserVariablesManager.sma - 549 views - 11.3 KB)
__________________
joaquimandrade is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-15-2009 , 17:51   Re: Permanent user variables handler
Reply With Quote #2

So, it's basically custom "user info" entries?
__________________
fysiks is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 07-15-2009 , 21:30   Re: Permanent user variables handler
Reply With Quote #3

No. It's better. Users can't change it. Example of usage:

PHP Code:
new Array:gagged

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    new Array:
options ArrayCreate(10)
    
ArrayPushString(options,"No")
    
ArrayPushString(options,"Yes")
    
    
gagged registerVar("isGagged",options)
    
    
register_clcmd("say","say")
    
    
register_clcmd("gag","gag")
}

public 
say(id)
{
    if(
ArrayGetCell(gagged,id))
    {
        return 
PLUGIN_HANDLED
    
}
}

public 
gag(id)
{
    new 
player = ...
    
    
ArraySetCell(gagged,player,1)

__________________
joaquimandrade is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 07-15-2009 , 22:46   Re: Permanent user variables handler
Reply With Quote #4

Further, I think you can do this in several different plugins:

Code:
gagged = registerVar("isGagged",options)
And the variable "gagged" will have the same value in each plugin if you register the same var called "isGagged" in each plugin. If that's the case, this method is very powerful and useful, because several plugins can make use of the same uniquely perpetual and global variables.

This could be used as a lazy-man's way to save XP for any mod like War3FT or Pokemod, for example. You could also save stats or other things. It's very convenient.

I'm still pondering about it...
__________________
stupok is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 07-15-2009 , 22:48   Re: Permanent user variables handler
Reply With Quote #5

Yes that's one of the points of having a cellarray (to share). Furthermore it can be created a menu in the plugin so the user can change every var on it (if the var allows it). Plus it can also be added an option so that an admin can search for a steamId an set a value on a variable for every player.
__________________
joaquimandrade 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 11:29.


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