Raised This Month: $ Target: $400
 0% 

Trie for every player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 05-06-2011 , 13:47   Trie for every player
Reply With Quote #1

Hey, I would like to create a bool, that will be saved for every player, arrays should be reseted on new map.

I need to make a bool, like:

new bool:g_MenuUsed[64];

then when player uses a menu it will be set to true, and then set a task that after 300 seconds will set it again to true, but I want to avoid cheating via reconnects so I've to use trie's, yeah? and how can I do it ?

I've like:

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Plugin name"
#define VERSION "1.0"
#define AUTHOR "author"

new bool:g_bMenuUsed[64];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /menu""CmdMenu")
}

public 
CmdMenu(id)
{
    if(!
g_bMenuUsed[id])
    {
        
g_bMenuUsed[id] = true;
        
//ShowMenu(id)
        
set_task(300.0"MenuUsedOff"id)
    }
    
client_print(idprint_chat"you can use menu only every 5 minutes")
}

public 
MenuUsedOff(id)
{
    
g_bMenuUsed[id] = false;

reinert is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-06-2011 , 13:55   Re: Trie for every player
Reply With Quote #2

Search for how to use trie and you can figure it out on your own, this is pretty simple. Use steam id as key.
__________________
Bugsy is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 05-06-2011 , 14:23   Re: Trie for every player
Reply With Quote #3

Ok, Found this: http://forums.alliedmods.net/showthr...highlight=trie

Last edited by reinert; 05-06-2011 at 14:46.
reinert is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-06-2011 , 14:43   Re: Trie for every player
Reply With Quote #4

Code:
new Trie:g_tPlayerAbility public plugin_init() {     g_tPlayerAbility = TrieCreate() } SetUserAbilityLength(id) {     new szSteamID[32]     get_user_authid(id, szSteamID, charsmax(szSteamID))     TrieSetCell(g_tPlayerAbility, szSteamID, get_systime() + 300) } bool:HasUserAbility(id) {     new iExpireTime, szSteamID[32]     get_user_authid(id, szSteamID, charsmax(szSteamID))     if( TrieGetCell(g_tPlayerAbility, szSteamID, iExpireTime) )     {         if( iExpireTime < get_systime() )         {             return false         }         TrieDeleteKey(g_tPlayerAbility, szSteamID)     }     return true }
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-06-2011 at 15:16.
ConnorMcLeod is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 05-06-2011 , 14:56   Re: Trie for every player
Reply With Quote #5

Thanks ConnorMcLeod, Your code is more humanlike and more understandable for me, thanks, but when I change map and enter server then I want to open /menu and It says I've already opened it before, and I've to wait 5minutes.

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Plugin name"
#define VERSION "1.0"
#define AUTHOR "author"

new Trie:g_tPlayerAbility


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /menu""CmdMenu")
    
    
g_tPlayerAbility TrieCreate()
}

public 
CmdMenu(id)
{
    if(
HasUserAbility(id))
    {
        new 
szSteamID[32]
        
get_user_authid(idszSteamIDcharsmax(szSteamID))
        
TrieSetCell(g_tPlayerAbilityszSteamIDget_systime() + 300)
        
//ShowMenu(id)
    
}
    else
    {
    
client_print(idprint_chat"you can use menu only every 5 minutes")
    }
}

bool:HasUserAbility(id)
{
    new 
iExpireTimeszSteamID[32]
    
get_user_authid(idszSteamIDcharsmax(szSteamID))
    if( 
TrieGetCell(g_tPlayerAbilityszSteamIDiExpireTime) )
    {
        if( 
iExpireTime get_systime() )
        {
            return 
false
        
}
        
TrieDeleteKey(g_tPlayerAbilityszSteamID)
    }
    return 
true
}

public 
plugin_end( )
{
    
TrieDestroyg_tPlayerAbility );


Last edited by reinert; 05-06-2011 at 15:34.
reinert is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-06-2011 , 15:13   Re: Trie for every player
Reply With Quote #6

I understand better your needs, code updated.
If you want other abilities, pass a trie into the 2 functions, and create as many tries as abilities
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-06-2011 at 15:17.
ConnorMcLeod is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 05-06-2011 , 15:34   Re: Trie for every player
Reply With Quote #7

If you only changed return true with return false and reverse, then now I can use menu infinite times.
reinert is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-06-2011 , 16:11   Re: Trie for every player
Reply With Quote #8

I don't think so.

1st time you use the menu, the Trie Key is created and delay is set to actual time + 300

When you try again, if the stored time is < actual time, false is returned so you can't use the menu.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 05-06-2011 , 16:21   Re: Trie for every player
Reply With Quote #9

Have you tested it ? because I do and I've this problem :/
reinert is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-06-2011 , 16:26   Re: Trie for every player
Reply With Quote #10

It will only work the first time it is checked.

When you set the ability for the player, it has a set time to work.
When you check if the player still has the ability, if time has run out, then it is returns false.
Otherwise, it deletes the key from the trie so the player no longer has the ability and returns true.
So if you were to check again without resetting the ability on the player, it won't work again.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 04:25.


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