[Help] Mysql weed script
#1

Hello! Working on a weed-script to my RP server. It would not work it says that I'm at the field even if I'm not near a field.


pawn Код:
stock weedspot(playerid)
{
    new weed[500];
    for(new id; id < MAX_WEEDSPOT; id++)
    {
        format(weed, sizeof(weed), "SELECT * FROM weedplace WHERE id= %d", id);
        mysql_query(weed);
        mysql_store_result();
        if(mysql_num_rows())
        if(mysql_fetch_row_format(weed,"|"))
        {
            sscanf(weed, "p<|>e<fff>", WeedSpot[id]);
            if (IsPlayerInRangeOfPoint(playerid, 2.0, WeedSpot[id][wPos][0],WeedSpot[id][wPos][1],WeedSpot[id][wPos][2])){
                return id;
            }
        }
    }
    return 1;
}
If you look in the debug file so you can see that it has picked up the info as it should.

Код:
[22:11:50] CMySQLHandler::FetchRow() - Return: 3|1527.91, -1266.21, 14.38|1527.91|-1266.21|14.38

[22:11:50] >> mysql_query( Connection handle: 1 )

[22:11:50] CMySQLHandler::Query(SELECT * FROM weedplace WHERE id= 4) - Successfully executed.
Here is the cmd as user using to plant a seed:

pawn Код:
CMD:growweed(playerid, params[])
{
    if (Logged[playerid])
    {
        if (weedspot(playerid)) //check if user is at one of the stored fields
        {
            if (PlayerInfo[playerid][pSeed] != 0)
            {
                SendClientMessage(playerid, 0x1EFF00FF, "You have planted a seed, wait for it to grow!");
                PlayerInfo[playerid][pSeed]--;
                CreateObject(808, 1508.65, -1392.60, 14.24,   0.00, 0.00, 0.00);
               
            }
            else SendClientMessage(playerid, 0xFF0000FF, "You must have a seed to plant, go and buy one at your nearest shop!");
        }
        else SendClientMessage(playerid, 0xFF0000FF,"You are not near a weed field or a weed pot!");
     }
    return 1;
}
And enum:
pawn Код:
enum wSpot
{
    wPos[3]
}
Now I wonder what I'm doing wrong for it not to read properly?
Reply
#2

pawn Код:
Float:wPos[3]
Try that, haven't looked over the whole code but this is the first thing that caught my eye :P
Reply
#3

Quote:
Originally Posted by FuTuяe
Посмотреть сообщение
pawn Код:
Float:wPos[3]
Try that, haven't looked over the whole code but this is the first thing that caught my eye :P
Does not work
Reply
#4

I think the sscanf is wrong, is there a post about how it works?

Database:
Код:
id
place
x
y
z
So i need to get xyz from the database
Reply
#5

Fixed!

pawn Код:
stock weedspot(playerid)
{
    new weed[500], savingstring[25], weedet;
    for(new id; id < MAX_WEEDSPOT; id++) // Makes an loop so all vehicles get loaded.
    {
        format(weed, sizeof(weed), "SELECT * FROM weedplace WHERE id= %d", id);
        mysql_query(weed); // Querys the "Query" Variable.
        mysql_store_result(); // Stores the result from Query
        if(mysql_num_rows()) // Checks if theres anyrow.
        while (mysql_fetch_row_format(weed,"|"))
        {
            mysql_fetch_field_row(savingstring, "id"); weedet = strval(savingstring);
            mysql_fetch_field_row(savingstring, "x"); WeedSpot[weedet][wPosX] = strval(savingstring);
            mysql_fetch_field_row(savingstring, "y"); WeedSpot[weedet][wPosY] = strval(savingstring);
            mysql_fetch_field_row(savingstring, "z"); WeedSpot[weedet][wPosZ] = strval(savingstring);
            if (IsPlayerInRangeOfPoint(playerid, 3.4, WeedSpot[id][wPosX], WeedSpot[id][wPosY], WeedSpot[id][wPosZ])) return 3;
        } mysql_free_result();
    }
    return 1;
}
Know that you can do better looking but i do not get sscanf.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)