[HELP] MySQL saving house
#1

Hi all, I made a little function for making house but my house doesn't save (MySQL) here is the whole function
pawn Код:
stock CreateDynamicHouse(Float: EnterX, Float: EnterY, Float: EnterZ, Interior, Float: InteriorX, Float: InteriorY, Float: InteriorZ, Price, VirtualWorld, HouseID)
{
    for(new i = 0; i != MAX_PLAYERS; ++i)
    {
        if (IsPlayerConnected(i))
        {
            EnterX = HouseInfo[i][hEnterX];
            EnterY = HouseInfo[i][hEnterY];
            EnterZ = HouseInfo[i][hEnterZ];
            InteriorX = HouseInfo[i][hInteriorX];
            InteriorY = HouseInfo[i][hInteriorY];
            InteriorZ = HouseInfo[i][hInteriorZ];
            Interior = HouseInfo[i][hInterior];
            VirtualWorld = HouseInfo[i][hVirtualWorld];
            Price = HouseInfo[i][hPrice];
            HouseID = HouseInfo[i][hHouseID];
        }
    }
    House += 1;
    House_Price[House] = Price;
    Buy_House[House] = CreatePickup(1239, 2, EnterX, EnterY, EnterZ, -1);
    hstring[126] += 1;
    format(hstring, sizeof(hstring), "For sale!\nPrice: %d\nType /buyhouse to buy house!", Price);
    Label += 1;
    LabelMake[Label] = Create3DTextLabel(hstring, 0x21DD00FF, EnterX, EnterY, EnterZ, 40.0, 0);
    for(new i = 0; i != MAX_PLAYERS; ++i)
    {
        if (IsPlayerConnected(i))
        {
            mysql_real_escape_string(GetName(i), hescpname);
            format(HQuery, sizeof(HQuery), "INSERT INTO `house` (`User`, `EnterX`, `EnterY`, `EnterZ`, `Interior`, `InteriorX`, `InteriorY`, `InteriorZ`, `Price`, `VirtualWorld`, `HouseID`) VALUES ('%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", hescpname, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ], HouseInfo[i][hInteriorX], HouseInfo[i][hInteriorY], HouseInfo[i][hInteriorZ], HouseInfo[i][hVirtualWorld], HouseInfo[i][hPrice], HouseInfo[i][hHouseID]);
            mysql_query(HQuery);
        }
    }
    return 1;
}
Everything works just saving not (It's not finished but.. huh)

Thanks a lot!
Reply
#2

do not use ' for integers...
i mean

use '%s' for strings and %d for integers and numbers (dont use '%d')
Reply
#3

that's not problem, if it' problem I could browse my database and I will just see who is owner else nothing...
Reply
#4

Never had problems with using '%d'. Works perfectly fine.

Yet that script makes absolutely no sense to me. You pass parameters to the function, but they are never used because they're instantly overwritten by other variables in that loop.

Then, after you've applied all the stuff that makes even less sense to me, you insert 0-500 new rows into the database (depending on how many players are online).
Reply
#5

(Enter|Interior)X/Y/Z is float.
Also,open Debug.txt (mysql_debug.txt) and look what it said.
Reply
#6

Vince: what to do?
Farsek: I now I said that's not problem!
I'n debug nothing isn't wrong!
Reply
#7

bump anyone?
Reply
#8

sorry for double post, I've made something
pawn Код:
/*
 * S32House - Create house with just one line (MySQL)!
 * Copyright©System32
 * This file is provided as is (no warranties)
 */

#if defined _S32House_included
  #endinput
#endif
#define _S32House_included
#include <a_samp>
#include <a_mysql>
#include <YSI\y_commands>

#define MAX_HOUSE 150

enum hInfo
{
    hOwner,
    hEnterX,
    hEnterY,
    hEnterZ,
    hInteriorX,
    hInteriorY,
    hInteriorZ,
    hInterior,
    hVirtualWorld,
    hHouseID,
    hPrice
};
new HouseInfo[MAX_HOUSE][hInfo];

//new PlayerHaveHouse[MAX_PLAYERS];
new House = -1, House_Price[MAX_HOUSE] = 0, Buy_House[sizeof(House)], CurrentHouse = -1;
new Label = -1;
new Text3D: LabelMake[sizeof(Label)];
new hstring[128] = -1, stringmake[sizeof(hstring)];
new hescpname[24];
new HQuery[300];
   
stock CreateDynamicHouse(Float: EnterX, Float: EnterY, Float: EnterZ, Interior, Float: InteriorX, Float: InteriorY, Float: InteriorZ, Price, VirtualWorld, HouseID)
{
    CurrentHouse += 1;
    House += 1;
    House_Price[House] = Price;
    Buy_House[House] = CreatePickup(1239, 2, EnterX, EnterY, EnterZ, -1);
    hstring[126] += 1;
    format(hstring, sizeof(hstring), "For sale!\nPrice: %d\nType /buyhouse to buy house!", Price);
    Label += 1;
    LabelMake[Label] = Create3DTextLabel(hstring, 0x21DD00FF, EnterX, EnterY, EnterZ, 40.0, 0);

    for(new i=0; i < 2; i++)
    {
        EnterX = HouseInfo[i][hEnterX];
        EnterY = HouseInfo[i][hEnterY];
        EnterZ = HouseInfo[i][hEnterZ];
        InteriorX = HouseInfo[i][hInteriorX];
        InteriorY = HouseInfo[i][hInteriorY];
        InteriorZ = HouseInfo[i][hInteriorZ];
        Interior = HouseInfo[i][hInterior];
        VirtualWorld = HouseInfo[i][hVirtualWorld];
        Price = HouseInfo[i][hPrice];
        HouseID = HouseInfo[i][hHouseID];
        mysql_real_escape_string(GetName(i), hescpname);
        format(HQuery, sizeof(HQuery), "INSERT INTO `house` (`User`, `EnterX`, `EnterY`, `EnterZ`, `Interior`, `InteriorX`, `InteriorY`, `InteriorZ`, `Price`, `VirtualWorld`, `HouseID`) VALUES ('%s', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%d', '%d', '%d')", hescpname, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ], HouseInfo[i][hInteriorX], HouseInfo[i][hInteriorY], HouseInfo[i][hInteriorZ], HouseInfo[i][hVirtualWorld], HouseInfo[i][hPrice], HouseInfo[i][hHouseID]);
        mysql_query(HQuery);
    }
    return 1;
}
so, when I open up my database, there is a lot of houses, it's not just 2 (i've put 2 in OnGameModeInit) & noone of them doesn't show right coordinates, etc.
Reply
#9

People really sorry for triple post but, I've made everything in script good but database..huh


Reply
#10

pawn Код:
stock CreateDynamicHouse(Float: EnterX, Float: EnterY, Float: EnterZ, Interior, Float: InteriorX, Float: InteriorY, Float: InteriorZ, Price, VirtualWorld, HouseID)
{
    if(HouseID < 0 || HouseID >= sizeof(HouseInfo)) return 0;
   
    HouseInfo[HouseID][hEnterX] = EnterX;
    HouseInfo[HouseID][hEnterY] = EnterY;
    HouseInfo[HouseID][hEnterZ] = EnterZ;
    HouseInfo[HouseID][hInteriorX] = InteriorX;
    HouseInfo[HouseID][hInteriorY] = InteriorY;
    HouseInfo[HouseID][hInteriorZ] = InteriorZ;
    HouseInfo[HouseID][hInterior] = Interior;
    HouseInfo[HouseID][hVirtualWorld] = VirtualWorld;
    HouseInfo[HouseID][hPrice] = Price;

    House += 1;
    House_Price[House] = Price;
    Buy_House[House] = CreatePickup(1239, 2, EnterX, EnterY, EnterZ, -1);
    format(hstring, sizeof(hstring), "For sale!\nPrice: %d\nType /buyhouse to buy house!", Price);
    Label += 1;
    LabelMake[Label] = Create3DTextLabel(hstring, 0x21DD00FF, EnterX, EnterY, EnterZ, 40.0, 0);
   
    mysql_real_escape_string("None", hescpname);
    format(HQuery, sizeof(HQuery), "INSERT INTO `house` (`User`, `EnterX`, `EnterY`, `EnterZ`, `Interior`, `InteriorX`, `InteriorY`, `InteriorZ`, `Price`, `VirtualWorld`, `HouseID`) VALUES ('%s', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%d', '%d', '%d')",
        hescpname, EnterX, EnterY, EnterZ, Interior, InteriorX, InteriorY, InteriorZ, Price, VirtualWorld, HouseID);
    mysql_query(HQuery);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)