AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Trie for every player (https://forums.alliedmods.net/showthread.php?t=156436)

reinert 05-06-2011 13:47

Trie for every player
 
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;



Bugsy 05-06-2011 13:55

Re: Trie for every player
 
Search for how to use trie and you can figure it out on your own, this is pretty simple. Use steam id as key.

reinert 05-06-2011 14:23

Re: Trie for every player
 
Ok, Found this: http://forums.alliedmods.net/showthr...highlight=trie

ConnorMcLeod 05-06-2011 14:43

Re: Trie for every player
 
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 }

reinert 05-06-2011 14:56

Re: Trie for every player
 
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 );



ConnorMcLeod 05-06-2011 15:13

Re: Trie for every player
 
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

reinert 05-06-2011 15:34

Re: Trie for every player
 
If you only changed return true with return false and reverse, then now I can use menu infinite times.

ConnorMcLeod 05-06-2011 16:11

Re: Trie for every player
 
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.

reinert 05-06-2011 16:21

Re: Trie for every player
 
Have you tested it ? because I do and I've this problem :/

Exolent[jNr] 05-06-2011 16:26

Re: Trie for every player
 
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.


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

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