2021-05-18, 12:01 AM
(This post was last modified: 2021-05-21, 12:55 PM by PutuSuhartawan.)
SOLUTION:
Need get cahce GetSVarInt("SlotTrunkUsed")
return SQL:
PROBLEM: No icrement in new ID maker from enum.
Need get cahce GetSVarInt("SlotTrunkUsed")
Code:
GetFreeTrunkID(v, s)
{
for (new i = 1; i <= 100; i++)
{
if (!get_vehicle_trunk[v][s][i])
{
return i + GetSVarInt("SlotTrunkUsed");
}
}
return -1; //Return -1 when there is no free trunk ID
}
return SQL:
Code:
if(sscanf( inputtext, "iiiii", targetOC_ID, slot, item_type, amount, value)) return SCM(playerid, -1, "USAGE: [targetOC_ID] [slot] [item_type] [amount] [value]");
new playa,carid=GetRealIdCar(targetOC_ID);
SetPVarInt(playerid, "SelectedSlot", slot);
printf("DEBUG: Checking VID changer from vehicle ID:[%d]", carid);
if(slot >= MAX_TRUNK_SLOTS || slot <= 0) return SCM(playerid, -1, "VEHICLE: Max trunk slot is 3 sir.",1);
printf("DEBUG: Adding item trunk in slot:[%d]", slot);
LoadOCTrunks(playerid, carid);
if(get_vehicle_trunk[carid][slot][TRUNK_SLOT]==slot) return SCM(playerid, -1, "OC_TRUNK: That slot has been used in this vehicle sir. Please remove item from this slot first.",1);
/*
for(new s=1; s<=10; s++)
{
if(get_vehicle_trunk[carid][s][TRUNK_SQL_ID]>0)continue;
if(get_vehicle_trunk[carid][s][TRUNK_SQL_ID]==slot)
{
break;
}
}
*/
if(!IsValidVehicle(carid))return SCM(playerid, -1, "VEHICLE: Thats vehicle has not exist sir.",1);
printf("DEBUG: Slot filter hassben passed sir");
new VID = targetOC_ID;
new result = n_mysql_query(g_Sql, "SELECT * FROM `trunkdata`", true); //ORDER BY oc_id ASC, slot ASC
new rows = cache_num_rows();
new number=get_vehicle_trunk[carid][slot][TRUNK_SQL_ID];
for(new v; v<=MAX_VEHICLES; v++)
{
for(new slot; slot<=MAX_TRUNK_SLOTS; slot++)
{
for(new idx; idx <= rows; idx ++)
{
cache_get_value_int(idx, "id", get_vehicle_trunk[v][slot][TRUNK_SQL_ID] );
/*
if(get_vehicle_trunk[v][slot][TRUNK_SQL_ID]>0)continue;
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
number++;
printf("[TRUNK]: New id:[%d]", number );
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
{
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
NewSQL_ID = number;
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
NewSQL_ID = number;
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
printf("[TRUNK]: New final SQL id:[%d]", number );
//if(NewSQL_ID ==0 )
break; // find emty slot vehicle ID. with find number primary car player
}*/
}
}
}
cache_delete(result);
NewSQL_ID = GetFreeTrunkID(carid, slot)+1; printf("[TRUNK ID]: New final SQL id:[%d]", NewSQL_ID );
format(str, sizeof(str), "{FFBBBB}DEBUG: NewSQL_ID: [%i]", NewSQL_ID); SCM(playerid, 0xFFCCCCFF, str);
if(NewSQL_ID==0)return SCM(playerid, -1, "{FFBBBB}SQL: {FFFFFF}System new ID SQL was failed sir");
if(NewSQL_ID>=0)printf("{FFBBBB}DEBUG: New id SQL trunk has been found",VID,GetRPName(playerid));
slot, get_vehicle_trunk[carid][slot][TRUNK_ITEM_TYPE] = item_type, get_vehicle_trunk[carid][slot][TRUNK_ITEM_AMOUNT] = amount, get_vehicle_trunk[carid][slot][TRUNK_ITEM_VALUE] = value;
//get_vehicle_trunk[carid][slot][TRUNK_SQL_ID]=get_vehicle_trunk[carid][slot][TRUNK_SQL_ID]+1;
if(get_vehicle_trunk[carid][slot][TRUNK_SQL_ID] == NewSQL_ID)
{
format(str, sizeof(str), "UPDATE `trunkdata` SET `oc_id`='%d',`slot`='%d',`item_type`='%d',`amount`='%d',`value`='%d',`owner_id`='%d' WHERE `id`='%d'", VID, slot, item_type, amount, value, pInfo[playerid][ID], NewSQL_ID);
n_mysql_query(g_Sql, str);
get_vehicle_trunk[carid][slot][TRUNK_SQL_ID] = NewSQL_ID;
}
else
{
format(str, sizeof(str), "INSERT INTO `trunkdata` (`id`, `owner_id`, `oc_id`, `slot`, `item_type`, `amount`, `value`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d')", NewSQL_ID, pInfo[playerid][ID], VID, slot, item_type, amount, value);
n_mysql_query(g_Sql, str);
SetSVarInt("SlotTrunkUsed", NewSQL_ID);
}
SCM(playerid,-1,"VEHICLE: You have adding item at this trunk vehicle",2);
SendClientMessage(playerid,-1, str);
Code:
if(sscanf( inputtext, "iiiii", targetOC_ID, slot, item_type, amount, value)) return SCM(playerid, -1, "USAGE: [targetOC_ID] [slot] [item_type] [amount] [value]");
new playa,carid=GetRealIdCar(targetOC_ID);
SetPVarInt(playerid, "SelectedSlot", slot);
printf("DEBUG: Checking VID changer from vehicle ID:[%d]", carid);
if(slot >= MAX_TRUNK_SLOTS || slot <= 0) return SCM(playerid, -1, "VEHICLE: Max trunk slot is 3 sir.",1);
printf("DEBUG: Adding item trunk in slot:[%d]", slot);
LoadOCTrunks(playerid, carid);
if(get_vehicle_trunk[carid][slot][TRUNK_SLOT]==slot) return SCM(playerid, -1, "OC_TRUNK: That slot has been used in this vehicle sir. Please remove item from this slot first.",1);
/*
for(new s=1; s<=10; s++)
{
if(get_vehicle_trunk[carid][s][TRUNK_SQL_ID]>0)continue;
if(get_vehicle_trunk[carid][s][TRUNK_SQL_ID]==slot)
{
break;
}
}
*/
if(!IsValidVehicle(carid))return SCM(playerid, -1, "VEHICLE: Thats vehicle has not exist sir.",1);
printf("DEBUG: Slot filter hassben passed sir");
new VID = targetOC_ID;
new result = n_mysql_query(g_Sql, "SELECT * FROM `trunkdata`", true); //ORDER BY oc_id ASC, slot ASC
new rows = cache_num_rows();
new number=get_vehicle_trunk[carid][slot][TRUNK_SQL_ID];
for(new v; v<=MAX_VEHICLES; v++)
{
for(new slot; slot<=MAX_TRUNK_SLOTS; slot++)
{
for(new idx; idx <= rows; idx ++)
{
cache_get_value_int(idx, "id", get_vehicle_trunk[v][slot][TRUNK_SQL_ID] );
if(get_vehicle_trunk[v][slot][TRUNK_SQL_ID]>0)continue;
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
number++;
printf("[TRUNK]: New id:[%d]", number );
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
{
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
NewSQL_ID = number;
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
NewSQL_ID = number;
number++;
if(number != get_vehicle_trunk[v][slot][TRUNK_SQL_ID])
printf("[TRUNK]: New final SQL id:[%d]", number );
//if(NewSQL_ID ==0 )
break; // find emty slot vehicle ID. with find number primary car player
} }
}
}
Code:
GetFreeTrunkID(v, s) {
new i=1;
for(i; i <= 100; i++)
{
//i++;
if(get_vehicle_trunk[v][s][i] == 0)
if(i != 0)
{
i++;
if(get_vehicle_trunk[v][s][i] == 0)
i+s;
return i+GetSVarInt("SlotTrunkUsed");
}
}
return i+GetSVarInt("SlotTrunkUsed");
printf("[TRUNK_ID]: Debug new ID SQL:[%d]", v);
}