ID not valid
#21

Bump. Anyone?
Reply
#22

Why are you using y_iterate already??

Why not just simply..

PHP код:
CMD:creategarage(playeridparams[])
{
    if(
Player[playerid][AdminLevel] < 5) return 0;
    new 
pricesize;
    if(
sscanf(params"dd(0)"pricesize))
    {
        
SCM(playeridCOLOR_BELGREEN"» [USAGE]: /creategarage [price] [size(default 0)]");
        return 
SCM(playeridCOLOR_BELGREEN"» Size: 0 - Small Garage , 1 - Medium Garage, 2 - Big Garage.");
    }
    if((
size 0) || (size 2)) return SCM(playeridCOLOR_ERROR"» Size must be from 0 to 2.");
    if((
price 1) || (price 999999)) return SCM(playeridCOLOR_ERROR"» Invalid price.");
    for(new 
1MAX_GARAGESi++)
    {
        if(!
GarageInfo[i][garageExists])
        {
            
GarageInfo[i][garageID] = i;
            new 
query[300];
            
mysql_format(g_SQLquerysizeof query"INSERT INTO `garages` (`garagePrice`, `garageSize`) VALUES ('%d', '%d')"pricesize);
            
mysql_tquery(g_SQLquery"OnGarageCreated""d"i);
            
GarageInfo[i][garageExists] = true;
            
GetPlayerPos(playeridGarageInfo[i][garagePos][0], GarageInfo[i][garagePos][1], GarageInfo[i][garagePos][2]);
            
GetPlayerFacingAngle(playeridGarageInfo[i][garagePos][3]);
            
GarageInfo[i][garagePos][0] = GarageInfo[i][garagePos][0] + (1.5 floatsin(-GarageInfo[i][garagePos][3], degrees));
            
GarageInfo[i][garagePos][1] = GarageInfo[i][garagePos][1] + (1.5 floatcos(-GarageInfo[i][garagePos][3], degrees));
            
GarageInfo[i][garageVW] = GetPlayerVirtualWorld(playerid);
            
GarageInfo[i][garagePrice] = price;
            
GarageInfo[i][garageSize] = size;
            
RefreshGarage(i);
            
SCMEX(playeridCOLOR_YELLOW"» You have successfully created a garage. ID: %d - Price: %s - Size: %d"iformatInt(price), size);
            
            
printf("Garage is saved for i: %d"i);
            if(
== -1) return SCM(playeridCOLOR_ERROR"» The server has reached the limit for garages.");
            return 
1;
        }
    }    

PHP код:
function OnQueryFinished(extraidthreadid)
{
    switch(
threadid)
    {
        case 
THREAD_CREATE_GARAGE:
        {
            
GarageInfo[extraid][garageID] = extraid;
            
SaveGarage(extraid);
        }
    }
    return 
1;

i believe that would do enough, no need for the y_iterate.
Reply
#23

Excuse me, you're using OnQueryFinished, but i don't see it calling in /creategarage code, or am i blind? You're just calling OnGarageCreated.

Also i'm getting invalid function call at:

pawn Код:
mysql_tquery(g_SQL, query, "OnGarageCreated", "d", GarageInfo();
Reply
#24

My bad..

PHP код:
CMD:creategarage(playeridparams[]) 

    if(
Player[playerid][AdminLevel] < 5) return 0
    new 
pricesize
    if(
sscanf(params"dd(0)"pricesize)) 
    { 
        
SCM(playeridCOLOR_BELGREEN"» [USAGE]: /creategarage [price] [size(default 0)]"); 
        return 
SCM(playeridCOLOR_BELGREEN"» Size: 0 - Small Garage , 1 - Medium Garage, 2 - Big Garage."); 
    } 
    if((
size 0) || (size 2)) return SCM(playeridCOLOR_ERROR"» Size must be from 0 to 2."); 
    if((
price 1) || (price 999999)) return SCM(playeridCOLOR_ERROR"» Invalid price."); 
    for(new 
1MAX_GARAGESi++) 
    { 
        if(!
GarageInfo[i][garageExists]) 
        { 
            
GarageInfo[i][garageID] = i
            new 
query[300]; 
            
mysql_format(g_SQLquerysizeof query"INSERT INTO `garages` (`garagePrice`, `garageSize`) VALUES ('%d', '%d')"pricesize);
    
mysql_tquery(g_SQLquery"OnQueryFinished""dd"idTHREAD_CREATE_GARAGE);
            
GarageInfo[i][garageExists] = true
            
GetPlayerPos(playeridGarageInfo[i][garagePos][0], GarageInfo[i][garagePos][1], GarageInfo[i][garagePos][2]); 
            
GetPlayerFacingAngle(playeridGarageInfo[i][garagePos][3]); 
            
GarageInfo[i][garagePos][0] = GarageInfo[i][garagePos][0] + (1.5 floatsin(-GarageInfo[i][garagePos][3], degrees)); 
            
GarageInfo[i][garagePos][1] = GarageInfo[i][garagePos][1] + (1.5 floatcos(-GarageInfo[i][garagePos][3], degrees)); 
            
GarageInfo[i][garageVW] = GetPlayerVirtualWorld(playerid); 
            
GarageInfo[i][garagePrice] = price
            
GarageInfo[i][garageSize] = size
            
RefreshGarage(i); 
            
SCMEX(playeridCOLOR_YELLOW"» You have successfully created a garage. ID: %d - Price: %s - Size: %d"iformatInt(price), size); 
             
            
printf("Garage is saved for i: %d"i); 
            if(
== -1) return SCM(playeridCOLOR_ERROR"» The server has reached the limit for garages."); 
            return 
1
        } 
    }     

Reply
#25

Ok forget my last post. Managed to fix garage creation. Now they start with ID 1, IG and in table are saved correctly.

There is a problem now, with the /buygarage command, it doesn't want update new owner ID (associated with Player[playerid][ID]), because it saves the new garage ownership info on ID 0. (This fuckin' ID 0 is a nightmare).

pawn Код:
CMD:buygarage(playerid, params[])
{
    new id = GetNearestGarage(playerid);

    if(id == -1) return SCM(playerid, COLOR_ERROR, "» There are no garages near you.");

    if(GarageInfo[id][garageOwnerID] == Player[playerid][ID]) return SCM(playerid, COLOR_ERROR, "» This garage is already yours.");

    if(GarageInfo[id][garageOwned]) return SCM(playerid, COLOR_ERROR, "» This garage has been already bought.");

    if(GetPlayerMoney(playerid) < GarageInfo[id][garagePrice])
    return SCMEX(playerid, COLOR_ERROR, "» You can't afford to buy this garage. You need %s.", formatInt(GarageInfo[id][garagePrice]));

    SCMEX(playerid, COLOR_YELLOW, "» [GARAGE] You've bought this garage for %s!", formatInt(GarageInfo[id][garagePrice]));
    SCM(playerid, COLOR_YELLOW, "» [GARAGE] Garage keys and ownership have been transferred to you.");

    GivePlayerMoney(playerid, -GarageInfo[id][garagePrice]);

    GarageInfo[id][garageOwned] = 1;
    GarageInfo[id][garagePrice] = 0;
    GarageInfo[id][garagePlayerSellPrice] = 0;
    GarageInfo[id][garageOwnerID] = Player[playerid][ID];

    RefreshGarage(id);
    SaveGarage(id);

    GameTextForPlayer(playerid, "~w~Garage ~g~bought~w~!", 3000, 3);
    return 1;
}
Mysql log:

Quote:

[15:01:59] [DEBUG] mysql_query(1, "UPDATE `garages` SET `garageOwnerID` = '1', `garageOwned` = '1', `garagePrice` = '0', `garagePlayerSellPrice` = '0', `garageSize` = '2', `garageCustomName` = 'e' WHERE `garageID` = '0'", 1) (C:\test\gamemodes\server.pwn:2602 -> C:\test\gamemodes\server.pwn:6480)
[15:01:59] [DEBUG] CHandle::Execute(this=0x23df80, type=3, query=0x2a932
[15:01:59] [DEBUG] CConnection::Execute(query=0x2a9328, this=0x23f4d8, connection=0x2007f0)
[15:01:59] [DEBUG] CQuery::Execute(this=0x2a9328, connection=0x2007f0)
[15:01:59] [INFO] query "UPDATE `garages` SET `garageOwnerID` = '1', `garageOwned` = '1', `garagePrice` = '0', `garagePlayerSellPrice` = '0', `garageSize` = '2', `garageCustomName` = 'e' WHERE `garageID` = '0'" successfully executed within 0.800 milliseconds
[15:01:59] [DEBUG] CResultSet::Create(connection=0x2007f0, query_str='UPDATE `garages` SET `garageOwnerID` = '1', `garageOwned` = '1', `garagePrice` = '0', `garagePlayerSellPrice` = '0', `garageSize` = '2', `garageCustomName` = 'e' WHERE `garageID` = '0'')

EDIT: Fixed by removing SaveGarage on /buygarage and adding:

pawn Код:
new query[300];
    mysql_format(g_SQL, query, sizeof query, "UPDATE `garages` SET `garageOwned` = 1, `garagePrice` = 0, `garagePlayerSellPrice` = 0, `garageOwnerID` = '%d'",
    Player[playerid][ID]);
    mysql_tquery(g_SQL, query, "OnQueryFinished", "dd", id, THREAD_SAVE_GARAGE);
And in THREAD_SAVE_GARAGE i just added SaveGarage. Now everything works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)