MYSQL problem
#1

I have never scripted with MYSQL before and we changed the gamemode to one with MYSQL. So I basically wanted to make a /checkhouse and /checkbiz to see what business and house ID is still free to create one.

But the following problems I am getting into:
- Once I do /checkhouse and then /checkbiz I will get Unknown Command and every command in the server will return it after that
- /checkbiz doesn't even works.
- Once I do /checkhouse it will return all the ID's and not a single one.

The code:
pawn Код:
#include <a_sampmysql>

if(strcmp(cmd,"/checkbiz",true) == 0)
    {
        new business[100][64];
        new sql[80];
        new row[512];
        format(sql, sizeof(sql), "SELECT COUNT(*) FROM bizz");
        samp_mysql_query(sql);
        samp_mysql_store_result();
        samp_mysql_fetch_row(row);
        totalbizz = strvalEx(row);
        samp_mysql_free_result();
        for (idx=0; idx<totalbizz; idx++)
        {
            format(sql, sizeof(sql), "SELECT * FROM bizz WHERE id=%d", idx);
            samp_mysql_query(sql);
            samp_mysql_store_result();
            if (samp_mysql_num_rows() > 0)
            {
                samp_mysql_fetch_row(row);
                split(row, business, '|');
                samp_mysql_free_result();
                Business[idx][bBuyPrice] = strvalEx(business[12]);
                new loadedbizz = 0;
                if(Business[idx][bBuyPrice] == 0)
                {
                    if(loadedbizz == 0)
                    {
                        loadedbizz = 1;
                        format(string, sizeof(string), "* Business ID %d is free!", idx);
                        SendClientMessage(playerid, COLOR_YELLOW, string);
                    }
                }
            }
        }
        return true;
    }
    if(strcmp(cmd,"/checkhouse",true) == 0)
    {
        new arrCoords[24][64];
        new sql[80], row[512];
        format(sql, sizeof(sql), "SELECT COUNT(*) FROM property");
        samp_mysql_query(sql);
        samp_mysql_store_result();
        samp_mysql_fetch_row(row);
        totalhouses = strvalEx(row);
        samp_mysql_free_result();
        for (idx=0; idx<totalhouses; idx++)
        {
            format(sql, sizeof(sql), "SELECT * FROM property WHERE id=%d", idx);
            samp_mysql_query(sql);
            samp_mysql_store_result();
            if (samp_mysql_num_rows() > 0)
            {
                samp_mysql_fetch_row(row);
                split(row, arrCoords, '|');
                samp_mysql_free_result();
                Property[idx][hValue] = strvalEx(arrCoords[9]);
                new loadedhouse = 0;
                if(Property[idx][hValue] == 0)
                {
                    if(loadedhouse == 0)
                    {
                        loadedhouse = 1;
                        format(string, sizeof(string), "* House ID %d is free!", idx);
                        SendClientMessage(playerid, COLOR_YELLOW, string);
                    }
                }
            }
        }
        return true;
    }
Does anybody have an idea how to fix it?

Aron
Reply
#2

Bump, I could really use some help, is it possible to fix or should I try to remake it and how?
Reply
#3

Could you use the PAWN-BBcode?
Reply
#4

Well, I think it's because you're using a "for" statement wherein it loops through all the IDs of the houses (/checkhouse). Try using IsPlayerInRangeOfPoint to detect the location of the player and the house near him/her.

Hope I helped.
Reply
#5

Quote:
Originally Posted by Steamator
Посмотреть сообщение
Could you use the PAWN-BBcode?
Updated it in my post.

Quote:
Originally Posted by Alvord
Посмотреть сообщение
Well, I think it's because you're using a "for" statement wherein it loops through all the IDs of the houses (/checkhouse). Try using IsPlayerInRangeOfPoint to detect the location of the player and the house near him/her.

Hope I helped.
Well I want it to check for the first biz in the database with an open spot, the system works like this:
I made 250 empty businesses in the database, ingame you can /createbiz one with the ID. But the problem is that admins will overwrite businesses, and that it is not usefull to let it return this is already being used once you make one, because you will need an open ID then.

Also why does no other command works once I use /checkbiz?
Reply
#6

I don't know why you would make 250 businesses already when they can be made in-game which would have an auto-incrementing ID, but nevertheless, you could make a field wherein it'll be detected if the business is an open spot or not. Did I get your point?
Reply
#7

Quote:
Originally Posted by Alvord
Посмотреть сообщение
I don't know why you would make 250 businesses already when they can be made in-game which would have an auto-incrementing ID, but nevertheless, you could make a field wherein it'll be detected if the business is an open spot or not. Did I get your point?
Well as you can see it is looking for:

pawn Код:
if(Business[idx][bBuyPrice] == 0)
{
}
Once a biz is created ingame it will always cost more then it so this is actually the field to detect if it is open or not. This is the same with the house, but still at the /checkhouse it will return ALL open slots and once I do /checkbiz it will return SERVER: Unknown Command. And no other command will work after it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)