#1

Okay this might be a big problem but i can't find solution so I tought you could help me..
PHP код:
CMD:createhouse(playeridparams[])
{
    if(
PlayerInfo[playerid][Admin] < 5)
    {
        
ERROR(playerid"You are not allowed to use this command");
        return 
1;
    }
    new 
typelevelprice;
    if(
sscanf(params"iii"typelevelprice))
    {
        
USAGE(playerid"/createhouse [Type] [Level] [Price]");
        
INFO(playerid"Type | 1 - Camp House | 2 - Small House | 3 - Medium House");
        
INFO(playerid"Type | 4 - Big House | 5 - Villa");
        return 
1;
    }
    if(
type || type 5)
    {
        
ERROR(playerid"Type can't be higher than 5 and lower than 1");
        return 
1;
    }
    if(
level || level 100)
    {
        
ERROR(playerid"Level can't be higher than 100 and lower than 1");
        return 
1;
    }
    if(
price 1)
    {
        
ERROR(playerid"Price can't be lower than 1$");
        return 
1;
    }
    new 
house;
    if(
HouseInfo[house][hID] > MAX_HOUSES)
    {
        
ERROR(playerid"Max houses reached!");
        return 
1;
    }
    if(
type == 1)
    {
        
HouseInfo[hID][hExitX] = 327.4407;
        
HouseInfo[hID][hExitY] = 1766.7507;
        
HouseInfo[hID][hExitZ] = 4.9849;
        
HouseInfo[hID][hType] = TYPE_CAMP;
        
strmid(HouseInfo[hID][hDescription],"Description",0,strlen("Description"),255);
        
HouseInfo[hID][hInt] = 2;
    }
    else if(
type == 2)
    {
        
HouseInfo[hID][hExitX] = 2308.7529;
        
HouseInfo[hID][hExitY] = -1212.5588;
        
HouseInfo[hID][hExitZ] = 1049.0234;
        
HouseInfo[hID][hType] = TYPE_SMALL;
        
strmid(HouseInfo[hID][hDescription], "Description",0,strlen("Description"),255);
        
HouseInfo[hID][hInt] = 6;
    }
    else if(
type == 3)
    {
        
HouseInfo[hID][hExitX] = 318.6055;
        
HouseInfo[hID][hExitY] = 1114.9292;
        
HouseInfo[hID][hExitZ] = 1083.8828;
        
HouseInfo[hID][hType] = TYPE_MEDIUM;
        
strmid(HouseInfo[hID][hDescription],"Description",0,strlen("Description"),255);
        
HouseInfo[hID][hInt] = 5;
    }
    else if(
type == 4)
    {
        
HouseInfo[hID][hExitX] = 386.6623;
        
HouseInfo[hID][hExitY] = 1471.7719;
        
HouseInfo[hID][hExitZ] = 1080.1875;
        
HouseInfo[hID][hType] = TYPE_BIG;
        
strmid(HouseInfo[hID][hDescription],"Description",0,strlen("Description"),255);
        
HouseInfo[hID][hInt] = 15;
    }
    else if(
type == 5)
    {
        
HouseInfo[hID][hExitX] = 2324.3840;
        
HouseInfo[hID][hExitY] = -1149.0188;
        
HouseInfo[hID][hExitZ] = 1050.7101;
        
HouseInfo[hID][hType] = TYPE_VILLA;
        
strmid(HouseInfo[hID][hDescription],"Description",0,strlen("Description"),255);
        
HouseInfo[hID][hInt] = 12;
    }
    new 
Float:XFloat:YFloat:Z;
    
house Iter_Free(i_Houses);
    
GetPlayerPos(playeridXYZ);
    
HouseInfo[house][hID] = house;
    
HouseInfo[house][hVW] = house;
    
HouseInfo[house][hOwnerCheck] = 0;
    
strmid(HouseInfo[house][hOwnerName], "Noone"0strlen("Noone"), 255);
    
HouseInfo[house][hEnterX] = X;
    
HouseInfo[house][hEnterY] = Y;
    
HouseInfo[house][hEnterZ] = Z;
    
HouseInfo[house][hLevel] = level;
    
HouseInfo[house][hPrice] = price;
    
HouseInfo[house][hMoney] = 0;
    
HouseInfo[house][hLocked] = 1;
    
HouseInfo[house][hWeapons] = -1;
    
HouseInfo[house][hAmmo] = 0;
    
HouseInfo[house][hRent]= 0;
    
HouseInfo[house][hRentPrice] = 20;
    
HouseInfo[house][hBell] = 0;
    
HouseInfo[house][hDrugs] = 0;
    
HouseInfo[house][HouseExist] = true;
    
Iter_Add(i_Houseshouse);
    
CreateHouses(house);
    new 
query[600];
    
mysql_format(g_SQLquerysizeof(query), "INSERT INTO `houses` (`ID`,`OwnerCheck`, `OwnerName`, `Description`, `Type`, `EnterX`, `EnterY`, `EnterZ`, `ExitX`, `ExitY`, `ExitZ`, `Level`, `Price`, `Money`, `Interior`, `VW`, `Locked`, `Rent`, `RentPrice`, `Weapons`, `Ammo`, `Bell`, `Drugs`)\
    VALUES (%d, %d, '%s', '%s', %d, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)"
,
    
HouseInfo[house][hID], HouseInfo[house][hOwnerCheck], HouseInfo[house][hOwnerName], HouseInfo[house][hDescription], HouseInfo[house][hType], HouseInfo[house][hEnterX], HouseInfo[house][hEnterY], HouseInfo[house][hEnterZ], HouseInfo[house][hExitX], HouseInfo[house][hExitY], HouseInfo[house][hExitZ], HouseInfo[house][hLevel], HouseInfo[house][hPrice], HouseInfo[house][hMoney], HouseInfo[house][hInt], HouseInfo[house][hVW], HouseInfo[house][hLocked], HouseInfo[house][hRent],
    
HouseInfo[house][hRentPrice], HouseInfo[house][hWeapons], HouseInfo[house][hAmmo], HouseInfo[house][hBell], HouseInfo[house][hDrugs]);
    
mysql_tquery(g_SQLquery);
    return 
1;

That is /createhouse command.. Problem is when I create first house as type 5 (Villa) it will be created as villa.. but every other house will be created as camp house.. Any ideas why is this happening??

But it is saved in mysql table as villa.. WTF..

Here are functions
PHP код:
HouseType(id)
{
    new 
string[17];
    switch(
id)
    {
        case 
TYPE_CAMPstring "Camp House";
        case 
TYPE_SMALLstring "Small House";
        case 
TYPE_MEDIUMstring "Medium House";
        case 
TYPE_BIGstring "Big House";
        case 
TYPE_VILLAstring "Villa";
        default: 
string "Unknown";
    }
    return 
string;
}
CreateHouses(id)
{
    if(
HouseInfo[id][hOwnerCheck] == 0)
    {
        new 
string[320];
        
format(stringsizeof(string), ""SERVERBLUE"House on sale\n"SERVERBLUE"Type: "WHITE"%s\n"SERVERBLUE"Price: "WHITE"%d\n"SERVERBLUE"Level: "WHITE"%d\n"SERVERBLUE"To buy house type /buyhouse"HouseType(HouseInfo[id][hType]), HouseInfo[id][hPrice], HouseInfo[id][hLevel]);
        
HouseLabel[id] = CreateDynamic3DTextLabel(string0x1D9F00AAHouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]+0.125.0___00__);
        
HousePickup[id] = CreateDynamicPickup(12731HouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]);
    }
    else if(
HouseInfo[id][hOwnerCheck] == 1)
    {
        new 
string[320], string2[220], string3[540];
        if(
HouseInfo[id][hRent] == 0)
        {
            
format(stringsizeof(string), ""SERVERBLUE"[ "WHITE"%s "SERVERBLUE"]\n"SERVERBLUE"Owner: "WHITE"%s\b"SERVERBLUE"Type: "WHITE"%d\n"HouseInfo[id][hDescription], HouseInfo[id][hOwnerName], HouseInfo[id][hType]);
            
format(string2sizeof(string2), ""SERVERBLUE"Level: "WHITE"%d\n"SERVERBLUE"Price: "WHITE"%d\n"SERVERBLUE"To enter press 'F' or 'ENTER'"HouseInfo[id][hLevel], HouseInfo[id][hPrice]);
            
format(string3sizeof(string3), "%s%s"stringstring2);
            
HouseLabel[id] = CreateDynamic3DTextLabel(string30x1D9F00AAHouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]+0.125.0___00__);
            
HousePickup[id] = CreateDynamicPickup(12731HouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]);
        }
        else if(
HouseInfo[id][hRent] == 1)
        {
            
format(stringsizeof(string), ""SERVERBLUE"[ "WHITE"%s "SERVERBLUE"]\n"SERVERBLUE"Owner: "WHITE"%s\b"SERVERBLUE"Type: "WHITE"%d\n"SERVERBLUE"Rent: "WHITE"%d$(/renthouse)"HouseInfo[id][hDescription], HouseInfo[id][hOwnerName], HouseInfo[id][hType], HouseInfo[id][hRentPrice]);
            
format(string2sizeof(string2), ""SERVERBLUE"Level: "WHITE"%d\n"SERVERBLUE"Price: "WHITE"%d\n"SERVERBLUE"To enter press 'F' or 'ENTER'"HouseInfo[id][hLevel], HouseInfo[id][hPrice]);
            
format(string3sizeof(string3), "%s%s"stringstring2);
            
HouseLabel[id] = CreateDynamic3DTextLabel(string30x1D9F00AAHouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]+0.125.0___00__);
            
HousePickup[id] = CreateDynamicPickup(12731HouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]);
        }
    }
    return 
1;

Reply
#2

Quote:
PHP код:
    new house;
    if(
HouseInfo[house][hID] > MAX_HOUSES
I do not understand how you think this can even function? That variable never gets assigned a value and as such will always be 0.

In the next part suddenly "hID" is used as the array index instead. Where does this variable come from? Is it a global? Where does it get assigned a value? I'm having a hard time understanding it all.
Reply
#3

I fixed it
Problem was that this
PHP код:
house Iter_Free(i_Houses); 
Should be putted before
PHP код:
if(type == 1
{
       
//code] 
And when house exceed max limit it won't create more houses but problem is it sends message
Код:
Server: Unknown command
I have to fix that but I will find way don't worry
Reply
#4

Okay so new problem descovered. When I create 10 houses problem is that first house is created but it is not written in DB. every other is written but first isn't.. any ideas??
Reply
#5

Quote:
Originally Posted by Micko123
Посмотреть сообщение
Okay so new problem descovered. When I create 10 houses problem is that first house is created but it is not written in DB. every other is written but first isn't.. any ideas??
is there have any error/warning in log of mysql?
maybe can find some reason
Reply
#6

I found this
Код:
[22:15:34] [ERROR] error #1062 while executing query "INSERT INTO `houses` (`ID`,`OwnerCheck`, `OwnerName`, `Description`, `Type`, `EnterX`, `EnterY`, `EnterZ`, `ExitX`, `ExitY`, `ExitZ`, `Level`, `Price`, `Money`, `Interior`, `VW`, `Locked`, `Rent`, `RentPrice`, `Weapons`, `Ammo`, `Bell`, `Drugs`)VALUES (1, 0, 'Noone', 'Medium House', 'Medium House', 2523.271240, -1679.245483, 15.497000, 318.605499, 1114.929199, 1083.882813, 7, 50000, 0, 5, 1, 1, 0, 20, -1, 0, 0, 0)": Duplicate entry '1' for key 'PRIMARY' (C:\Users\Micko\Desktop\MySQL\gamemodes\Untitled.pwn:6412)
Reply
#7

-FIXED-

Konstantinos reply on this thread helped me..

https://sampforum.blast.hk/showthread.php?tid=615848
Reply
#8

New problem..
When I create house it is created nicely and saved nicely.. but every house is loaded as Camp House..
PHP код:
CreateHouses(id)
{
    if(
HouseInfo[id][hOwnerCheck] == 0)
    {
        new 
string[320];
        
format(stringsizeof(string), ""SERVERBLUE"House on sale\n"SERVERBLUE"Type: "WHITE"%s\n"SERVERBLUE"Price: "WHITE"%d\n"SERVERBLUE"Level: "WHITE"%d\n"SERVERBLUE"To buy house type /buyhouse"HouseType(HouseInfo[id][hType]), HouseInfo[id][hPrice], HouseInfo[id][hLevel]);
        
HouseLabel[id] = CreateDynamic3DTextLabel(string0x1D9F00AAHouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]+0.125.0___00__);
        
HousePickup[id] = CreateDynamicPickup(12731HouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]);
    }
    else if(
HouseInfo[id][hOwnerCheck] == 1)
    {
        new 
string[320], string2[220], string3[540];
        if(
HouseInfo[id][hRent] == 0)
        {
            
format(stringsizeof(string), ""SERVERBLUE"[ "WHITE"%s "SERVERBLUE"]\n"SERVERBLUE"Owner: "WHITE"%s\b"SERVERBLUE"Type: "WHITE"%d\n"HouseInfo[id][hDescription], HouseInfo[id][hOwnerName], HouseInfo[id][hType]);
            
format(string2sizeof(string2), ""SERVERBLUE"Level: "WHITE"%d\n"SERVERBLUE"Price: "WHITE"%d\n"SERVERBLUE"To enter press 'F' or 'ENTER'"HouseInfo[id][hLevel], HouseInfo[id][hPrice]);
            
format(string3sizeof(string3), "%s%s"stringstring2);
            
HouseLabel[id] = CreateDynamic3DTextLabel(string30x1D9F00AAHouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]+0.125.0___00__);
            
HousePickup[id] = CreateDynamicPickup(12731HouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]);
        }
        else if(
HouseInfo[id][hRent] == 1)
        {
            
format(stringsizeof(string), ""SERVERBLUE"[ "WHITE"%s "SERVERBLUE"]\n"SERVERBLUE"Owner: "WHITE"%s\b"SERVERBLUE"Type: "WHITE"%d\n"SERVERBLUE"Rent: "WHITE"%d$(/renthouse)"HouseInfo[id][hDescription], HouseInfo[id][hOwnerName], HouseInfo[id][hType], HouseInfo[id][hRentPrice]);
            
format(string2sizeof(string2), ""SERVERBLUE"Level: "WHITE"%d\n"SERVERBLUE"Price: "WHITE"%d\n"SERVERBLUE"To enter press 'F' or 'ENTER'"HouseInfo[id][hLevel], HouseInfo[id][hPrice]);
            
format(string3sizeof(string3), "%s%s"stringstring2);
            
HouseLabel[id] = CreateDynamic3DTextLabel(string30x1D9F00AAHouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]+0.125.0___00__);
            
HousePickup[id] = CreateDynamicPickup(12731HouseInfo[id][hEnterX], HouseInfo[id][hEnterY], HouseInfo[id][hEnterZ]);
        }
    }
    return 
1;
}
HouseType(id)
{
    new 
string[17];
    switch(
id)
    {
        case 
TYPE_CAMPstring "Camp House";
        case 
TYPE_SMALLstring "Small House";
        case 
TYPE_MEDIUMstring "Medium House";
        case 
TYPE_BIGstring "Big House";
        case 
TYPE_VILLAstring "Villa";
        default: 
string "Unknown";
    }
    return 
string;

They are loaded fine but only name is problem.. Any ideas>>
Name is hDescription
Reply
#9

Fixed..
Instead of
PHP код:
HouseType(id

    new 
string[17]; 
    switch(
id
    { 
        case 
TYPE_CAMPstring "Camp House"
        case 
TYPE_SMALLstring "Small House"
        case 
TYPE_MEDIUMstring "Medium House"
        case 
TYPE_BIGstring "Big House"
        case 
TYPE_VILLAstring "Villa"
        default: 
string "Unknown"
    } 
    return 
string

I was using strmid function to declare type to house
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)