AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Block keeps getting called. (https://forums.alliedmods.net/showthread.php?t=334939)

Napoleon_be 10-28-2021 13:01

Block keeps getting called.
 
I have this code

PHP Code:

public GetFreePoints(id)
{
    new 
szName[32], szAuth[35];
    
get_user_name(idszNamecharsmax(szName));
    
get_user_authid(idszAuthcharsmax(szAuth));

    if(!
nvault_get(g_iVaultHandleszAuthszNamecharsmax(szName)))
    {
        
hnsxp_add_user_xp(idget_pcvar_num(g_pPointsAmount));
        
nvault_set(g_iVaultHandleszAuthszName);
        
CC_SendMessage(id"You succesfully received &x03%i &x04XP&x01."get_pcvar_num(g_pPointsAmount));
    }


No matter what, that check still passes every time. Can someone explain me why, cause i'm really not getting it right now.

Natsheh 10-28-2021 13:29

Re: Block keeps getting called.
 
Use nvault_lookup instead.


or you can do this, you don't have to save the name.

PHP Code:

public GetFreePoints(id)
{
    new 
szAuth[35];
    
get_user_authid(idszAuthcharsmax(szAuth));

    if(
nvault_get(g_iVaultHandleszAuth) != 1)
    {
        new 
szName[32];
        
get_user_name(idszNamecharsmax(szName));
        
hnsxp_add_user_xp(idget_pcvar_num(g_pPointsAmount));
        
nvault_set(g_iVaultHandleszAuth"1");
        
CC_SendMessage(id"You succesfully received &x03%i &x04XP&x01."get_pcvar_num(g_pPointsAmount));
    }



Napoleon_be 10-28-2021 15:49

Re: Block keeps getting called.
 
Thanks for the help, will try it.

Could u explain to me why it wasn't working as how i tried to do it?

My intention was to save the name according to the steam id. So everytime a player joins with the same steam id, but a different name, this check should still be passed.

The basic idea is to give someone points just once per name. Once their name is changed, i want the command to be available again. I don't wanna use booleans for this.

Natsheh 10-28-2021 16:22

Re: Block keeps getting called.
 
Then change the key to save by name instead of steamid if you desire to give points per name.

And about the explanation you can just do debugging and see what'sthe outputs.

Shadows Adi 10-28-2021 17:10

Re: Block keeps getting called.
 
Quote:

Originally Posted by Napoleon_be (Post 2761892)
I have this code

No matter what, that check still passes every time. Can someone explain me why, cause i'm really not getting it right now.

http://www.amxmodx.org/api/nvault/nvault_get

Code:
Return Result as integer if only the first two arguments of the function are used. 1 if only the first three arguments are used. String length if all four parameters are used.

Napoleon_be 10-28-2021 17:17

Re: Block keeps getting called.
 
Quote:

Originally Posted by Shadows Adi (Post 2761909)
http://www.amxmodx.org/api/nvault/nvault_get

Code:
Return Result as integer if only the first two arguments of the function are used. 1 if only the first three arguments are used. String length if all four parameters are used.

However, my first example should return a string, as explained in the wiki.

Code:

nvault_get(vaultHandle, "myKey", myString, charsmax(myString));
Quote:

Originally Posted by Natsheh (Post 2761907)
Then change the key to save by name instead of steamid if you desire to give points per name.

And about the explanation you can just do debugging and see what'sthe outputs.

Yea you're right, i'll just save by name, lmao my brain these days.

Shadows Adi 10-28-2021 17:37

Re: Block keeps getting called.
 
Quote:

Originally Posted by Napoleon_be (Post 2761910)
However, my first example should return a string, as explained in the wiki.

Code:

nvault_get(vaultHandle, "myKey", myString, charsmax(myString));

No, in return you will get the string lenght, string is copied into the parameter passed.

Napoleon_be 10-28-2021 18:07

Re: Block keeps getting called.
 
Quote:

Originally Posted by Shadows Adi (Post 2761911)
No, in return you will get the string lenght, string is copied into the parameter passed.

You're right.

From what i've heard of the tester, this version should work.

PHP Code:

public GetFreePoints(id)
{
    new 
szName[MAX_NAME_LENGTH], szResult[MAX_NAME_LENGTH];
    
get_user_name(idszNamecharsmax(szName));

    
log_amx("DEBUG: Player current name: %s"szName);

    if(
nvault_get(g_iVaultHandleszNameszResultcharsmax(szResult)))
    {
        
log_amx("DEBUG: Player name was already found: %s"szResult);
        return 
PLUGIN_HANDLED;
    }

    
log_amx("DEBUG: Player name not found in nvault: %s, xp granted."szName);

    
nvault_set(g_iVaultHandleszNameszName);

    
hnsxp_add_user_xp(idget_pcvar_num(g_pPointsAmount));

    
CC_SendMessage(id"You succesfully received &x03%i &x04XP&x01."get_pcvar_num(g_pPointsAmount));

    return 
PLUGIN_HANDLED;


If anyone has suggestions on how to do it "better", always welcome.

bigdaddy424 10-29-2021 18:21

Re: Block keeps getting called.
 
If this command can be used more than once, you can use the timestamp advantage nvault offers using nvault_lookup. Whenever you claim your points update its timestamp with nvault_touch.

Napoleon_be 10-29-2021 20:53

Re: Block keeps getting called.
 
Quote:

Originally Posted by bigdaddy424 (Post 2762000)
If this command can be used more than once, you can use the timestamp advantage nvault offers using nvault_lookup. Whenever you claim your points update its timestamp with nvault_touch.

Why would i do that when i only have to compare player name vs vault player name?

It's pretty simple: If name is not found in nvault, give XP. If name is found in nvault, don't give XP, cause he already got it earlier.


All times are GMT -4. The time now is 11:29.

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