28.11.2015, 18:03
Try this:
About the /createhouse command, I've had a similar problem. What I did was I inserted a new record in the shops table and then called another method, OnCreateShop. This allowed me to use cache_insert_id() to retrieve the ID of the auto generated field ID.
Example:
Код:
forward OnLoadHouses(); public OnLoadHouses() { new index; new rows = cache_num_rows(); if(rows) { while(index < rows) { hInfo[index][ID] = cache_get_field_content_int(index, "ID"); cache_get_field_content(index, "Owner", hInfo[index][Owner], mysql, 128); hInfo[index][Owned] = cache_get_field_content_int(index, "Owned"); hInfo[index][Locked] = cache_get_field_content_int(index, "Locked"); hInfo[index][Price] = cache_get_field_content_int(index, "Price"); hInfo[index][OX] = cache_get_field_content_float(index, "OX"); hInfo[index][OY] = cache_get_field_content_float(index, "OY"); hInfo[index][OZ] = cache_get_field_content_float(index, "OZ"); hInfo[index][World] = cache_get_field_content_int(index, "World"); hInfo[index][OnSale] = cache_get_field_content_int(index, "OnSale"); hInfo[index][InteriorID] = cache_get_field_content_int(index, "InteriorID"); new lString[500]; if(hInfo[index][OnSale] == 0 ) { switch(hInfo[index][Owned]) { case 0: { hInfo[index][Label] = CreateDynamic3DTextLabel("This House is on Sale\n{FFFFFF}Press [F] to Buy", 0xFF9900FF, hInfo[index][OX], hInfo[index][OY], hInfo[index][OZ]+0.5, 36.0, .testlos = 1); hInfo[index][Icon] = CreateDynamicMapIcon(hInfo[index][OX], hInfo[index][OY], hInfo[index][OZ], 31, -1); hInfo[index][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[index][OX], hInfo[index][OY], hInfo[index][OZ], -1, -1, -1, 36.0); loaded++; Iter_Add(Houses, loaded); } case 1: { switch(hInfo[index][Locked]) { case 0: { format(lString, sizeof(lString), "%s's House\n{FFFFFF}Press [F] to Enter", hInfo[index][Owner]); hInfo[index][Label] = CreateDynamic3DTextLabel(lString, 0xFF9900FF, hInfo[index][OX], hInfo[index][OY], hInfo[index][OZ]+0.5, 36.0, .testlos = 1); hInfo[index][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[index][OX],hInfo[index][OY], hInfo[index][OZ], -1, -1, -1, 36.0); } case 1: { format(lString, sizeof(lString), "%s's House\n{E00B0B}Locked\n{FFFFFF}Press [F] to Enter", hInfo[i][Owner]); hInfo[index][Label] = CreateDynamic3DTextLabel(lString, 0xFF9900FF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0, .testlos = 1); hInfo[index][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[index][OX],hInfo[index][OY], hInfo[index][OZ], -1, -1, -1, 36.0); } } loaded++; Iter_Add(Houses, loaded); } } } if(hInfo[index][OnSale] == 1) { format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse On Sale: Yes", hInfo[index][Owner], hInfo[index][Price]); hInfo[index][Label] = CreateDynamic3DTextLabel(lString, 0xD65418FF, hInfo[index][OX], hInfo[index][OY], hInfo[index][OZ]+0.5, 36.0, .testlos = 1); hInfo[index][Icon] = CreateDynamicMapIcon(hInfo[index][OX], hInfo[index][OY], hInfo[index][OZ], 32, -1); hInfo[index][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[index][OX],hInfo[index][OY], hInfo[index][OZ], -1, -1, -1, 36.0); loaded++; Iter_Add(Houses, loaded); } index++; } } if(index > 1) printf("[House System] %i houses were created...", index); return 1; }
Example:
Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `shops` (`ID`, `Header`, `PosX`, `PosY`, `PosZ`) VALUES (NULL, '%e', %f, %f, %f)", header, pos[0], pos[1], pos[2]); mysql_tquery(mysql, query, "OnCreateShop", "sfff", header, pos[0], pos[1], pos[2]); return 1; } forward OnCreateShop(header[], Float:posX, Float:posY, Float:posZ); public OnCreateShop(header[], Float:posX, Float:posY, Float:posZ) { new insertID, string[128]; insertID = cache_insert_id(); ShopInfo[insertID][ID] = insertID; format(ShopInfo[insertID][Header], 128, header); format(string, sizeof(string), COL_GOLD"ID{FFFFFF}: %i - {FFD700}%s{FFFFFF}", ShopInfo[insertID][ID], ShopInfo[insertID][Header]); ShopInfo[insertID][Pos][0] = posX; ShopInfo[insertID][Pos][1] = posY; ShopInfo[insertID][Pos][2] = posZ; ShopInfo[insertID][Text] = CreateDynamic3DTextLabel(string, 0xFFD700FF, ShopInfo[insertID][Pos][0], ShopInfo[insertID][Pos][1], ShopInfo[insertID][Pos][2], 5.0); ShopInfo[insertID][Pickup] = CreateDynamicPickup(1254, 1, ShopInfo[insertID][Pos][0], ShopInfo[insertID][Pos][1], ShopInfo[insertID][Pos][2]); return 1; }