[HELP] Converting CMD from Dini to MYSQL r33 (BlueG)
#1

hellow, iam a newbie scripter and i in the learning process mysql
ok first, iam creating a house system,
with db (samp) and colom (house)

but, i so confused (I did not find logic) to convert my command from dini to mysql
anony can help me?


this script
pawn Код:
CMD:createhouse(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] > 0)
    {
        new string[512];
        new NewHouse = HouseSpawn+1;
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, a);
        if(NewHouse >= MAX_HOUSE)
        {
            SCME(playerid, COLOR_WHITE, "Too many HOUSE are currently spawned!");
        }
        cache_get_data(rows, fields, mysql);
        if(rows)
        {
            HouseSpawn++;
            format( string, sizeof( string ), "House (ID: %d) already exist!", NewHouse);
            SCME( playerid, COLOR_GREY, string);
            SCME( playerid, COLOR_YELLOW, "Please try again by typing /createhouse" );
        }
        else
        {
            format(HouseInfo[NewHouse][hOwner], 69, "NoOwner");
            dini_Create(string);
            dini_IntSet(string, "Owned", HouseInfo[NewHouse][hOwned] = 0);
            dini_Set(string, "Owner", HouseInfo[NewHouse][hOwner]);
            dini_IntSet(string, "Lock", HouseInfo[NewHouse][hLock] = 1);
            dini_IntSet(string, "Price", HouseInfo[NewHouse][hPrice] = -1);
            dini_FloatSet(string, "Ext", HouseInfo[NewHouse][hIntEX] = 0);
            dini_FloatSet(string, "ExteriorX", HouseInfo[NewHouse][hExtX] = x);
            dini_FloatSet(string, "ExteriorY", HouseInfo[NewHouse][hExtY] = y);
            dini_FloatSet(string, "ExteriorZ", HouseInfo[NewHouse][hExtZ] = z);
            dini_FloatSet(string, "ExteriorA", HouseInfo[NewHouse][hExtA] = a);
            dini_IntSet(string, "VirtualWorld", HouseInfo[NewHouse][hIntVW] = 0);
            dini_FloatSet(string, "Int", HouseInfo[NewHouse][hIntIN] = 0);
            dini_FloatSet(string, "InteriorX", HouseInfo[NewHouse][hIntX] = 0);
            dini_FloatSet(string, "InteriorY", HouseInfo[NewHouse][hIntY] = 0);
            dini_FloatSet(string, "InteriorZ", HouseInfo[NewHouse][hIntZ] = 0);
            dini_FloatSet(string, "InteriorA", HouseInfo[NewHouse][hIntA] = 0);
            new location[MAX_ZONE_NAME];
            Get2DZone(location, MAX_ZONE_NAME, HouseInfo[NewHouse][hExtX], HouseInfo[NewHouse][hExtY], HouseInfo[NewHouse][hExtZ]);
            format(string, sizeof(string), "{00F0F0}[House #%d]\n{FFFFFF}Selling!\n{0080FF}Location: {FFFFFF}%s\n{0080FF}Price: {FFFFFF}%d\n/buyhouse to buy this house", NewHouse, location, HouseInfo[NewHouse][hPrice]);
            HouseInfo[NewHouse][hText] = CreateDynamik3DTextLabel(string, COLOR_YELLOW, HouseInfo[NewHouse][hExtX], HouseInfo[NewHouse][hExtY], HouseInfo[NewHouse][hExtZ], 10.0, 0);
            HouseInfo[NewHouse][hCP] = CreateDynamicCP(HouseInfo[NewHouse][hExtX],HouseInfo[NewHouse][hExtY],HouseInfo[NewHouse][hExtZ], 2, 0, 0, -1, 5.0);
            HouseInfo[NewHouse][hPickupEX] = CreateDynamicPickup(1273, 23, HouseInfo[NewHouse][hExtX],HouseInfo[NewHouse][hExtY],HouseInfo[NewHouse][hExtZ], 0, 0, -1, 10.0 );
        }
    }
    return 1;
}
Reply
#2

It should be something like this:
pawn Код:
new szQuery[128];
mysql_format(ServerLine, szQuery,"UPDATE `houses` SET `variableone` = '%d', `variabletwo` = '%e'", 2, hello);
mysql_function_query(ServerLine, szQuery, true, "OnQueryFinish", "i", THREAD_NO_RESULT);
mysql_format is not a must, you can still format it using format(..), but the advantage is that you don't have to make mysql_escape_string after then if you have used %e is mysql_format.
so basically mysql_format formats the string safely.
I hope I helped any feedback is appreciated!
Reply
#3

I do not know, the first step should I change it to mysql,

first if I should save house id? or somthng els?
Reply
#4

You should insert the house ID in your database ( if its not inserted - I used that method personally ) then make sure that you have your database set up. After then, you do the saving stage (like the one I provided earlier)

I hope I helped any feedback is appreciated!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)