MYSQL problems -
yllo - 16.12.2018
Hi
Im trying to make it so that the players can see the owners of the faction by walking into an info symbol and then a text draw appears with the faction info. However this fails to update even though I change the database to show that no one owns it or another player owns it UNTIL gamemode restart. This is my info range code:
PHP код:
forward PlayerInfoRange(playerid);
public PlayerInfoRange(playerid)
{
if(playerInfo[playerid][LoggedIn])
{
foreach(new id : Player) // Using "foreach" we're going to loop through the online players.
{
for(new i = 0; i < sizeof(factionInfo); i++)
{
if(IsPlayerInRangeOfPoint(id,3, factionInfo[i][facX], factionInfo[i][facY],factionInfo[i][facZ]))
{
new DB_Query[1000];
mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `factions` WHERE `fID` = '%d'", i);
mysql_tquery(Database, DB_Query);
new string[128],ownerstring[128];
format(string, sizeof(string),"%s",factionInfo[i][facName]);
PlayerTextDrawSetString(playerid, STRINGNAME[playerid], string);
PlayerTextDrawShow(playerid,STRINGNAME[playerid]);
format(ownerstring, sizeof(ownerstring),"%s",factionInfo[i][fOwner]);
PlayerTextDrawSetString(playerid, STRINGOWNER[playerid], ownerstring);
PlayerTextDrawShow(playerid,STRINGOWNER[playerid]);
TextDrawShowForPlayer(playerid, EMPTYINFOBOX);
TextDrawShowForPlayer(playerid, PROPNAME);
TextDrawShowForPlayer(playerid, PROPADD);
TextDrawShowForPlayer(playerid, PROPOWNER);
TextDrawShowForPlayer(playerid, PROPINFO);
TextDrawShowForPlayer(playerid, TEXTBOT);
SetTimerEx("PlayerInfoRangeHide",7000,true,"i",playerid);
}
}
}
}
return 1;
}
Secondly, I am trying to make it so that the owners of the factions can sell the faction they own but it does not work properly. It does not select the players faction that they own and loops itself (shown below too)
PHP код:
CMD:sellfaction(playerid,params[])
{
new string[128],accept[32],DB_Query[800];
// if(IsPlayerInRangeOfPoint(id,3, x, y,z)) // PROP OFF??
//if(sscanf(params, "s", accept)) return SendClientMessage(playerid, COLOR_GRAYTEXT, "{PROP OFFICE} :{FFFFFF} /sellproperty [ACCEPT]");
if(playerInfo[playerid][playerFact] >= 1)
{
if(playerInfo[playerid][playerFactR] >= 6)
{
for(new i = 0; i < sizeof(factionInfo); i++)
{
mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `factions` WHERE `fID` = '%d'", playerInfo[playerid][playerFact]);
mysql_tquery(Database, DB_Query);
//GivePlayerMoney(playerid,factionInfo[fID][fWorth]);
format(string, sizeof(string), "{PROP OFFICE}: {FFFFFF} You have sold the company '%s' for a value of '$%d'", factionInfo[i][facName],factionInfo[i][fWorth]);
printf("You just sold faction id : %d (%s)", factionInfo[i][fID],factionInfo[i][facName]);
SendClientMessage(playerid, COLOR_GRAYTEXT, string);
}
}
}
else
{
format(string, sizeof(string), "{PROP OFFICE}: {FFFFFF} You do not own the faction that you are a member of!");
SendClientMessage(playerid, COLOR_GRAYTEXT, string);
}
return 1;
}
PHP код:
[20:55:09] [connection] incoming connection: 127.0.0.1:50568 id: 0
[20:55:10] [join] Jason_McCabe has joined the server (0:127.0.0.1)
[20:55:12] SELECT * FROM `accounts` WHERE `playerName` = 'Jason_McCabe' LIMIT 1
[20:55:12] player loaded.
[20:55:15] You just sold faction id : 0 (Yellow-Taxis)
[20:55:15] You just sold faction id : 0 (Yellow-Taxis)
[20:55:15] You just sold faction id : 0 (Yellow-Taxis)
[20:55:15] You just sold faction id : 0 (Yellow-Taxis)
[20:55:15] You just sold faction id : 0 (Yellow-Taxis)
[20:55:15] You just sold faction id : 0 (Yellow-Taxis)
[20:55:15] You just sold faction id : 0 (Yellow-Taxis)
and so on
Re: MYSQL problems -
Calisthenics - 16.12.2018
The problem in these two is their faulty function syntax. If you want to select data, you specify a callback in mysql_tquery function. By using the cache functions, you retrieve them.
If you store them in global arrays, what is the point of querying the database?
If a player walks into an info symbol, isn't the one who should see the info? Why do you send in every player in range that is in any faction?
When selling a function, you should send an UPDATE query to change the value of the owner and not a SELECT query. The faction loops are unnecessary to both cases.