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

Solved [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)


Post New Thread Reply   
 
Thread Tools Display Modes
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 04-10-2018 , 08:38   Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
Reply With Quote #11

So now it works.. One last thing, if a use a command to remove/add tokens, so to add or remove from UsedTokens[iClient] will it work as I thing it will?

PHP Code:
public Action AddTokens(int clientint args)
{
    if (
args 2)
    {
        
ReplyToCommand(client"[SM] Usage: sm_addtokens <name or #userid> <tokens to give>");
        return 
Plugin_Handled;    
    }

    
char player[64], tokens[10];
    
GetCmdArg(1playersizeof(player));
    
GetCmdArg(2tokenssizeof(tokens));

    
int target FindTarget(clientplayertruefalse);
    
int whattoadd StringToInt(tokens);

    if (
target == -1
    {
        
ReplyToCommand(client"[SM] Target not found.");
        return 
Plugin_Handled;
    }

    
UsedTokens[target] -= whattoadd;
    return 
Plugin_Continue;
}

public 
Action RemoveTokens(int clientint args)
{
    if (
args 2)
    {
        
ReplyToCommand(client"[SM] Usage: sm_removetokens <name or #userid> <tokens to remove>");
        return 
Plugin_Handled;    
    }

    
char player[64], tokens[10];
    
GetCmdArg(1playersizeof(player));
    
GetCmdArg(2tokenssizeof(tokens));

    
int target FindTarget(clientplayertruefalse);
    
int whattoremove StringToInt(tokens);

    if (
target == -1
    {
        
ReplyToCommand(client"[SM] Target not found.");
        return 
Plugin_Handled;
    }

    
UsedTokens[target] += whattoremove;
    return 
Plugin_Continue;

This for example.
P.S: Nope, not working as intended.
It's sometimes working when adding 2 for example. If i use it again:

PHP Code:
 [ServerYou don't have enough tokens to buy this.
 [Server] You have: -251 | Required: 7 
__________________

Last edited by PinHeaDi; 04-10-2018 at 12:12.
PinHeaDi is offline
Reiko1231
Member
Join Date: Apr 2013
Location: Russia
Old 04-11-2018 , 14:49   Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
Reply With Quote #12

I didn't understand what you want to do.
Reiko1231 is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 04-11-2018 , 15:27   Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
Reply With Quote #13

To add or remove tokens. So edit:

PHP Code:
UsedTokens[client
So that here:
PHP Code:
int tokens = ((MostActive_GetPlayTimeTotalExceptSpec(client) / 3600) / 35) - UsedTokens[client]; 
It could add/remove tokens. If for example I want to add tokens -> UsedTokens[client] -= tokenstoadd, so it will remove used tokens and he'll have more tokens and the opposite for removing tokens.
__________________
PinHeaDi is offline
Reiko1231
Member
Join Date: Apr 2013
Location: Russia
Old 04-13-2018 , 10:40   Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
Reply With Quote #14

Still do not understand your problem.
By the way, do you really want to add tokens to client on remove command:
Code:
UsedTokens[target] += whattoremove;
or to substract tokens on add command?
Code:
UsedTokens[target] -= whattoadd;
Maybe you mixed up signs?
And you could use only one command to add, and substract by passing negative value to your command's argument.
Reiko1231 is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 04-13-2018 , 11:01   Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
Reply With Quote #15

I thing it should be that way, because if you buy for example credits for 2 tokens it will add 2 credits to UsedTokens[client], so that I can remove them for the total credits ((MostActive_GetPlayTimeTotalExceptSpec(clien t) / 3600) / 35) - UsedTokens[client];, or at least that what I used as a solution. The adding/removing itself is buggy, I guess i can add it to one command, but still that bug will persist. And on add it removes tokens from UsedTokens[client], and again i'm doing the calculation, so if it removes 2(example) tokens from UsedTokens[client] when I add, it will be total time - UsedTokens[client](which is with minus 2 now and he'll have more tokens).
__________________

Last edited by PinHeaDi; 04-13-2018 at 11:03.
PinHeaDi is offline
Reiko1231
Member
Join Date: Apr 2013
Location: Russia
Old 04-15-2018 , 08:26   Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
Reply With Quote #16

There might be error in int rounding. If you divide int on int, you will get integer as result. Try to forcing float:
Code:
((MostActive_GetPlayTimeTotalExceptSpec(client) / 3600.0) / 35) - UsedTokens[client]
By writing 3600 as 3600.0 you tell compiler to treat your expression as floats. Then output your result to confirm that this is value you expect. Later you can round it to int using RoundToFloor or RoundToCeil or RoundToNear functions.
Reiko1231 is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 04-15-2018 , 12:12   Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
Reply With Quote #17

float tokens = ((MostActive_GetPlayTimeTotalExceptSpec(clien t) / 3600.0) / 35) - UsedTokens[client];

This is giving me tag mismatch.
__________________
PinHeaDi is offline
Reiko1231
Member
Join Date: Apr 2013
Location: Russia
Old 04-16-2018 , 17:54   Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
Reply With Quote #18

My compiler doesn't give me tag mismatch if UsedTokens is integer array and MostActive_GetPlayTimeTotalExceptSpec() returns integer.
Try to split your expression into smaller ones and find where conversion fails.
Reiko1231 is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 04-24-2018 , 06:00   Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
Reply With Quote #19

The problem was indeed in:
PHP Code:
char UsedTokens[MAXPLAYERS+1]; 
With int it works.
__________________
PinHeaDi 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 05:38.


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