CURRENT_TIMESTAMP
#1

Код HTML:
if(cache_get_field_content(0, "UnbanTime", bSt[3]) < CURRENT_TIMESTAMP())
{
    format(query, sizeof(query), "DELETE FROM `bans` WHERE `Name` = '%s'", GetName(playerid)), mysql_tquery(MySQLCon, query, "", "");
    return 1;
}
ERROR:
Код HTML:
error 017: undefined symbol "CURRENT_TIMESTAMP"
Why?
Reply
#2

SA-MP doesn't have a "CURRENT_TIMESTAMP" function, however passing no values by reference to gettime() will return the current unix timestamp.

Example:
pawn Код:
if(cache_get_field_content(0, "UnbanTime", bSt[3]) < gettime())
Reply
#3

"UnbanTime" something like: 2016-02-03 04:29:58
GetTime return: Hour, Minute, Second.
Reply
#4

Quote:
Originally Posted by Bruker
Посмотреть сообщение
"UnbanTime" something like: 2016-02-03 04:29:58
GetTime return: Hour, Minute, Second.
You should use unix timestamps instead of dealing with plain dates. It will also be a lot easier to compare them in the future.

Here is a good example of what you're probably trying to achieve.

https://sampforum.blast.hk/showthread.php?tid=269126
Reply
#5

Quote:
Originally Posted by Cypress
Посмотреть сообщение
You should use unix timestamps instead of dealing with plain dates. It will also be a lot easier to compare them in the future.

Here is a good example of what you're probably trying to achieve.

https://sampforum.blast.hk/showthread.php?tid=269126
I want to ban expire in days.
Can I give an example of how to use unix timestamps, please?
Reply
#6

I would change your system to this:
PHP код:
//Where you fill in the value of "UnBanTime":
UnBanTime gettime()+60*60*24*//2 days 
UnBanTime has to be an integer. And then like this:
PHP код:
if(cache_get_field_content_int(0,"UnbanTime",MySQLCon) < gettime())
{
    
format(query,sizeof query,"DELETE FROM `bans` WHERE `Name`='%s'",GetName(playerid));
    
mysql_tquery(MySQLCon,query,"","");
    return 
1;

Reply
#7

Quote:
Originally Posted by Mencent
Посмотреть сообщение
I would change your system to this:
PHP код:
//Where you fill in the value of "UnBanTime":
UnBanTime gettime()+60*60*24*//2 days 
UnBanTime has to be an integer. And then like this:
PHP код:
if(cache_get_field_content_int(0,"UnbanTime",MySQLCon) < gettime())
{
    
format(query,sizeof query,"DELETE FROM `bans` WHERE `Name`='%s'",GetName(playerid));
    
mysql_tquery(MySQLCon,query,"","");
    return 
1;

First of all UnbanTime isn't a variable in his code, it's a row name in his table.

You can also use pquery, if you're running the latest version of BlueG's MySQL plugin.

pawn Код:
mysql_pquery( MySQLCon, query );
Also, I already gave you an example of how you should do it, just look at jBan, it has everything that you need.

Here is a link to get it http://www.jatochnietdan.com/project/sa-mp/jban

pawn Код:
stock jUnbanName(name[], bool:expired = false)
{
    if(strlen(name) > MAX_PLAYER_NAME) return 0;
   
    mysql_real_escape_string(name, name);
   
    if(expired == false) format(jQuery, MAX_QUERY_LENGTH, "DELETE FROM `"#J_TABLE"` WHERE user_banned = '%s' AND NOW() <= DATE_ADD(ban_timestamp, INTERVAL ban_time MINUTE)", name);
    else format(jQuery, MAX_QUERY_LENGTH, "DELETE FROM `"#J_TABLE"` WHERE user_banned = '%s'", name);
   
    mysql_query(jQuery, QUERY_UNBAN_NAME, 0, jban_connection);
    return 1;
}
It uses a bit older version of MySQL, however you could just easily edit it.

Another method would be when you load the UnBanTime from SQL, assuming you're using unix timestamps,
you could do this.

pawn Код:
new unban_date;

// When loading the information
unban_date = cache_get_field_content_int(0,"UnbanTime" );

if ( unban_date < gettime() )
{
     format(query,sizeof query,"DELETE FROM `bans` WHERE `Name`='%e'",GetName(playerid));
    mysql_pquery( MySQLCon,query );
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)