BUD (editing variable for whole offline players)
#1

Hello dear,
I am new to SQL coding, and I managed to code a BUD system that manages my server's database.
Basicly I created a VIP, with expiring date, I already created the timer that detects if the day is over, I would like to know how can I edit all offline players pExpire variable on the BUD sql datbase (only for people who has pPremium > 0).
I hope you can help me on this.
Reply
#2

Is this script related or database.

1) Script: wrong section
2) Hows your database (tables) setup?
Reply
#3

Simply:
pawn Код:
UPDATE `players` SET `VIPExpire`='%s' WHERE `Premium` > 0
Reply
#4

About the pExpire, how can I load the each players pExpire? and set it pExpire - 1? they are offline. and I apologize about the wrong thread location, I haven't paid attentiont o it.
Reply
#5

For all players, or only the players with a certain statistic / variable set? And how often are you trying to perform this operation?
Reply
#6

all online/offline players. one time each day, I am using a clock system, once it reachs midnight all the pExpire gets - 1
Reply
#7

pawn Код:
// somewhere
new query[100];
format(query, sizeof(query), "SELECT * FROM `players` WHERE `Premium` > 0 AND `Online` = 0");
mysql_tquery(MySQL, query,  "OnPremiumDepleteResponse", "");
then...

pawn Код:
public OnPremiumDepleteResponse()
{
    new numrows = cache_get_row_count();
    if(numrows)
    {
            new tmpstring[5], intval, userid;
       
        new rows, field, idx;
        cache_get_data(rows, field);
       
        while(idx >= rows)
        {
            cache_get_field_content(idx, "UserID", tmpstring, sizeof(tmpstring)), userid = strval(tmpstring));
           
                cache_get_field_content(idx, "VIPExpire", tmpstring, sizeof(tmpstring));
                intval = strval(tmpstring);
           
                intval--;
           
                new query[125];
            format(query, sizeof(query), "UPDATE `players` SET `Expire` = '%d' WHERE `UserID` = '%d'", intval, userid);
                mysql_tquery(MySQL, query,  "", "");
           
            idx++;
        }
    }
    return 1;
}
Untested however it should work fine.
Reply
#8

I am using BUD SQL system not MySQL...
this one: https://sampforum.blast.hk/showthread.php?tid=187720
Reply
#9

First go to include script and find these lines :
Код:
private
	 bool:g_bIsInitialized = false,
	      g_szDatabaseName[BUD::MAX_DATABASE_NAME] = "bud.db",
	      g_iColumnCount,
	      g_szColumnName[BUD::MAX_COLUMNS][BUD::MAX_COLUMN_NAME],
	   DB:g_dbKeptAlive = INVALID_DB,
	      g_iKeepAlive = 2000,
	      g_iKeepAliveTimer = -1,
	 bool:g_bAsynchronous = true,
	      g_iIntEntryDefault = 0,
	Float:g_fFloatEntryDefault = 0.0,
	      g_iDatabaseOpenTimeOut = 3000,
	 bool:g_bCheckForUpdates = true,
	      g_szBuffer[BUD::BUFFER_SIZE]
;
Then remove DB:g_dbKeptAlive = INVALID_DB, line from above script and add the following line after the ";"
Код:
global DB:g_dbKeptAlive = INVALID_DB;
Now when you have done this run the query like this :
Код:
db_query(g_dbKeptAlive, "UPDATE `players` SET `VIPExpire`= -1");
This code will set all players expire to -1 both online and offline players. But for changing the variable for online players in script you have to loop through all online player's enum and set it to -1.
Reply
#10

Somehow it doesnt work, what I want exacly is if I have 30 days on VIP, when a day is finished, it should be 29 do you understand how it works? so basicly pExpire var is how many days a user has left, when it reachs 0 it resets his premium.
The only problem now is the part where I should set everyone's on the DB to pExpire - 1 day, that code somehow did not work, I hope you can help me on this..
Reply
#11

Do what I said in my earlier post, just change the query like this :
Код:
db_query(g_dbKeptAlive, "UPDATE `players` SET `pExpire`= pExpire -1");
I use this type of query to increase player's lines and words in my chat recording system and it works like a charm.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)