Finish interaction on items
This commit is contained in:
@@ -107,16 +107,10 @@ mp.events.add("removeItem", (userItemId, amount) => {
|
||||
arrIndex = i;
|
||||
}
|
||||
}
|
||||
if (amount === "stack") {
|
||||
items[arrIndex][4] = "-1";
|
||||
inventoryWeight -= parseInt(items[arrIndex][2]) * parseInt(items[arrIndex][3]);
|
||||
inventoryWeight -= parseInt(items[arrIndex][2]) * parseInt(items[arrIndex][3]);
|
||||
items[arrIndex][3] -= amount;
|
||||
if (items[arrIndex][3] === 0) {
|
||||
items.splice(arrIndex, 1);
|
||||
} else if (amount === "one") {
|
||||
items[arrIndex][3]--;
|
||||
inventoryWeight -= items[arrIndex][2];
|
||||
if (items[arrIndex][3] === 0) {
|
||||
items.splice(arrIndex, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -479,7 +473,7 @@ function ifMouseSelectRadial(cX2, cY2) {
|
||||
// radialSelect = "right";
|
||||
// rightRColor = 255;
|
||||
// return true;
|
||||
//} else {
|
||||
else {
|
||||
upRColor = 222;
|
||||
downRColor = 222;
|
||||
leftRColor = 222;
|
||||
@@ -496,7 +490,7 @@ mp.events.add('click', (x, y, upOrDown, leftOrRight, relativeX, relativeY, world
|
||||
if (show) {
|
||||
//LINKE MAUSTASTE
|
||||
//RUNTER
|
||||
if (upOrDown === "down" && leftOrRight === "left" && mouseLDown === false && mouseRDown === false && itemRadial === false) {
|
||||
if (upOrDown === "down" && leftOrRight === "left" && mouseLDown === false && mouseRDown === false) {
|
||||
|
||||
mouseLDown = true;
|
||||
|
||||
@@ -504,26 +498,24 @@ mp.events.add('click', (x, y, upOrDown, leftOrRight, relativeX, relativeY, world
|
||||
dragItem = hoverItem;
|
||||
oldDragSlot = items[dragItem][4];
|
||||
items[dragItem][4] = "-1";
|
||||
} else if (ifMouseSelectRadial(x, y) && dragItem === null) {
|
||||
} else if (ifMouseSelectRadial(x, y)) {
|
||||
switch (radialSelect) {
|
||||
case "up":
|
||||
var dropInput = new InputHelper("Wie viel Items möchtest du wegwerfen?");
|
||||
dropInput.show();
|
||||
dropInput.getValue((data) => {
|
||||
var amount = parseInt(data);
|
||||
if (isNaN(amount)) {
|
||||
mp.game.graphics.notify('~r~Du musst eine Nummer eingeben!');
|
||||
if (isNaN(amount) || amount < 1) {
|
||||
mp.game.graphics.notify('~r~Du musst eine Zahl größer als 0 eingeben!');
|
||||
return;
|
||||
}
|
||||
mp.events.callRemote('itemInteract', "drop", items[clickedItem][5], amount);
|
||||
items[clickedItem][3] -= amount;
|
||||
});
|
||||
|
||||
itemRadial = false;
|
||||
break;
|
||||
case "down":
|
||||
mp.events.callRemote('itemInteract', "use", items[clickedItem][5], 1);
|
||||
items[clickedItem][3]--;
|
||||
itemRadial = false;
|
||||
break;
|
||||
case "left":
|
||||
|
||||
@@ -223,12 +223,61 @@ namespace reallife_gamemode.Server.Managers
|
||||
[RemoteEvent("itemInteract")]
|
||||
public void ItemInteract(Client player, string type, string itemId, int amount)
|
||||
{
|
||||
switch (type)
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
case "use":
|
||||
break;
|
||||
case "drop":
|
||||
break;
|
||||
UserItem fItem = context.UserItems.FirstOrDefault(j => j.Id == int.Parse(itemId));
|
||||
IItem iItem = InventoryManager.GetItemById(fItem.ItemId);
|
||||
|
||||
List<UserItem> itemList = player.GetUser().GetItems();
|
||||
UserItem userItem = itemList.FirstOrDefault(i => i.ItemId == iItem.Id);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "use":
|
||||
if (iItem == null)
|
||||
{
|
||||
player.SendChatMessage("Dieses Essen existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (userItem == null)
|
||||
{
|
||||
player.SendChatMessage("Du hast dieses Item nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
if (iItem is IUsableItem usableItemObj)
|
||||
{
|
||||
usableItemObj.Use(userItem, player);
|
||||
player.TriggerEvent("removeItem", itemId, amount);
|
||||
fItem.Amount -= amount;
|
||||
}
|
||||
break;
|
||||
case "drop":
|
||||
|
||||
if (iItem == null)
|
||||
{
|
||||
player.SendChatMessage("Dieses Item existiert nicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (userItem == null)
|
||||
{
|
||||
player.SendChatMessage("Du hast dieses Item nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
if (iItem is IUsableItem usableItemObj2)
|
||||
{
|
||||
fItem.Amount -= amount;
|
||||
usableItemObj2.Use(userItem, player);
|
||||
NAPI.Object.CreateObject(1017479830, new Vector3(player.Position.X, player.Position.Y, player.Position.Z), new Vector3(0, 0, 0), 0);
|
||||
NAPI.TextLabel.CreateTextLabel(iItem.Name + " ~s~(~y~" + amount + "~s~)", new Vector3(player.Position.X, player.Position.Y, player.Position.Z), 5, 0.5f, 4, new Color(255, 255, 255), false, 0);
|
||||
player.TriggerEvent("removeItem", itemId, amount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user