mysql from r33 to r40
#1

PHP Code:
CMD:tempban(playerid, params[])
{
    new 
banner[MAX_PLAYER_NAME], banned[MAX_PLAYER_NAME], bannedid, reason[25], hours, string[400], secs, unbants, ip[16], query[180];
    if(!
IsPlayerAdmin(playerid) && pInfo[playerid][playerAdmin] < 2) return SendClientMessage(playerid, ERROR, "You do not have sufficient permissions to use this command."); //this is just my admin check, yours may be different.
    
if(sscanf(params, "uds[25]", bannedid, hours, reason)) return SendClientMessage(playerid, -1, "Usage: /tempban [player name/ID] [hours] [reason]"); // here, we're checking if the administrator entered the command correctly. "u" is a player name or ID, "d" is the amount of hours as an integer, and "s[25]" is the reason.
    
if(!IsPlayerConnected(bannedid)) return SendClientMessage(playerid, -1, "Invalid player name/ID."); //checking if the player that the admin is trying to ban is connected to the server
    
if(pInfo[playerid][playerAdmin] < pInfo[bannedid][playerAdmin]) return SendClientMessage(playerid, -1, "You cannot ban someone with a higher level than you!"); //I don't allow admins to ban those with higher levels than their own.
    
if(strlen(reason) < 3 || strlen(reason) > 24) return SendClientMessage(playerid, -1, "Your reason must be between 3 and 24 characters."); //limiting the reason length to 3-24 characters
    
if(hours < 12 || hours > 720) return SendClientMessage(playerid, -1, "Ban hours are between 12 and 720 hours");
    
GetPlayerName(playerid, banner, sizeof(banner));
    
GetPlayerName(bannedid, banned, sizeof(banned));
    
GetPlayerIp(bannedid, ip, sizeof(ip));
     
secs = hours*3600
    unbants 
= gettime()+ secs;
    
format(query, sizeof(query), "INSERT INTO `bans` (ban_id, player, ip, admin, reason, ban_time, unban_time) VALUES ('0', '%s', '%s', '%s', '%s', %d, %d)",
    
banned, ip, banner, reason, gettime(), unbants);
    
mysql_query(query);
    
format(string, sizeof(string), "You've been temporarily banned.\n\n{FFFFFF}Staff member: %s\nReason: %s", banner, reason);
    
ShowPlayerDialog(bannedid, 678, DIALOG_STYLE_MSGBOX, "Banned!", string, "Close", "");
    
format(string, sizeof(string), "%s(%d) has banned %s(%d) for %d hours for: %s", banner, playerid, banned, bannedid, hours, reason);
    
SendClientMessageToAll(-1, string);
    
SetTimerEx("KickEx", 500, false, playerid, "i");
    return 
1;
}
forward KickEx(playerid);
public 
KickEx(playerid)
{
    
Kick(playerid);
    return 
1;
}
forward OnBanCheck(playerid);
public 
OnBanCheck(playerid)
{
    new 
banquery[180], ip[16];
    
GetPlayerIp(playerid, ip, 16);
    
format(banquery, sizeof(banquery), "SELECT unban_time FROM `bans` WHERE ip = '%s'", ip);
    
mysql_query(banquery);
    
mysql_store_result();
    if(
mysql_num_rows() != 0) 
    {
        new 
unbantimestamp = mysql_fetch_int(); 
        if(
unbantimestamp > gettime())
        {
            
SendClientMessage(playerid, -1, "You're banned from this server.");
            
SetTimerEx("KickEx", 500, false, playerid, "i");
        }
    }
    return 
1;
} 
i have this code and i wanna to make it use r40mysql insteand of r33 actually i tried but i dont know how to transfer them
so if someone can help me
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=616103
Reply
#3

You need a handle, if you already have one, make sure you use it, also change to threaded queries
PHP Code:
// MySQL connection handle
new MySQL: YOURHANDLENAME;//Your Connection Handle, can be whatever you want it to be, if you have this already, disregard this.
CMD:tempban(playerid, params[])
{
    new 
banner[MAX_PLAYER_NAME], banned[MAX_PLAYER_NAME], bannedid, reason[25], hours, string[400], secs, unbants, ip[16], query[180];
    if(!
IsPlayerAdmin(playerid) && pInfo[playerid][playerAdmin] < 2) return SendClientMessage(playerid, ERROR, "You do not have sufficient permissions to use this command."); //this is just my admin check, yours may be different.
    
if(sscanf(params, "uds[25]", bannedid, hours, reason)) return SendClientMessage(playerid, -1, "Usage: /tempban [player name/ID] [hours] [reason]"); // here, we're checking if the administrator entered the command correctly. "u" is a player name or ID, "d" is the amount of hours as an integer, and "s[25]" is the reason.
    
if(!IsPlayerConnected(bannedid)) return SendClientMessage(playerid, -1, "Invalid player name/ID."); //checking if the player that the admin is trying to ban is connected to the server
    
if(pInfo[playerid][playerAdmin] < pInfo[bannedid][playerAdmin]) return SendClientMessage(playerid, -1, "You cannot ban someone with a higher level than you!"); //I don't allow admins to ban those with higher levels than their own.
    
if(strlen(reason) < 3 || strlen(reason) > 24) return SendClientMessage(playerid, -1, "Your reason must be between 3 and 24 characters."); //limiting the reason length to 3-24 characters
    
if(hours < 12 || hours > 720) return SendClientMessage(playerid, -1, "Ban hours are between 12 and 720 hours");
    
GetPlayerName(playerid, banner, sizeof(banner));
    
GetPlayerName(bannedid, banned, sizeof(banned));
    
GetPlayerIp(bannedid, ip, sizeof(ip));
    
secs = hours*3600;
    
unbants = gettime()+ secs;
    
mysql_format(YOURHANDLENAME, query, sizeof(query), "INSERT INTO bans (ban_id, player, ip, admin, reason, ban_time, unban_time) VALUES('0', '%s', '%s', '%s', '%s', %d, %d)", banned, ip, banner, reason, gettime(), unbants);
    
mysql_tquery(YOURHANDLENAME, query);
    
format(string, sizeof(string), "You've been temporarily banned.\n\n{FFFFFF}Staff member: %s\nReason: %s", banner, reason);
    
ShowPlayerDialog(bannedid, 678, DIALOG_STYLE_MSGBOX, "Banned!", string, "Close", "");
    
format(string, sizeof(string), "%s(%d) has banned %s(%d) for %d hours for: %s", banner, playerid, banned, bannedid, hours, reason);
    
SendClientMessageToAll(-1, string);
    
SetTimerEx("KickEx", 500, false, playerid, "i");
    return 
1;
}
forward KickEx(playerid);
public 
KickEx(playerid)
{
    
Kick(playerid);
    return 
1;
}
forward OnBanCheck(playerid);
public 
OnBanCheck(playerid)
{
    new 
banquery[180], ip[16];
    
GetPlayerIp(playerid, ip, 16);
    new 
rows;
    
mysql_format(YOURHANDLENAME, banquery, sizeof(banquery), "SELECT unban_time FROM `bans` WHERE `ip` = '%s'", ip);
    
mysql_tquery(YOURHANDLENAME, banquery);
    if(
cache_get_row_count(rows))
    {
        new 
unbantimestamp = mysql_fetch_int();
        if(
unbantimestamp > gettime())
        {
            
SendClientMessage(playerid, -1, "You're banned from this server.");
            
SetTimerEx("KickEx", 500, false, playerid, "i");
            return 
1;
        }
    }
    return 
1;
} 
Reply
#4

Quote:
Originally Posted by Kwarde
View Post
Thanks for the help +rep
Reply
#5

PHP Code:
CMD:tempban(playerid, params[])
{
    new 
banner[MAX_PLAYER_NAME], banned[MAX_PLAYER_NAME], bannedid, reason[25], hours, string[400], secs, unbants, ip[16], query[180];
    if(!
pInfo[playerid][playerAdmin]) return SendClientMessage(playerid, ERROR, "You do not have sufficient permissions to use this command.");
    if(
sscanf(params, "uds[25]", bannedid, hours, reason)) return SendClientMessage(playerid, -1, "Usage: /tempban [player name/ID] [hours] [reason]"); // here, we're checking if the administrator entered the command correctly. "u" is a player name or ID, "d" is the amount of hours as an integer, and "s[25]" is the reason.
    
if(!IsPlayerConnected(bannedid)) return SendClientMessage(playerid, -1, "Invalid player name/ID."); //checking if the player that the admin is trying to ban is connected to the server
    
if(pInfo[playerid][playerAdmin] < pInfo[bannedid][playerAdmin]) return SendClientMessage(playerid, -1, "You cannot ban someone with a higher level than you!"); //I don't allow admins to ban those with higher levels than their own.
    
if(strlen(reason) < 3 || strlen(reason) > 24) return SendClientMessage(playerid, -1, "Your reason must be between 3 and 24 characters."); //limiting the reason length to 3-24 characters
    
if(hours < 12 || hours > 720) return SendClientMessage(playerid, -1, "Ban hours are between 12 and 720 hours");
    
GetPlayerName(playerid, banner, sizeof(banner));
    
GetPlayerName(bannedid, banned, sizeof(banned));
    
GetPlayerIp(bannedid, ip, sizeof(ip));
    
secs = hours*3600
    unbants 
= gettime()+ secs;
    
mysql_format(connectionHandle, query, sizeof(query), "INSERT INTO bans (ban_id, player, ip, admin, reason, ban_time, unban_time) VALUES('0', '%s', '%s', '%s', '%s', %d, %d)", banned, ip, banner, reason, gettime(), unbants);
    
mysql_tquery(connectionHandle, query);
    
format(string, sizeof(string), "You've been temporarily banned.\n\n{FFFFFF}Staff member: %s\nReason: %s", banner, reason);
    
ShowPlayerDialog(bannedid, 678, DIALOG_STYLE_MSGBOX, "Banned!", string, "Close", "");
    
format(string, sizeof(string), "%s(%d) has banned %s(%d) for %d hours for: %s", banner, playerid, banned, bannedid, hours, reason);
    
SendClientMessageToAll(-1, string);
    
SetTimerEx("Kick", 500, false, playerid, "i");
    return 
1;
}
forward OnBanCheck(playerid);
public 
OnBanCheck(playerid)
{
    new 
banquery[180], ip[16];
    
GetPlayerIp(playerid, ip, 16);
    new 
rows;
    
mysql_format(connectionHandle, banquery, sizeof(banquery), "SELECT unban_time FROM `bans` WHERE `ip` = '%s'", ip);
    
mysql_tquery(connectionHandle, banquery);
    if(
cache_get_row_count(rows))
    {
        new 
unbantimestamp = mysql_fetch_int();
        if(
unbantimestamp > gettime())
        {
            
SendClientMessage(playerid, -1, "You're banned from this server.");
            
SetTimerEx("Kick", 500, false, playerid, "i");
            return 
1;
        }
    }
    return 
1;
}
forward KickEx(playerid);
public 
KickEx(playerid)
{
    
Kick(playerid);
    return 
1;
} 
PHP Code:
(3348) : warning 213: tag mismatch
(3358) : error 001: expected token: ";", but found "-identifier-"
(3365) : error 035: argument type mismatch (argument 4)
(
3378) : error 017: undefined symbol "mysql_fetch_int"
(3382) : error 035: argument type mismatch (argument 4) 
PHP Code:
unbants = gettime()+ secs; line 3358
if(!pInfo[playerid][playerAdmin]) return SendClientMessage(playerid, ERROR, "You do not have sufficient permissions to use this command."); line 3348
SetTimerEx
("Kick", 500, false, playerid, "i"); line 3365
new unbantimestamp = mysql_fetch_int(); 3378 line
forward KickEx
(playerid);
public 
KickEx(playerid)
{
    
Kick(playerid);
    return 
1;
} 
line 3382 
Reply
#6

Quote:
Originally Posted by makemoneynotfriends
View Post
PHP Code:
CMD:tempban(playerid, params[])
{
    new 
banner[MAX_PLAYER_NAME], banned[MAX_PLAYER_NAME], bannedid, reason[25], hours, string[400], secs, unbants, ip[16], query[180];
    if(!
pInfo[playerid][playerAdmin]) return SendClientMessage(playerid, ERROR, "You do not have sufficient permissions to use this command.");
    if(
sscanf(params, "uds[25]", bannedid, hours, reason)) return SendClientMessage(playerid, -1, "Usage: /tempban [player name/ID] [hours] [reason]"); // here, we're checking if the administrator entered the command correctly. "u" is a player name or ID, "d" is the amount of hours as an integer, and "s[25]" is the reason.
    
if(!IsPlayerConnected(bannedid)) return SendClientMessage(playerid, -1, "Invalid player name/ID."); //checking if the player that the admin is trying to ban is connected to the server
    
if(pInfo[playerid][playerAdmin] < pInfo[bannedid][playerAdmin]) return SendClientMessage(playerid, -1, "You cannot ban someone with a higher level than you!"); //I don't allow admins to ban those with higher levels than their own.
    
if(strlen(reason) < 3 || strlen(reason) > 24) return SendClientMessage(playerid, -1, "Your reason must be between 3 and 24 characters."); //limiting the reason length to 3-24 characters
    
if(hours < 12 || hours > 720) return SendClientMessage(playerid, -1, "Ban hours are between 12 and 720 hours");
    
GetPlayerName(playerid, banner, sizeof(banner));
    
GetPlayerName(bannedid, banned, sizeof(banned));
    
GetPlayerIp(bannedid, ip, sizeof(ip));
    
secs = hours*3600
    unbants 
= gettime()+ secs;
    
mysql_format(connectionHandle, query, sizeof(query), "INSERT INTO bans (ban_id, player, ip, admin, reason, ban_time, unban_time) VALUES('0', '%s', '%s', '%s', '%s', %d, %d)", banned, ip, banner, reason, gettime(), unbants);
    
mysql_tquery(connectionHandle, query);
    
format(string, sizeof(string), "You've been temporarily banned.\n\n{FFFFFF}Staff member: %s\nReason: %s", banner, reason);
    
ShowPlayerDialog(bannedid, 678, DIALOG_STYLE_MSGBOX, "Banned!", string, "Close", "");
    
format(string, sizeof(string), "%s(%d) has banned %s(%d) for %d hours for: %s", banner, playerid, banned, bannedid, hours, reason);
    
SendClientMessageToAll(-1, string);
    
SetTimerEx("Kick", 500, false, playerid, "i");
    return 
1;
}
forward OnBanCheck(playerid);
public 
OnBanCheck(playerid)
{
    new 
banquery[180], ip[16];
    
GetPlayerIp(playerid, ip, 16);
    new 
rows;
    
mysql_format(connectionHandle, banquery, sizeof(banquery), "SELECT unban_time FROM `bans` WHERE `ip` = '%s'", ip);
    
mysql_tquery(connectionHandle, banquery);
    if(
cache_get_row_count(rows))
    {
        new 
unbantimestamp = mysql_fetch_int();
        if(
unbantimestamp > gettime())
        {
            
SendClientMessage(playerid, -1, "You're banned from this server.");
            
SetTimerEx("Kick", 500, false, playerid, "i");
            return 
1;
        }
    }
    return 
1;
}
forward KickEx(playerid);
public 
KickEx(playerid)
{
    
Kick(playerid);
    return 
1;
} 
PHP Code:
(3348) : warning 213: tag mismatch
(3358) : error 001: expected token: ";", but found "-identifier-"
(3365) : error 035: argument type mismatch (argument 4)
(
3378) : error 017: undefined symbol "mysql_fetch_int"
(3382) : error 035: argument type mismatch (argument 4) 
PHP Code:
unbants = gettime()+ secs; line 3358
if(!pInfo[playerid][playerAdmin]) return SendClientMessage(playerid, ERROR, "You do not have sufficient permissions to use this command."); line 3348
SetTimerEx
("Kick", 500, false, playerid, "i"); line 3365
new unbantimestamp = mysql_fetch_int(); 3378 line
forward KickEx
(playerid);
public 
KickEx(playerid)
{
    
Kick(playerid);
    return 
1;
} 
line 3382 
Youre missing ";" in secs = hours*3600
PHP Code:
CMD:tempban(playerid, params[])
{
    new 
banner[MAX_PLAYER_NAME], banned[MAX_PLAYER_NAME], bannedid, reason[25], hours, string[400], secs, unbants, ip[16], query[180];
    if(!
pInfo[playerid][playerAdmin]) return SendClientMessage(playerid, ERROR, "You do not have sufficient permissions to use this command.");
    if(
sscanf(params, "uds[25]", bannedid, hours, reason)) return SendClientMessage(playerid, -1, "Usage: /tempban [player name/ID] [hours] [reason]"); // here, we're checking if the administrator entered the command correctly. "u" is a player name or ID, "d" is the amount of hours as an integer, and "s[25]" is the reason.
    
if(!IsPlayerConnected(bannedid)) return SendClientMessage(playerid, -1, "Invalid player name/ID."); //checking if the player that the admin is trying to ban is connected to the server
    
if(pInfo[playerid][playerAdmin] < pInfo[bannedid][playerAdmin]) return SendClientMessage(playerid, -1, "You cannot ban someone with a higher level than you!"); //I don't allow admins to ban those with higher levels than their own.
    
if(strlen(reason) < 3 || strlen(reason) > 24) return SendClientMessage(playerid, -1, "Your reason must be between 3 and 24 characters."); //limiting the reason length to 3-24 characters
    
if(hours < 12 || hours > 720) return SendClientMessage(playerid, -1, "Ban hours are between 12 and 720 hours");
    
GetPlayerName(playerid, banner, sizeof(banner));
    
GetPlayerName(bannedid, banned, sizeof(banned));
    
GetPlayerIp(bannedid, ip, sizeof(ip));
    
secs = hours*3600;//You were missing the ; at the end of this line
    
unbants = gettime()+ secs;
    
mysql_format(connectionHandle, query, sizeof(query), "INSERT INTO bans (ban_id, player, ip, admin, reason, ban_time, unban_time) VALUES('0', '%s', '%s', '%s', '%s', %d, %d)", banned, ip, banner, reason, gettime(), unbants);
    
mysql_tquery(connectionHandle, query);
    
format(string, sizeof(string), "You've been temporarily banned.\n\n{FFFFFF}Staff member: %s\nReason: %s", banner, reason);
    
ShowPlayerDialog(bannedid, 678, DIALOG_STYLE_MSGBOX, "Banned!", string, "Close", "");
    
format(string, sizeof(string), "%s(%d) has banned %s(%d) for %d hours for: %s", banner, playerid, banned, bannedid, hours, reason);
    
SendClientMessageToAll(-1, string);
    
SetTimerEx("Kick", 500, false, playerid, "i");
    return 
1;
} 
Reply
#7

still the others errors 1only fixed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)