SA-MP Forums Archive
Name wont save on database! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Name wont save on database! (/showthread.php?tid=624701)



Name wont save on database! - daghost111 - 21.12.2016

Hello.I have a problem with command /banaccount.It does not save the name of the banned player on the database.It saves all other stuffs like time,ban reason,admin etc...but not the name of the player getting baned.

CODE:
Anything wrong there?

Код:
stock BanAccount(playerid, giveplayerid[24], time, reason[], ip[])
{
	new name[24], namegive[24];
	if(playerid == 501) format(name, sizeof(name), "Squidward (Anti-Cheat)");
	else GetPlayerName(playerid, name, sizeof(name));
	new curtime = gettime();
	new expire;
	if(!time)
	{
		expire = 1577836800;
	}
	else
	{
		new Float:banminutes = time * 24 * 60 * 60;
		new bantime = floatround(banminutes);
		expire = curtime + bantime;
	}
	new q[400];
	format(q, sizeof(q), "INSERT INTO bans (id, name, reason, ban_time, issue_time, expiry_time, admin, ip) VALUES ('', '%s', '%s', %d, %d, %d, '%s', '%s')", namegive, reason, time, curtime, expire, name, ip);
	mysql_query(q, THREAD_INSERT_BAN);
	/*new banid = mysql_insert_id();
	format(q, sizeof(q), "INSERT INTO bans (id, name, reason, ban_time, issue_time, expiry_time, admin, ip) VALUES ('$s', '%s', '%s', %d, %d, %d, '%s', '%s')", banid, giveplayerid, reason, time, curtime, expire, name, ip);
	mysql_query(q, THREAD_INSERT_BAN);*/
	new string[128];
	if(time)
	format(string,sizeof(string), "AdmCmd: %s was offline banned for %d days by %s: %s", giveplayerid, time, GetPlayerNameEx(playerid), reason);
	else
	format(string,sizeof(string), "AdmCmd: %s was offline banned permanently by %s: %s", giveplayerid, name, reason);
	ABroadCast(COLOR_LIGHTRED, string, 2);
	return 1;
}



Re: Name wont save on database! - KNIGHT786 - 21.12.2016

can u show me the mysql log?


Re: Name wont save on database! - itsCody - 21.12.2016

PHP код:
format(qsizeof(q), "INSERT INTO bans (name, reason, ban_time, issue_time, expiry_time, admin, ip) VALUES ('%s', '%s', %d, %d, %d, '%s', '%s')" 
id isn't really needed if you have the A_I checked


Re: Name wont save on database! - CutX - 21.12.2016

it's obvious when you actually look at the code and try to understand what youre doing here.
soooo, im guessing the "name" variable is used to store the name of the admin who banned the player.
and "namegive" variable is supposed to hold the name of the player that is being banned right?

but the only problem here is, you never ever set that variable to something.
it's emty thus the name field

and what's "giveplayerid"? why is it a array, isn't it supposed to hold the id of the player that's being banned? (im guessing)
if so, you can use that id and get the name -> save it to the "namegive" char string


side note: use UPDATE instead of INSERT if you're not creating any new rows


Re: Name wont save on database! - daghost111 - 21.12.2016

Quote:
Originally Posted by CutX
Посмотреть сообщение
it's obvious when you actually look at the code and try to understand what youre doing here.
soooo, im guessing the "name" variable is used to store the name of the admin who banned the player.
and "namegive" variable is supposed to hold the name of the player that is being banned right?

but the only problem here is, you never ever set that variable to something.
it's emty thus the name field

and what's "giveplayerid"? why is it a array, isn't it supposed to hold the id of the player that's being banned? (im guessing)
if so, you can use that id and get the name -> save it to the "namegive" char string


side note: use UPDATE instead of INSERT if you're not creating any new rows
Just to clear the situation,im not trying to ban a player that is in game.This command is used to ban the player that is offline.And about the name and namegive,they are declared on the command /banaccount.
I will show you the command and then maybe you will understand whats going on...

Код:
CMD:banaccount(playerid, params[])
{
	if(!PlayerInfo[playerid][pAdmin]) return Error(playerid, "You are not authorized to use this command!");
	new playername[24], length, reason[64];
	if(sscanf(params, "s[24]is[64]", playername, length, reason)) return Syntax(playerid, "banaccount", "[playername] [length (days) 0 = perm] [reason]");
	new giveplayerid = ReturnUser(playername);
	new string[128];
	format(STRING, "That player is currently on the server. Use /ban. (ID: %d)", giveplayerid);
	if(IsPlayerConnected(giveplayerid)) return Error(playerid, string);
	if(!doesAccountExist(playername)) return Error(playerid, "Could not find account specified. Check the name and try again.");
	OnPlayerOfflineLogin(playername);
	if(PlayerInfo[MAX_PLAYERS][pAdmin] > PlayerInfo[playerid][pAdmin]) return Error(playerid, "You cannot ban a higher level admin.");
	new ip[16];
	format(ip, sizeof(ip), "%s", PlayerInfo[MAX_PLAYERS][pIP]);
	BanAccount(playerid, playername, length, reason, ip);
	//PlayerInfo[MAX_PLAYERS][pBanned] = 1;
	OnPlayerOfflineSave(playername);
	new year, month,day;
	getdate(year, month, day);
	format(string, sizeof(string), "AdmCmd: %s (IP:%s) was offline banned for %d days by %s, reason: %s (%d-%d-%d)", playername, PlayerInfo[MAX_PLAYERS][pIP], length, GetPlayerNameEx(playerid), reason, month, day, year);
	Log("logs/ban.log", string);
	return 1;
}
So command /bannacount call the functions banaccount!
And all other variables gets saved....just the name of player is not getting saved.


Re: Name wont save on database! - daghost111 - 21.12.2016

Quote:
Originally Posted by itsCody
Посмотреть сообщение
PHP код:
format(qsizeof(q), "INSERT INTO bans (name, reason, ban_time, issue_time, expiry_time, admin, ip) VALUES ('%s', '%s', %d, %d, %d, '%s', '%s')" 
id isn't really needed if you have the A_I checked
I changed to that line,still it does not store the name!


Re: Name wont save on database! - Konstantinos - 21.12.2016

Looking at the function the name of the player to ban is passed in "giveplayerid" parameter so you need to use this as an argument in your INSERT query.

About the IP, unless you read it from the database/player's file you can't be aware of it. Is what OnPlayerOfflineLogin does this? I hope you don't load unnecessary data as well but only the IP in there.

What do you use to save player's data?

pawn Код:
new ip[16];
format(ip, sizeof(ip), "%s", PlayerInfo[MAX_PLAYERS][pIP]);
By the way if the size of PlayerInfo array is set to MAX_PLAYERS will give run time error.
It'd have to be MAX_PLAYERS + 1.


Re: Name wont save on database! - daghost111 - 21.12.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Looking at the function the name of the player to ban is passed in "giveplayerid" parameter so you need to use this as an argument in your INSERT query.

About the IP, unless you read it from the database/player's file you can't be aware of it. Is what OnPlayerOfflineLogin does this? I hope you don't load unnecessary data as well but only the IP in there.

What do you use to save player's data?

pawn Код:
new ip[16];
format(ip, sizeof(ip), "%s", PlayerInfo[MAX_PLAYERS][pIP]);
By the way if the size of PlayerInfo array is set to MAX_PLAYERS will give run time error.
It'd have to be MAX_PLAYERS + 1.
Man you always giving the right answers.Thanks a lot.That "giveplayerid" was the one to have the name on it,its working all good now.
And about IP,i get them from player database.Its working good.
About that max_players idk what do you mean xD.
Rep++


Re: Name wont save on database! - Konstantinos - 21.12.2016

You are welcome.

I highly recommend you though to retrieve the IP directly (or even set a sub-query in INSERT?) than forcing a fake logging in and out.

Since you say it is working, the size of the array is okay.