MySQL Problem
#1

I created ban check but i doesn't works.. it saves perfectly .. but the problem is it bans the Admin rather than the PLAYER!

pawn Код:
stock MySQL_BanCheck(playerid)
{
  new IP[16], admin[MAX_PLAYER_NAME], adminn, player[MAX_PLAYER_NAME], string1[100];
  GetPlayerName(playerid, player, sizeof(player));
  GetPlayerName(adminn, admin, sizeof(admin));
  GetPlayerIp(playerid, IP, 16);
  new query[200];
  format(query, sizeof(query),"SELECT * FROM bandata WHERE (player = '%s' OR IP = '%s') AND banned=1 LIMIT 1", PlayerName(playerid), IP);
  mysql_query(query);
  mysql_store_result();
  new rows = mysql_num_rows();
  if(rows == 1)
  {
     while(mysql_fetch_row(query))
     {
       mysql_fetch_field_row(admin, "admin");
       mysql_fetch_field_row(player, "player");
       mysql_fetch_field_row(string1, "reason");
     }
  new string[50], str[50], str1[100];
  format(string, sizeof(string),"Admin: %s", admin);
  format(str, sizeof(str),"Player: %s", player);
  format(str1, sizeof(str1),"Reason: %s", string1);
  SendClientMessage(playerid, RED,"You are banned from this server!");
  SendClientMessage(playerid, RED,"___________________");
  SendClientMessage(playerid, RED, str);
  SendClientMessage(playerid, RED, string);
  SendClientMessage(playerid, RED, str1);
  SendClientMessage(playerid, RED,"___________________");
  SendClientMessage(playerid, RED, "If you think you this is a mistake please visit our website");
  SendClientMessage(playerid, RED, "www.ventrum-gaming.com/forum/forum.php");
  Kick(playerid);
  }
  mysql_free_result();
  return 1;
}
and ban CMD:

pawn Код:
CMD:ban(playerid, params[])
{
  if(PlayerInfo[playerid][pAdmin] >= 2 || IsPlayerAdmin(playerid))
  {
    new targetid, reason[100];
    if(sscanf(params,"ds[100]", targetid, reason)) return SendClientMessage(playerid, RED,"[USAGE]: /ban [playerid][reason]");
    if(!IsPlayerConnected(playerid) && targetid != INVALID_PLAYER_ID)
    {
      SendClientMessage(playerid, RED,"[ERROR]: Player is not connected!");
    }
    if(PlayerInfo[targetid][pAdmin] > PlayerInfo[playerid][pAdmin])
    {
      SendClientMessage(playerid, RED,"You have been kicked for trying to ban your senior!");
      Kick(playerid);
    }
    else
    {
      new bquery[200], IP[16];
      GetPlayerIp(playerid, IP, 16);
      format(bquery, sizeof(bquery),"INSERT INTO bandata(admin, player, reason, IP, banned) VALUES('%s', '%s', '%s','%s', 1)", PlayerName(playerid),PlayerName(targetid), reason, IP);
      mysql_query(bquery);
      CMDMessage(playerid,"BAN");
      new string[256];
      format(string, sizeof(string),"%s has been banned by Admin %s [Reason: %s]", PlayerName(targetid), PlayerName(playerid), reason);
      SendClientMessageToAll(RED, string);
      mysql_free_result();
      Kick(targetid);
    }
  } else return SendClientMessage(playerid, RED,"[ERROR]: You need to be RCON admin or level 2 admin to use this command!");
  return 1;
}
Reply
#2

in your command you do: GetPlayerIp(playerid, IP, 16);

use targetid not playerid, playerid = admin, targetid=player to be banned


remove mysql_free_result(); from the command, you didnt store a result so no need to free it
Reply
#3

You are not obliged to "mysql_free_result();" when inserted.
You must put "mysql_free_result();" when you collect information

Sorry for my english
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)