House ID Help?
#1

why each I /createhouse, in id the house is always 0? how to order the house next id in /createhouse?


PHP код:
CMD:createhouse(playeridparams[])
{
    if(
pAdmin[playerid] < 4)
        return 
Error(playerid"You are not authorized to use this command!");
    if(
GetPlayerInterior(playerid) != 0)
        return 
Error(playerid"You can't create houses on any interior other than 0.");
    new 
costhint;
    new 
Float:XFloat:YFloat:Z;
    if(
sscanf(params"iD(0)"costhint)) return ShowInfoBoxEx(playeridCOLOR_SYSTEME_CMD_USAGE_CREATEHOUSE);
    if(
Iter_Count(Houses) > MAX_HOUSES) return ShowInfoBoxEx(playeridCOLOR_SYSTEM""WHITE_E"Max limit of houses reached!");
    if(
hint || hint MAX_HOUSE_INTERIORS) return ShowInfoBoxEx(playeridCOLOR_SYSTEME_INVALID_HINT);
    if(
cost MIN_HOUSE_VALUE || cost MAX_HOUSE_VALUE) return ShowInfoBoxEx(playeridCOLOR_SYSTEME_INVALID_HVALUE);
    else
    {
        
// Set a random interior if not specified.
        
if(hint == 0)
        {
             
hint random(10);
        }
        
GetPlayerPos(playeridXpYpZp);
        
GetPlayerFacingAngle(playeridAngle);
        
        new 
interior GetPlayerInterior(playerid);
        
GetPlayerPos(playeridXYZ);
        
GetPosInFrontOfPlayer(playeridXY, -2.5);
        
format(querysizeof(query), "INSERT INTO houses(house_id,hname,howner,hpass,x,y,z,a,cpx,cpy,cpz,hint,hvalue) VALUES(0,'House For Sale!','INVALID_PLAYER_ID','INVALID_HOUSE_PASSWORD', %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %d, %d)"XYZp, (180.0 Angle), XpYpZpinteriorcost);
        
MySQL_query(queryfalse"OnHouseCreate""ifffffffii"playeridXpYpZp, (180.0 Angle), XYZphintcost);
    }
    return 
1;
}
forward OnHouseCreate(playeridFloat:inXFloat:inYFloat:inZFloat:outAFloat:outXFloat:outYFloat:outZinteriorIDcost);
public 
OnHouseCreate(playeridFloat:inXFloat:inYFloat:inZFloat:outAFloat:outXFloat:outYFloat:outZinteriorIDcost)
{
    new 
cache_insert_id();
    new 
labeltext[300];
    
printf("A_I value of the newly entered house: %d"h);
    
hInfo[h][CPOutX] = inXhInfo[h][CPOutY] = inYhInfo[h][CPOutZ] = inZ;
    
hInfo[h][SpawnOutX] = outXhInfo[h][SpawnOutY] = outYhInfo[h][SpawnOutZ] = outZhInfo[h][SpawnOutAngle] = outA;
    
hInfo[h][HouseInterior] = interiorID;
    
format(hInfo[h][HousePassword], 28"%s""INVALID_HOUSE_PASSWORD");
    
format(hInfo[h][HouseName], 28"%s"DEFAULT_HOUSE_NAME);
    
format(hInfo[h][HouseOwner], 24"%s"INVALID_HOWNER_NAME);
    
format(hInfo[h][HouseLocation], 30"%s"GetHouseLocation(h));
    
hInfo[h][HouseValue] = costhInfo[h][HouseStorage] = 0hInfo[h][HouseForSale] = 0;
    
format(labeltextsizeof(labeltext), LABELTEXT1DEFAULT_HOUSE_NAMEToCurrency(cost), h);
    
HouseMIcon[h] = CreateDynamicMapIcon(inXinYinZ31, -1, -1, -1, -1MICON_VD);
    
HouseLabel[h] = CreateDynamic3DTextLabel(labeltextCOLOR_GREENinXinYinZ+0.7TEXTLABEL_DISTANCE, .testlos 1);
    
HousePickupOut[h] = CreateDynamicPickup(PICKUP_MODEL_OUTPICKUP_TYPEinXinYinZ, -1, -1, -130.0);
    
HousePickupInt[h] = CreateDynamicPickup(PICKUP_MODEL_INTPICKUP_TYPEhIntInfo[interiorID][IntCPX], hIntInfo[interiorID][IntCPY], hIntInfo[interiorID][IntCPZ], (1000), hIntInfo[interiorID][IntInterior], -115.0);
    
ShowInfoBox(playeridI_H_CREATEDh);
    
format(strsizeof(str), "Server: "GREY2_E"House ID "GREY_E"[%d] "GREY2_E"created!"h);
    
SendClientMessage(playeridCOLOR_REDstr);
    
    
Iter_Add(Housesh);
    
format(querysizeof(query), "UPDATE houses SET hlocation='%s',hint=%d WHERE house_id=%d"hInfo[h][HouseLocation], interiorIDh);
    
MySQL_updateQuery(query);
    return 
1;

Reply
#2

cache_insert_id returns 0 if the column is not set as A_I (auto increment) in R39-6 and below. In the INSERT query, set house_id as NULL or remove it completely and it will be auto generated. If you have NO_AUTO_VALUE_ON_ZERO sql mode disabled then you can use 0 but it's still not recommended as it causes few problems with mysqldump.
Reply
#3

ahh.. okey, i will try using it. thnk
Reply
#4

How the script bro?

PHP код:
CREATE TABLE `houses` (
  `
house_idmediumint(4NOT NULL,
  `
hnamevarchar(35NOT NULL,
  `
hownervarchar(21NOT NULL,
  `
hlocationvarchar(30NOT NULL DEFAULT '*',
  `
hpassvarchar(24NOT NULL,
  `
last_visitedint(11UNSIGNED NOT NULL DEFAULT '0',
  `
xfloat NOT NULL DEFAULT '0',
  `
yfloat NOT NULL DEFAULT '0',
  `
zfloat NOT NULL DEFAULT '0',
  `
afloat NOT NULL DEFAULT '0',
  `
cpxfloat NOT NULL DEFAULT '0',
  `
cpyfloat NOT NULL DEFAULT '0',
  `
cpzfloat NOT NULL DEFAULT '0',
  `
hvalueint(12UNSIGNED NOT NULL DEFAULT '500',
  `
hforsaleint(12UNSIGNED NOT NULL DEFAULT '0',
  `
hstorageint(12UNSIGNED NOT NULL DEFAULT '0',
  `
hinttinyint(2UNSIGNED NOT NULL DEFAULT '4',
  `
hprivacytinyint(1UNSIGNED NOT NULL DEFAULT '0'
ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC
Reply
#5

If you have records in the table that you want to keep, just execute:
pawn Код:
ALTER TABLE houses MODIFY house_id MEDIUMINT(4) PRIMARY KEY AUTO_INCREMENT;
so each house ID will be automatically regenerated starting from 1. The query for the table:
pawn Код:
CREATE TABLE `houses` (
 `house_id` mediumint(4) NOT NULL AUTO_INCREMENT,
 `hname` varchar(35) NOT NULL,
 `howner` varchar(21) NOT NULL,
 `hlocation` varchar(30) NOT NULL DEFAULT '*',
 `hpass` varchar(24) NOT NULL,
 `last_visited` int(11) unsigned NOT NULL DEFAULT '0',
 `x` float NOT NULL DEFAULT '0',
 `y` float NOT NULL DEFAULT '0',
 `z` float NOT NULL DEFAULT '0',
 `a` float NOT NULL DEFAULT '0',
 `cpx` float NOT NULL DEFAULT '0',
 `cpy` float NOT NULL DEFAULT '0',
 `cpz` float NOT NULL DEFAULT '0',
 `hvalue` int(12) unsigned NOT NULL DEFAULT '500',
 `hforsale` int(12) unsigned NOT NULL DEFAULT '0',
 `hstorage` int(12) unsigned NOT NULL DEFAULT '0',
 `hint` tinyint(2) unsigned NOT NULL DEFAULT '4',
 `hprivacy` tinyint(1) unsigned NOT NULL DEFAULT '0',
 PRIMARY KEY (`house_id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)