MYSQL problems
#1

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 
0sizeof(factionInfo); i++)
            {
                if(
IsPlayerInRangeOfPoint(id,3factionInfo[i][facX], factionInfo[i][facY],factionInfo[i][facZ]))
                {
                    new 
DB_Query[1000];
                     
mysql_format(DatabaseDB_Querysizeof(DB_Query), "SELECT * FROM `factions` WHERE `fID` = '%d'"i);
                    
mysql_tquery(DatabaseDB_Query);
                    new 
string[128],ownerstring[128];
                    
format(stringsizeof(string),"%s",factionInfo[i][facName]);
                    
PlayerTextDrawSetString(playeridSTRINGNAME[playerid], string);
                    
PlayerTextDrawShow(playerid,STRINGNAME[playerid]);
                    
format(ownerstringsizeof(ownerstring),"%s",factionInfo[i][fOwner]);
                    
PlayerTextDrawSetString(playeridSTRINGOWNER[playerid], ownerstring);
                    
PlayerTextDrawShow(playerid,STRINGOWNER[playerid]);
                    
TextDrawShowForPlayer(playeridEMPTYINFOBOX);
                    
TextDrawShowForPlayer(playeridPROPNAME);
                    
TextDrawShowForPlayer(playeridPROPADD);
                    
TextDrawShowForPlayer(playeridPROPOWNER);
                    
TextDrawShowForPlayer(playeridPROPINFO);
                    
TextDrawShowForPlayer(playeridTEXTBOT);
                    
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 
0sizeof(factionInfo); i++)
            {
                
mysql_format(DatabaseDB_Querysizeof(DB_Query), "SELECT * FROM `factions` WHERE `fID` = '%d'"playerInfo[playerid][playerFact]);
                
mysql_tquery(DatabaseDB_Query);
                
//GivePlayerMoney(playerid,factionInfo[fID][fWorth]);
                
format(stringsizeof(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(playeridCOLOR_GRAYTEXTstring);
            }
        }
    }
    else
    {
        
format(stringsizeof(string), "{PROP OFFICE}: {FFFFFF} You do not own the faction that you are a member of!");
        
SendClientMessage(playeridCOLOR_GRAYTEXTstring);
    }
    return 
1;

PHP код:
[20:55:09] [connectionincoming connection127.0.0.1:50568 id0
[20:55:10] [joinJason_McCabe has joined the server (0:127.0.0.1)
[
20:55:12SELECT FROM `accountsWHERE `playerName` = 'Jason_McCabe' LIMIT 1
[20:55:12player loaded.
[
20:55:15You just sold faction id (Yellow-Taxis)
[
20:55:15You just sold faction id (Yellow-Taxis)
[
20:55:15You just sold faction id (Yellow-Taxis)
[
20:55:15You just sold faction id (Yellow-Taxis)
[
20:55:15You just sold faction id (Yellow-Taxis)
[
20:55:15You just sold faction id (Yellow-Taxis)
[
20:55:15You just sold faction id (Yellow-Taxis)
and 
so on 
Reply
#2

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)