SA-MP Forums Archive
Need help with MYSQL not saving gun cords.. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Need help with MYSQL not saving gun cords.. (/showthread.php?tid=183313)



Need help with MYSQL not saving gun cords.. - Snyper1 - 14.10.2010

I'm trying to get a DROPGUN script to save all the objects after a restart through MYSQL. The problem is that the gun object IDs aren't saving and loading where they should. Normally I could /dw and the gun would appear on the floor and still be there after logging in and out. When I restart however, the guns disappear and don't load properly.

pawn Код:
function SavePickupWeapons()
{
    new query[256];

    ConnectToDatabase();

    format(query, sizeof query, "DELETE FROM pickup_weapons");
    mysql_query(query);
    printf("QUERY: %s", query);

    for(new w; w < maxobj; w++)
    {
        if(ObjCoords[w][0] != 0.0)
        {
            format(query, sizeof query, "INSERT INTO pickup_weapons (pickupid, weapid, ammo, x, y, z) VALUES (%d, %d, %d, '%f', '%f', '%f')",
            GunObjects[ObjectID[w][0]][0], ObjectID[w][0], ObjectID[w][1], ObjCoords[w][0],ObjCoords[w][1],ObjCoords[w][2]);
            mysql_query(query);
            printf("%s", query);
        }
    }
    printf("pickup weapons saved");
}

function LoadPickupWeapons()
{
    new resultline[256];
    new player[6][32];
    new query[256];

    ConnectToDatabase();

//    format(query, sizeof query, "SELECT * FROM pickup_weapons");
    printf("QUERY: %s",query);
    mysql_query(query);
    mysql_store_result();

    for(new f; f < maxobj; f++)
    while (mysql_fetch_row(resultline) != 0)
    {
        printf("%s", resultline);
        split(resultline, player, '|');
        ObjectID[f][0] = strval(player[1]);
        ObjectID[f][1] = strval(player[2]);
        ObjCoords[f][0] = floatstr(player[3]);
        ObjCoords[f][1] = floatstr(player[4]);
        ObjCoords[f][2] = floatstr(player[5]);
        object[f] = CreateObject(strval(player[0]),ObjCoords[f][0],ObjCoords[f][1],ObjCoords[f][2]-1,93.7,120.0,120.0);
        f++;
    }

    printf("pickup weapons loaded.");
    return 1;
}
Can someone help me please? These are the two functions that are supposed to be working.


Re: Need help with MYSQL not saving gun cords.. - Austin - 15.10.2010

Why is it an object and not a pickup?


Re: Need help with MYSQL not saving gun cords.. - Cameltoe - 15.10.2010

I'm to tired to look at the code, but do some prints in there to check if the functions gets called at all.


Re: Need help with MYSQL not saving gun cords.. - [HiC]TheKiller - 15.10.2010

Use mysql_debug(1); at the top of your script then go to the server directory and paste what it says in the mysql log file.


Re: Need help with MYSQL not saving gun cords.. - Ben7544 - 13.04.2011

Actually, I'm trying to make that also, but it won't work, someone would help us please?


Re: Need help with MYSQL not saving gun cords.. - Voldemort - 13.04.2011

Firstly dont abuse MySQL, I mean its not kid toy...

in way how you format query you can easly brake down your DB, because I bet you everywhere use this style of format, try to use this:
pawn Код:
format(query, sizeof query, "INSERT INTO `pickup_weapons` (`pickupid`, `weapid`, `ammo`, `x`, `y`, `z`) VALUES ('%d', '%d', '%d', '%0.3f', '%0.3f', '%0.3f')",
Also I hope you use mysql_real_escape_string(); everywhere where you save strings, also you make a loop where you insert into DB, so what if someon decides to spam your drop cmd, it will hangup your DB