Add load item types & item cmds

This commit is contained in:
Vortrex
2021-01-08 18:30:11 -06:00
parent 882fc3893b
commit d9aee52499

View File

@@ -22,7 +22,7 @@ function loadItemsFromDatabase() {
if(dbQuery) {
if(dbQuery.numRows > 0) {
while(dbFetchAssoc = fetchQueryAssoc(dbQuery)) {
let tempItemData = getClasses().itemData(dbFetchAssoc);
let tempItemData = new serverClasses.itemData(dbFetchAssoc);
tempItems.push(tempItemData);
}
}
@@ -30,7 +30,105 @@ function loadItemsFromDatabase() {
}
disconnectFromDatabase(dbConnection);
}
return tempItems;
}
// ---------------------------------------------------------------------------
function loadItemTypesFromDatabase() {
let tempItemTypes = [];
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQuery = queryDatabase(dbConnection, `SELECT * FROM item_type WHERE item_type_enabled = 1 AND item_type_server = ${getServerId()}`);
if(dbQuery) {
if(getQueryNumRows(dbQuery) > 0) {
while(dbFetchAssoc = fetchQueryAssoc(dbQuery)) {
let tempItemTypeData = new serverClasses.itemTypeData(dbFetchAssoc);
tempItemTypes.push(tempItemTypeData);
}
}
freeDatabaseQuery(dbQuery);
}
disconnectFromDatabase(dbConnection);
}
return tempItemTypes;
}
// ---------------------------------------------------------------------------
function dropItemCommand(command, params, client) {
}
// ---------------------------------------------------------------------------
function useItemCommand(command, params, client) {
}
// ---------------------------------------------------------------------------
function pickupItemCommand(command, params, client) {
let itemId = getClosestItemOnGround(getPlayerPosition(client));
if(!getItemData(itemId)) {
messagePlayerError(client, `The item you're trying to pick up is bugged. Please contact an admin.`);
return false;
}
if(!getItemTypeData(getItemData(itemId).type)) {
messagePlayerError(client, `The item you're trying to pick up is bugged. Please contact an admin.`);
return false;
}
if(getDistance(getPlayerPosition(client), getItemData(itemId).position) > getGlobalConfig().droppedItemPickupRange) {
messagePlayerError(client, `You're too far away!`);
return false;
}
playerPickupItem(client, itemId);
}
// ---------------------------------------------------------------------------
function dropItemCommand(command, params, client) {
let itemId = getClosestItemOnGround(getPlayerPosition(client));
if(!getItemData(itemId)) {
messagePlayerError(client, `The item you're trying to pick up is bugged. Please contact an admin.`);
return false;
}
if(!getItemTypeData(getItemData(itemId).type)) {
messagePlayerError(client, `The item you're trying to pick up is bugged. Please contact an admin.`);
return false;
}
if(getDistance(getPlayerPosition(client), getItemData(itemId).position) > getGlobalConfig().droppedItemPickupRange) {
messagePlayerError(client, `You're too far away!`);
return false;
}
playerDropItem(client, itemId);
}
// ---------------------------------------------------------------------------
function playerUseItem(client, itemIndex) {
}
// ---------------------------------------------------------------------------
function playerDropItem(client, itemIndex) {
}
// ---------------------------------------------------------------------------
function playerPickupItem(client, itemIndex) {
}
// ---------------------------------------------------------------------------