[mysql] What's wrong with this CMD ?
#1

Hi,

I did a command to transfer money from your bank account to an other player bank account.

Код:
public OnEssaiTransfert(playerid, nom[], somme)
{
	new string[128], query[128];
	if(!cache_get_row_count()) return SendClientMessage(playerid, Rouge, "Ce joueur n'existe pas !");
	mysql_format(mysql, query, sizeof(query),"UPDATE `joueurs` SET `Banque` = 'Banque + %d'  WHERE `Username` = '%e'", somme, nom);
	pInfo[playerid][Banque] -= somme;
	format(string, sizeof(string), "Vous avez maintenant %d $ sur votre compte bancaire.", pInfo[playerid][Banque]);
	SendClientMessage(playerid, Gris,string);
	GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
	format(string, sizeof(string), "%s a transferer %d $ %s.", joueuremetteur, somme, nom);
	ChannelAdmin(Rouge, string);
	return 1;
}


CMD:transferer(playerid, params[]) // ajouter le IsPlayerInRangeOfPoint de la future banque
{
	new nom, somme, query[128], string[128];
	if(sscanf(params, "ud", nom, somme)) return SendClientMessage(playerid, Gris, "Utilisation: /transferer [Nom_Prйnom ou Prйnom_Nom du Joueur] [Somme]"); //Essayer s[24] si ca marche pas
	if(somme >= 2500000 || somme < 0) return SendClientMessage(playerid, Rouge, "La somme doit кtre comprise entre 1 et 2 500 000 $.");
	if(pInfo[playerid][Banque] < somme) return SendClientMessage(playerid, Rouge, "Vous n'avez pas assez sur votre compte bancaire.");
	if(playerid == nom) return SendClientMessage(playerid, Rouge, "Vous ne pouvez pas transferer d'argent а vous mкme.");
	if(IsPlayerConnected(nom))
	{
		pInfo[playerid][Banque] -= somme;
		pInfo[nom][Banque] += somme;
		format(string, sizeof(string), "%s a transferй %d $ sur votre compte bancaire. Vous avez maintenant %d $ sur votre compte.", joueuremetteur, somme, pInfo[nom][Banque]);
		SendClientMessage(nom, Jaune, string);
		format(string, sizeof(string), "[Admin]:%s a transferй %d $ sur le compte de %s", joueuremetteur, somme, nom);
		ChannelAdmin(Rouge, string);
		return 1;
	}
	if(!IsPlayerConnected(nom))
	{
		format(query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Username` = '%s' LIMIT 1", nom);
		mysql_tquery(mysql, query, "OnEssaiTransfert", "isd", playerid, nom, somme);
		return 1;
	}
	return 1;
}
So the CMD is in 2 part. We detect if the receiver of the money is connected, if he is, we don't need sql.
But if he isn't connected, we check if the player exist, if there's isn't account with his name, we return something.
If we found an account, we proceed.
Everytime it return me that the account doesn't exist. And I have this in mysql_log


The CMD doesn't seem to work, I don't know why. Could you please help me ?

PS: I'm not sure if this work:

Код:
if(sscanf(params, "ud", nom, somme)) return SendClientMessage(playerid, Gris, "Utilisation: /transferer [Nom_Prйnom ou Prйnom_Nom du Joueur] [Somme]");
Should it be "s[24]d" ?



Thank you !
Reply
#2

Still trying to resolve this, I tried to modify "nom" to "nom[24] but I have a lot of errors.
Reply
#3

u stands for userid, which will return INVALID_PLAYER_ID if the player is not connected (numerical). Otherwise it'll return the numerical player id.

You can solve it by using the 's' object instead of the 'u', that way it'll be:

Код:
sscanf(params,"s[24]d",nom,somne)
And of coruse the nom must be an array defined variable.

By this way you would also need to change the script, you can no longer do IsPlayerConnected(nom) (since it requieres a numerical input), instead, you would need a loop to check thru all players if their name equals to the typed one.
Reply
#4

Thank you !


But if I do this, as I said I got a lot of errors:


Код:
Beta.pwn(2385) : error 033: array must be indexed (variable "nom")
Beta.pwn(2386) : error 035: argument type mismatch (argument 1)
Beta.pwn(2389) : error 035: argument type mismatch (argument 1)
Beta.pwn(2391) : error 033: array must be indexed (variable "nom")
Beta.pwn(2392) : error 033: array must be indexed (variable "nom")
Beta.pwn(2393) : error 035: argument type mismatch (argument 1)
Beta.pwn(2400) : error 035: argument type mismatch (argument 1)
Line 2385:
Код:
if(playerid == nom) return SendClientMessage(playerid, Rouge, "Vous ne pouvez pas transferer d'argent а vous mкme.");
Line 2386:
Код:
if(IsPlayerConnected(nom))
Line 2389:
Код:
GetPlayerName(nom, joueurdestinataire, sizeof(joueurdestinataire));
Line 2391:
Код:
pInfo[nom][Banque] += somme;
Line 2392:
Код:
format(string, sizeof(string), "%s a transferй %d $ sur votre compte bancaire. Vous avez maintenant %d $ sur votre compte.", joueuremetteur, somme, pInfo[nom][Banque]);
Line 2393:
Код:
SendClientMessage(nom, Jaune, string);
Line 2400:
Код:
if(!IsPlayerConnected(nom))
Should I, every time replace nom by nom[24] ?

Thank you !



EDIT:
Quote:
Originally Posted by CuervO
Посмотреть сообщение
By this way you would also need to change the script, you can no longer do IsPlayerConnected(nom) (since it requieres a numerical input), instead, you would need a loop to check thru all players if their name equals to the typed one.
How could I do this ?
Reply
#5

I edited my post as you were writing this answer:

Quote:

By this way you would also need to change the script, you can no longer do IsPlayerConnected(nom) (since it requieres a numerical input), instead, you would need a loop to check thru all players if their name equals to the typed one.

nom is no longer a numerical input, but a string. You need to loop thru all players to get who has that name. If no one has the typed name, then the player is not connected, otherwise, the player that has it is the player that should be used.
Reply
#6

Is a loop like that gonna work ?

Код:
foreach(new i : Player)
{
	GetPlayerName(playerid, name, sizeof(name))
	if(name == nom)
	{
		// Should I do here here:
		GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
		GetPlayerName(nom, joueurdestinataire, sizeof(joueurdestinataire));
		pInfo[playerid][Banque] -= somme;
		pInfo[nom][Banque] += somme;
		format(string, sizeof(string), "%s a transferй %d $ sur votre compte bancaire. Vous avez maintenant %d $ sur votre compte.", joueuremetteur, somme, pInfo[nom][Banque]);
		SendClientMessage(nom, Jaune, string);
		format(string, sizeof(string), "Vous avez maintenant %d $ sur votre compte bancaire.", pInfo[playerid][Banque]);
		SendClientMessage(playerid, Jaune, string);
		format(string, sizeof(string), "[Admin]:%s a transferй %d $ sur le compte de %s", joueuremetteur, somme, joueurdestinataire);
		ChannelAdmin(Rouge, string);
		return 1;
	}
}
Reply
#7

Strings can't be compared with the '==' equal operator. You need to use strcmp (string compare)

https://sampwiki.blast.hk/wiki/Strcmp

Apart from that, the loop wouldn't work either:

Do something like this:

pawn Код:
new player = INVALID_PLAYER_ID;
foreach(new i : Player)
{
    GetPlayerName(i, name, sizeof(name))
    if(strcmp(name, nom, true) == 0)
    {
        player = i;
        break;
    }
}
if(player != INVALID_PLAYER_ID) //means that a player was found
{
    //code
}
else //no player was found online with that name
{
   //code
}
Use 'player' instead of 'nom', because you've stored the player id to handle in that variable.
Reply
#8

Thank you for this, So I used what you told me:

Код:
CMD:transferer(playerid, params[]) // ajouter le IsPlayerInRangeOfPoint de la future banque
{
	new nom[24], somme, query[128], string[256];
	if(sscanf(params, "s[24]d", nom, somme)) return SendClientMessage(playerid, Gris, "Utilisation: /transferer [Nom_Prйnom ou Prйnom_Nom du Joueur] [Somme]"); 
	if(somme >= 2500000 || somme < 0) return SendClientMessage(playerid, Rouge, "La somme doit кtre comprise entre 1 et 2 500 000 $.");
	if(pInfo[playerid][Banque] < somme) return SendClientMessage(playerid, Rouge, "Vous n'avez pas assez sur votre compte bancaire.");
	if(playerid == nom) return SendClientMessage(playerid, Rouge, "Vous ne pouvez pas transferer d'argent а vous mкme.");
	new joueur = INVALID_PLAYER_ID;
	foreach(new i : Player)
	{
		GetPlayerName(i, joueurdestinataire, sizeof(joueurdestinataire));
		if(strcmp(joueurdestinataire, joueur, true) == 0)
		{
			joueur = i;
			break;
		}
	}
	if(joueur != INVALID_PLAYER_ID) 
	{
		GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
		GetPlayerName(nom, joueurdestinataire, sizeof(joueurdestinataire));
		pInfo[playerid][Banque] -= somme;
		pInfo[nom][Banque] += somme;
		format(string, sizeof(string), "%s a transferй %d $ sur votre compte bancaire. Vous avez maintenant %d $ sur votre compte.", joueuremetteur, somme, pInfo[nom][Banque]);
		SendClientMessage(nom, Jaune, string);
		format(string, sizeof(string), "Vous avez maintenant %d $ sur votre compte bancaire.", pInfo[playerid][Banque]);
		SendClientMessage(playerid, Jaune, string);
		format(string, sizeof(string), "[Admin]:%s a transferй %d $ sur le compte de %s", joueuremetteur, somme, joueurdestinataire);
		ChannelAdmin(Rouge, string);
		return 1;
	}
	else 
	{
	   	format(query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Username` = '%s' LIMIT 1", nom);
		mysql_tquery(mysql, query, "OnEssaiTransfert", "is", playerid, nom, somme);
		return 1;
	}
}
With this, I still have errors:

Код:
Beta.pwn(2385) : error 033: array must be indexed (variable "nom")
Beta.pwn(2390) : error 035: argument type mismatch (argument 1)
Beta.pwn(2399) : error 035: argument type mismatch (argument 1)
Beta.pwn(2401) : error 033: array must be indexed (variable "nom")
Beta.pwn(2402) : error 033: array must be indexed (variable "nom")
Beta.pwn(2403) : error 035: argument type mismatch (argument 1)
Line 2385:
Код:
if(playerid == nom) return SendClientMessage(playerid, Rouge, "Vous ne pouvez pas transferer d'argent а vous mкme.");
// Should I use strcmp or something else ?
Line 2390:
Код:
if(strcmp(joueurdestinataire, joueur, true) == 0)
Line 2399:
Код:
GetPlayerName(nom, joueurdestinataire, sizeof(joueurdestinataire));
// If I do nom[24] It says "Array index out of bounds".
Line 2401:
Код:
pInfo[nom][Banque] += somme;
Line 2402:
Код:
format(string, sizeof(string), "%s a transferй %d $ sur votre compte bancaire. Vous avez maintenant %d $ sur votre compte.", joueuremetteur, somme, pInfo[nom][Banque]);
Line 2403:
Код:
SendClientMessage(nom, Jaune, string);
Ps: In the top of my script I got: "new joueurdestinataire[MAX_PLAYER_NAME];"
Reply
#9

Still the same mistake, nom is an array with a string, you need to input numerical variables in where you get the errors:

You stored the player name in the variable "joueur" as I noticed, change those noms for joueur.

As for the line 2390: use nom instead of joueur, as again, joueur is a numerical value, you're checking strings (what the player typed)
Reply
#10

Thank you guy !

No I have no errors but still have one problem:


This the CMD.

Код:
`public OnEssaiTransfert(playerid, nom[], somme)
{
	new string[128], query[128];
	if(!cache_get_row_count()) return SendClientMessage(playerid, Rouge, "Ce joueur n'existe pas !");
	mysql_format(mysql, query, sizeof(query),"UPDATE `joueurs` SET `Banque` = 'Banque + '%d''  WHERE `Username` = '%e'", somme, nom);
	mysql_tquery(mysql, query, "", "");
	pInfo[playerid][Banque] -= somme;
	format(string, sizeof(string), "Vous avez maintenant %d $ sur votre compte bancaire.", pInfo[playerid][Banque]);
	SendClientMessage(playerid, Gris,string);
	GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
	format(string, sizeof(string), "%s a transferer %d $ %s.", joueuremetteur, somme, nom);
	ChannelAdmin(Rouge, string);
	return 1;
}
Код:
CMD:transferer(playerid, params[]) // ajouter le IsPlayerInRangeOfPoint de la future banque
{
	new nom[24], somme, query[128], string[256], joueur = INVALID_PLAYER_ID;
	if(sscanf(params, "s[24]d", nom, somme)) return SendClientMessage(playerid, Gris, "Utilisation: /transferer [Nom_Prйnom ou Prйnom_Nom du Joueur] [Somme]"); 
	if(somme >= 2500000 || somme < 0) return SendClientMessage(playerid, Rouge, "La somme doit кtre comprise entre 1 et 2 500 000 $.");
	if(pInfo[playerid][Banque] < somme) return SendClientMessage(playerid, Rouge, "Vous n'avez pas assez sur votre compte bancaire.");
	foreach(new i : Player)
	{
		GetPlayerName(i, joueurdestinataire, sizeof(joueurdestinataire));
		if(strcmp(joueurdestinataire, nom, true) == 0)
		{
			joueur = i;
			break;
		}
	}
	if(playerid == joueur) return SendClientMessage(playerid, Rouge, "Vous ne pouvez pas transferer d'argent а vous mкme.");
	if(joueur != INVALID_PLAYER_ID) 
	{
		GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
		GetPlayerName(joueur, joueurdestinataire, sizeof(joueurdestinataire));
		pInfo[playerid][Banque] -= somme;
		pInfo[joueur][Banque] += somme;
		format(string, sizeof(string), "%s a transferй %d $ sur votre compte bancaire. Vous avez maintenant %d $ sur votre compte.", joueuremetteur, somme, pInfo[joueur][Banque]);
		SendClientMessage(joueur, Jaune, string);
		format(string, sizeof(string), "Vous avez maintenant %d $ sur votre compte bancaire.", pInfo[playerid][Banque]);
		SendClientMessage(playerid, Jaune, string);
		format(string, sizeof(string), "[Admin]:%s a transferй %d $ sur le compte de %s", joueuremetteur, somme, joueurdestinataire);
		ChannelAdmin(Rouge, string);
		return 1;
	}
	else 
	{
	   	format(query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Username` = '%s' LIMIT 1", nom);
		mysql_tquery(mysql, query, "OnEssaiTransfert", "isd", playerid, nom, somme);
		return 1;
	}
}
All work fine in the CMD, except when the player is offline, it doesn't give him the money on his bank account. I think there's a problem with my query or something like that. Could you please help me with this ?

Again thank you for your help !



EDIT: Mysql_log:
Код:
2:28] [DEBUG] mysql_format - connection: 1, len: 128, format: "UPDATE `joueurs` SET `Banque` = 'Banque + '%d''  WHERE `Username` = '%e'"
[04:22:28] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `joueurs` SET `Banque` = 'Banque + '10000''  WHERE `Usern", callback: "(null)", format: "(null)"
[04:22:28] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[04:22:28] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[04:22:28] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '10000''  WHERE `Username` = 'Cista_Adel'' at line 1
So I can't do 'Banque+ %d'. Is there a way instead of it ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)