SA-MP Forums Archive
House ID Help? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: House ID Help? (/showthread.php?tid=617139)



House ID Help? - DandyCorleone - 16.09.2016

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


PHP код:
CMD:createhouse(playerid, params[])
{
    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 
cost, hint;
    new 
Float:X, Float:Y, Float:Z;
    if(
sscanf(params, "iD(0)", cost, hint)) return ShowInfoBoxEx(playerid, COLOR_SYSTEM, E_CMD_USAGE_CREATEHOUSE);
    if(
Iter_Count(Houses) > MAX_HOUSES) return ShowInfoBoxEx(playerid, COLOR_SYSTEM, ""WHITE_E"Max limit of houses reached!");
    if(
hint < 0 || hint > MAX_HOUSE_INTERIORS) return ShowInfoBoxEx(playerid, COLOR_SYSTEM, E_INVALID_HINT);
    if(
cost < MIN_HOUSE_VALUE || cost > MAX_HOUSE_VALUE) return ShowInfoBoxEx(playerid, COLOR_SYSTEM, E_INVALID_HVALUE);
    else
    {
        
// Set a random interior if not specified.
        
if(hint == 0)
        {
             
hint = random(10);
        }
        
GetPlayerPos(playerid, Xp, Yp, Zp);
        
GetPlayerFacingAngle(playerid, Angle);
        
        new 
interior = GetPlayerInterior(playerid);
        
GetPlayerPos(playerid, X, Y, Z);
        
GetPosInFrontOfPlayer(playerid, X, Y, -2.5);
        
format(query, sizeof(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)", X, Y, Zp, (180.0 + Angle), Xp, Yp, Zp, interior, cost);
        
MySQL_query(query, false, "OnHouseCreate", "ifffffffii", playerid, Xp, Yp, Zp, (180.0 + Angle), X, Y, Zp, hint, cost);
    }
    return 
1;
}
forward OnHouseCreate(playerid, Float:inX, Float:inY, Float:inZ, Float:outA, Float:outX, Float:outY, Float:outZ, interiorID, cost);
public 
OnHouseCreate(playerid, Float:inX, Float:inY, Float:inZ, Float:outA, Float:outX, Float:outY, Float:outZ, interiorID, cost)
{
    new 
h = cache_insert_id();
    new 
labeltext[300];
    
printf("A_I value of the newly entered house: %d", h);
    
hInfo[h][CPOutX] = inX, hInfo[h][CPOutY] = inY, hInfo[h][CPOutZ] = inZ;
    
hInfo[h][SpawnOutX] = outX, hInfo[h][SpawnOutY] = outY, hInfo[h][SpawnOutZ] = outZ, hInfo[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] = cost, hInfo[h][HouseStorage] = 0, hInfo[h][HouseForSale] = 0;
    
format(labeltext, sizeof(labeltext), LABELTEXT1, DEFAULT_HOUSE_NAME, ToCurrency(cost), h);
    
HouseMIcon[h] = CreateDynamicMapIcon(inX, inY, inZ, 31, -1, -1, -1, -1, MICON_VD);
    
HouseLabel[h] = CreateDynamic3DTextLabel(labeltext, COLOR_GREEN, inX, inY, inZ+0.7, TEXTLABEL_DISTANCE, .testlos = 1);
    
HousePickupOut[h] = CreateDynamicPickup(PICKUP_MODEL_OUT, PICKUP_TYPE, inX, inY, inZ, -1, -1, -1, 30.0);
    
HousePickupInt[h] = CreateDynamicPickup(PICKUP_MODEL_INT, PICKUP_TYPE, hIntInfo[interiorID][IntCPX], hIntInfo[interiorID][IntCPY], hIntInfo[interiorID][IntCPZ], (h + 1000), hIntInfo[interiorID][IntInterior], -1, 15.0);
    
ShowInfoBox(playerid, I_H_CREATED, h);
    
format(str, sizeof(str), "Server: "GREY2_E"House ID "GREY_E"[%d] "GREY2_E"created!", h);
    
SendClientMessage(playerid, COLOR_RED, str);
    
    
Iter_Add(Houses, h);
    
format(query, sizeof(query), "UPDATE houses SET hlocation='%s',hint=%d WHERE house_id=%d", hInfo[h][HouseLocation], interiorID, h);
    
MySQL_updateQuery(query);
    return 
1;
} 



Re: House ID Help? - Konstantinos - 16.09.2016

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.


Re: House ID Help? - DandyCorleone - 16.09.2016

ahh.. okey, i will try using it. thnk


Re: House ID Help? - DandyCorleone - 16.09.2016

How the script bro?

PHP код:
CREATE TABLE `houses` (
  `
house_id` mediumint(4) NOT NULL,
  `
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'
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; 



Re: House ID Help? - Konstantinos - 16.09.2016

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