MySQL help?
#1

I have been trying to make a camp system with mysql but have some issues mabye u guys can help me? also check the pic what the result is when i buy a camp didnt set the pos or anything, and u see the owner just became numbers.



PHP код:
}
stock SaveCamp(campid)
{
    new 
string[2048];
    
printf("Saving Camp ID %d"campid);
    
format(stringsizeof(string), "UPDATE `camps` SET \
        `cOwner`=%d, \
        `cPosX`=%f, \
        `cPosY`=%f, \
        `cPosZ`=%f, \
        `cPosAngle`=%f, \
        `cLock`=%d, \
        `cVirtualWorld`=%d WHERE `id`=%d"
,
        
CampInfo[campid][cOwner],
        
CampInfo[campid][cPosition][0],
        
CampInfo[campid][cPosition][1],
        
CampInfo[campid][cPosition][2],
        
CampInfo[campid][cPosition][3],
        
CampInfo[campid][cLocked],
        
CampInfo[campid][cVW],
        
campid+0
    
); // Array starts from zero, MySQL starts at 0 (this is why we are adding one).
    
mysql_function_query(MainPipelinestringfalse"OnQueryFinish""i"SENDDATA_THREAD);

PHP код:
stock LoadCamp()
{
    
printf("[LoadCamp] Loading data from database...");
    
mysql_function_query(MainPipeline"SELECT * FROM `camps`"true"OnLoadCamps""");

PHP код:
}
forward OnLoadCamps();
public 
OnLoadCamps()
{
    new 
irowsfieldstmp[128];
    
cache_get_data(rowsfieldsMainPipeline);
    while(
rows)
    {
        
cache_get_field_content(i"sqlID"tmpMainPipeline); CampInfo[i][cSQLID] = strval(tmp);
        
cache_get_field_content(i"cOwner"tmpMainPipeline); CampInfo[i][cOwner] = strval(tmp);
        
cache_get_field_content(i"cPosX"tmpMainPipeline); CampInfo[i][cPosition][0] = floatstr(tmp);
        
cache_get_field_content(i"cPosY"tmpMainPipeline); CampInfo[i][cPosition][1] = floatstr(tmp);
        
cache_get_field_content(i"cPosZ"tmpMainPipeline); CampInfo[i][cPosition][2] = floatstr(tmp);
        
cache_get_field_content(i"cPosAngle"tmpMainPipeline); CampInfo[i][cPosition][3] = floatstr(tmp);
        
cache_get_field_content(i"cLock"tmpMainPipeline); CampInfo[i][cLocked] = strval(tmp);
        
cache_get_field_content(i"cVirtualWorld"tmpMainPipeline); CampInfo[i][cVW] = strval(tmp);
        
i++;
    }
    if(
0printf("[LoadCamps] %d Camps rehashed/loaded."i);
    else 
printf("[LoadCamps] Failed to load any Camps.");

PHP код:
    if(dialogid == DIALOG_CAMPBUY)
    {
        if(!
response) return SendClientMessage(playerid,-1,""WHITE"You are exit from Camp Trailer Buy Menu!");
        if(
response)
        {
            if(
GetPlayerMoney(playerid) < 10000) return SendClientMessage(playerid,-1,""RED"[!] "WHITE"You dont have money!");
            {
                new 
szQuery[128];
                new 
poz random(sizeof(RandomKampSpawn));
                 
CampInfo[playerid][cPosition][0] = RandomKampSpawn[poz][0];
                  
CampInfo[playerid][cPosition][1] = RandomKampSpawn[poz][1];
                   
CampInfo[playerid][cPosition][2] = RandomKampSpawn[poz][2];
                
CampInfo[playerid][cPosition][3] = RandomKampSpawn[poz][3];
                
CampInfo[playerid][cLocked] = 1;
                
CampInfo[playerid][cVW] = 0;
                
strmid(CampInfo[playerid][cOwner],  GetPlayerNameEx(playerid), 0strlen(GetPlayerNameEx(playerid)), 999);
                
CampInfo[playerid][cSQLID] = CreateVehicle(607CampInfo[playerid][cPosition][0], CampInfo[playerid][cPosition][1], CampInfo[playerid][cPosition][2], CampInfo[playerid][cPosition][3], 00100);
                
objekt CreateObject(31710,0,0,0,0,0);
                
AttachObjectToVehicle(objektCampInfo[playerid][cSQLID], 0.084999, -2.125115, -1.144999, -3.0149990.000000178.890090);
                
GivePlayerMoney(playerid,-10000);
                
PlayerInfo[playerid][pCampTrailer] = 1;
                
SaveCamp(playerid);
                
g_mysql_SaveAccount(playerid);
                   
format(szQuerysizeof(szQuery), "UPDATE `accounts` SET `CampTrailer`=%d WHERE `id` = %d"PlayerInfo[playerid][pCampTrailer]);
                
mysql_function_query(MainPipelineszQueryfalse"OnQueryFinish""ii"SENDDATA_THREADplayerid);
                
ShowPlayerDialog(playerid,INFOBUY_DIALOG,DIALOG_STYLE_MSGBOX,""GREEN"Camp Trailer",""WHITE"You are sucessfuly buy Camp Trailer, use "GREEN"/camptrailer\n"WHITE"If you want to tow trailer use key "GREEN"'Y'"WHITE", for enter in trailer use key "GREEN"'N'","Okey","");
                
//break;
            
}
        }
    }
    if(
dialogid == DIALOG_CAMP)
    {
        if(!
response) return 1;
        if(
PlayerInfo[playerid][pCampTrailer] == 0) return SendClientMessage(playerid,-1,""RED"[!] "WHITE"Vi ne posjedujete kamp prikolicu!");
        new 
PlayerInfo[playerid][pCampTrailer];
        switch(
listitem)
        {
            case 
0:
            {
                new 
kPrikolica[250];
                new 
z[5]; if(CampInfo[i][cLocked] == 1"Da"; else "Ne";
                
format(kPrikolicasizeof(kPrikolica), ""GREEN"_______________________________\n\n\
                                                       "
WHITE"Locked: "WHITE"%s | "WHITE"Owner: "WHITE"%s\n\n\
                                                       "
GREEN"_______________________________"zCampInfo[i][cOwner]);
                
ShowPlayerDialog(playeridDIALOG_CAMPINFODIALOG_STYLE_MSGBOX""GREEN"Camp Trailer Info"kPrikolica"Okey""");
            }
            case 
1:
            {
                new 
Float:Poz[3];
                
GetVehiclePos(CampInfo[i][cSQLID], Poz[0], Poz[1], Poz[2]);
                if(!
IsPlayerInRangeOfPoint(playerid6.0Poz[0], Poz[1], Poz[2])) return SendClientMessage(playerid,-1,""RED"[!] "WHITE"You need to be near your Camp Trailer!");
                if(
CampInfo[i][cLocked] == 0)
                {
                    
CampInfo[i][cLocked] = 1SaveCamp(i);
                    
GameTextForPlayer(playerid"~w~Camp trailer ~r~locked"50003);
                }
                else
                {
                    
CampInfo[i][cLocked] = 0SaveCamp(i);
                    
GameTextForPlayer(playerid"~w~Camp Trailer ~g~unlocked"50003);
                }
            }
            case 
2:
            {
                new 
Float:Poz[4];
                
GetVehiclePos(CampInfo[i][cSQLID], Poz[0], Poz[1], Poz[2]);
                
GetVehicleZAngle(CampInfo[i][cSQLID], Poz[3]);
                new 
vehicleid GetPlayerVehicleID(playerid);
                if(!
IsPlayerInVehicle(playerid,vehicleid)) return SendClientMessage(playerid,-1,""RED"[!] "WHITE"You need to be in vehicle!");
                if(!
IsPlayerInRangeOfPoint(playerid6.0Poz[0], Poz[1], Poz[2])) return SendClientMessage(playerid,-1,""RED"[!] "WHITE"You need to be near your Camp Trailer!");
                if(
TowedCamp[playerid] == 1)
                {
                    
CampInfo[i][cPosition][0] = Poz[0]; CampInfo[i][cPosition][1] = Poz[1];
                    
CampInfo[i][cPosition][2] = Poz[2]; CampInfo[i][cPosition][3] = Poz[3];
                    
DestroyVehicle(CampInfo[i][cSQLID]);
                    
CampInfo[i][cSQLID] = CreateVehicle(607CampInfo[i][cPosition][0], CampInfo[i][cPosition][1], CampInfo[i][cPosition][2], CampInfo[i][cPosition][3], 00, -1);
                    
SendClientMessage(playerid,-1,""RED"[!] "WHITE"Camp Trailer sucessfuly parked!");
                    
SaveCamp(i); SetVehicleToRespawn(CampInfo[i][cSQLID]);
                }
                else return 
SendClientMessage(playerid,-1,""RED"[!] "WHITE"You need to tow Camp Trailer on vehicle (Key: Y)!");
            }
            case 
3:
            {
                new 
Float:Poz[3]; LocateCamp[playerid] = 1;
                
GetVehiclePos(CampInfo[i][cSQLID], Poz[0], Poz[1], Poz[2]);
                
SetPlayerCheckpoint(playeridPoz[0], Poz[1], Poz[2], 4.0);
                
SendClientMessage(playerid,-1,""GREEN"Your Camp Trailer are marked on radar!");
            }
            case 
4:
            {
                new 
Float:Poz[3];
                
GetVehiclePos(CampInfo[i][cSQLID], Poz[0], Poz[1], Poz[2]);
                if(!
IsPlayerInRangeOfPoint(playerid6.0Poz[0], Poz[1], Poz[2])) return SendClientMessage(playerid,-1,""RED"[!] "WHITE"You need to be near your Camp trailer!");
                
ShowPlayerDialog(playerid,DIALOG_CAMPSELL,DIALOG_STYLE_MSGBOX,""GREEN"Sell Camp Trailer",""WHITE"Do you want sell your Camp Trailer for $5000?","Sell","Cancel");
            }
        }
    }
    if(
dialogid == DIALOG_CAMPSELL)
    {
        if(!
response) return SendClientMessage(playerid,-1,""GREEN"You have been withdrawn from the sale of Camp trailer!");
        if(
response)
        {
            new 
PlayerInfo[playerid][pCampTrailer];
            
DestroyVehicle(CampInfo[i][cSQLID]); DestroyObject(objekt);
            
//IzbrisiKampPrikolicu(PlayerInfo[playerid][pCampTrailer]);
            
PlayerInfo[playerid][pCampTrailer] = 0;
            
GivePlayerMoney(playerid,5000); //SavePlayer(playerid);
            
g_mysql_SaveAccount(playerid);
            
SendClientMessage(playerid,-1,""GREEN"You are succesfuly sold your Camp Trailer!");
            
SaveCamp();
        }
    } 
EDIT
this is from the console
Код:
[19:54:17] [MySQL] Query Error - (ErrorID: 1064) (Handle: 1)
[19:54:17] [MySQL] Check mysql_log.txt to review the query that threw the error.
[19:54:17] Dumping query from 2016/1/30 (19:54:17)

Description: 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 '' at line 1 (index 0). Query:
Reply
#2

Anyone?
Reply
#3

I don't use MySQL but you use the owner variable as a string for the player's name. But then you're saving it as an integar.

Код:
cOwner`=%d
Reply
#4

Quote:
Originally Posted by -CaRRoT
Посмотреть сообщение
I don't use MySQL but you use the owner variable as a string for the player's name. But then you're saving it as an integar.

Код:
cOwner`=%d
What about the camp wont set the pos when i buy one.
Reply
#5

Quote:
Originally Posted by Hellman92
Посмотреть сообщение
What about the camp wont set the pos when i buy one.
What do you mean won't set? As in won't create the vehicle? Won't spawn it ? or won't save on server restart?
Reply
#6

Quote:
Originally Posted by -CaRRoT
Посмотреть сообщение
What do you mean won't set? As in won't create the vehicle? Won't spawn it ? or won't save on server restart?
It won't save this

pawn Код:
cache_get_field_content(i, "cPosX", tmp, MainPipeline); CampInfo[i][cPosition][0] = floatstr(tmp);
        cache_get_field_content(i, "cPosY", tmp, MainPipeline); CampInfo[i][cPosition][1] = floatstr(tmp);
        cache_get_field_content(i, "cPosZ", tmp, MainPipeline); CampInfo[i][cPosition][2] = floatstr(tmp);
        cache_get_field_content(i, "cPosAngle", tmp, MainPipeline); CampInfo[i][cPosition][3] = floatstr(tmp);
Reply
#7

As I said earlier, I don't use MySQL but I was reading some of the plugin functions and I came across this.

https://sampwiki.blast.hk/wiki/MySQL/R33..._content_float

You're saving the trailer X, Y, Z which are floats so shouldn't you retrieve the value as floats instead of strings?
Reply
#8

Quote:
Originally Posted by -CaRRoT
Посмотреть сообщение
As I said earlier, I don't use MySQL but I was reading some of the plugin functions and I came across this.

https://sampwiki.blast.hk/wiki/MySQL/R33..._content_float

You're saving the trailer X, Y, Z which are floats so shouldn't you retrieve the value as floats instead of strings?
They're
Reply
#9

Before you save the values, check what values arrays are holding using print() function here:

Код:
CampInfo[campid][cPosition][0], 
CampInfo[campid][cPosition][1], 
CampInfo[campid][cPosition][2], 
CampInfo[campid][cPosition][3],
Also, have you defined those arrays as FLOAT arrays with the Float: tag?

Quote:
Originally Posted by -CaRRoT
Посмотреть сообщение
As I said earlier, I don't use MySQL but I was reading some of the plugin functions and I came across this.

https://sampwiki.blast.hk/wiki/MySQL/R33..._content_float

You're saving the trailer X, Y, Z which are floats so shouldn't you retrieve the value as floats instead of strings?
The way he's LOADING value is acceptable as well.
Reply
#10

PHP код:
enum kInfo
{
    
cSQLID,
    
cOwnerID,
    
cOwner[MAX_PLAYER_NAME],
    
Float:cPosition[4],
    
cLocked,
    
cVW

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)