Ragemp-roleplay-skript/Items.cs
2019-04-16 13:59:07 +02:00

906 lines
38 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrandTheftMultiplayer.Server;
using GrandTheftMultiplayer.Shared;
using GrandTheftMultiplayer.Server.API;
using GrandTheftMultiplayer.Shared.Math;
using GrandTheftMultiplayer.Server.Elements;
using GrandTheftMultiplayer.Server.Constant;
using GrandTheftMultiplayer.Server.Managers;
using System.IO;
using System.Xml.Linq;
using System.Xml;
namespace Roleplay.Environment
{
[Flags]
public enum AnimationFlags
{
Loop = 1 << 0,
StopOnLastFrame = 1 << 1,
OnlyAnimateUpperBody = 1 << 4,
AllowPlayerControl = 1 << 5,
Cancellable = 1 << 7
}
class Items : Script
{
public Items()
{
API.onResourceStart += onStart;
API.onClientEventTrigger += clientEvent;
API.onEntityEnterColShape += colShapeEvent;
API.onClientEventTrigger += ScriptEvent;
API.onEntityEnterColShape += onWeaponPackage;
}
public List<KeyValuePair<string, string>> AnimationList = new List<KeyValuePair<string, string>>()
{
{new KeyValuePair<string,string>("sitdowntofloor", "amb@world_human_picnic@male@base base")},
{new KeyValuePair<string,string>("finger", "mp_player_intfinger mp_player_int_finger")},
{new KeyValuePair<string,string>("guitar", "anim@mp_player_intcelebrationmale@air_guitar air_guitar")},
{new KeyValuePair<string,string>("shagging", "anim@mp_player_intcelebrationmale@air_shagging air_shagging")},
{new KeyValuePair<string,string>("synth", "anim@mp_player_intcelebrationmale@air_synth air_synth")},
{new KeyValuePair<string,string>("kiss", "anim@mp_player_intcelebrationmale@blow_kiss blow_kiss")},
{new KeyValuePair<string,string>("bro", "anim@mp_player_intcelebrationmale@bro_love bro_love")},
{new KeyValuePair<string,string>("chicken", "anim@mp_player_intcelebrationmale@chicken_taunt chicken_taunt")},
{new KeyValuePair<string,string>("chin", "anim@mp_player_intcelebrationmale@chin_brush chin_brush")},
{new KeyValuePair<string,string>("dj", "anim@mp_player_intcelebrationmale@dj dj")},
{new KeyValuePair<string,string>("dock", "anim@mp_player_intcelebrationmale@dock dock")},
{new KeyValuePair<string,string>("facepalm", "anim@mp_player_intcelebrationmale@face_palm face_palm")},
{new KeyValuePair<string,string>("fingerkiss", "anim@mp_player_intcelebrationmale@finger_kiss finger_kiss")},
{new KeyValuePair<string,string>("freakout", "anim@mp_player_intcelebrationmale@freakout freakout")},
{new KeyValuePair<string,string>("jazzhands", "anim@mp_player_intcelebrationmale@jazz_hands jazz_hands")},
{new KeyValuePair<string,string>("knuckle", "anim@mp_player_intcelebrationmale@knuckle_crunch knuckle_crunch")},
{new KeyValuePair<string,string>("nose", "anim@mp_player_intcelebrationmale@nose_pick nose_pick")},
{new KeyValuePair<string,string>("no", "anim@mp_player_intcelebrationmale@no_way no_way")},
{new KeyValuePair<string,string>("peace", "anim@mp_player_intcelebrationmale@peace peace")},
{new KeyValuePair<string,string>("photo", "anim@mp_player_intcelebrationmale@photography photography")},
{new KeyValuePair<string,string>("rock", "anim@mp_player_intcelebrationmale@rock rock")},
{new KeyValuePair<string,string>("salute", "anim@mp_player_intcelebrationmale@salute salute")},
{new KeyValuePair<string,string>("shush", "anim@mp_player_intcelebrationmale@shush shush")},
{new KeyValuePair<string,string>("slowclap", "anim@mp_player_intcelebrationmale@slow_clap slow_clap")},
{new KeyValuePair<string,string>("surrender", "anim@mp_player_intcelebrationmale@surrender surrender")},
{new KeyValuePair<string,string>("thumbs", "anim@mp_player_intcelebrationmale@thumbs_up thumbs_up")},
{new KeyValuePair<string,string>("taunt", "anim@mp_player_intcelebrationmale@thumb_on_ears thumb_on_ears")},
{new KeyValuePair<string,string>("vsign", "anim@mp_player_intcelebrationmale@v_sign v_sign")},
{new KeyValuePair<string,string>("wank", "anim@mp_player_intcelebrationmale@wank wank")},
{new KeyValuePair<string,string>("wave", "anim@mp_player_intcelebrationmale@wave wave")},
{new KeyValuePair<string,string>("loco", "anim@mp_player_intcelebrationmale@you_loco you_loco")},
{new KeyValuePair<string,string>("handsup", "missminuteman_1ig_2 handsup_base")},
};
public const int CHAR_ROOT = 15;
public const int CHAR_PAY = 16;
public const int CHAR_MESSENGER = 17;
public const int CHAR_ANIM = 20;
public void ScriptEvent(Client sender, string eventName, object[] args)
{
if (eventName == "InventoryKeyPressed")
{
if (API.getEntityData(sender, "loggedin") == true)
{
object[] argumentList = new object[16];
argumentList[0] = CHAR_ROOT;
argumentList[1] = sender.name;
argumentList[2] = "Optionen";
argumentList[3] = false;
argumentList[4] = 3;
argumentList[5] = "Inventar";
argumentList[6] = "Geld geben";
argumentList[7] = "Animationen";
for (var i = 0; i < 3; i++)
{
argumentList[8 + i] = "";
}
API.triggerClientEvent(sender, "menu_handler_create_menu", argumentList);
}
}
else if (eventName == "menu_handler_select_item")
{
var callbackId = (int)args[0];
var index = (int)args[1];
if (callbackId == CHAR_ROOT)
{
if (index == 0)
{
Items.InventoryHolder ih = API.getEntityData(sender, "InventoryHolder");
var itemsLen = ih.Inventory.Count;
object[] argumentList = new object[5 + itemsLen * 2];
argumentList[0] = 1;
argumentList[1] = "Inventar";
argumentList[2] = "Items:";
argumentList[3] = false;
argumentList[4] = itemsLen;
var i = 0;
foreach (Items.InventoryItem item in ih.Inventory)
{
argumentList[5 + i] = item.Details.Name;
argumentList[5 + itemsLen + i] = "Anzahl: " + item.Quantity;
i++;
}
API.triggerClientEvent(sender, "menu_handler_create_menu3", argumentList);
}
else if (index == 1)
{
var peopleNearby = API.getPlayersInRadiusOfPlayer(4, sender);
peopleNearby.Remove(sender);
API.setEntityData(sender, "NearbyList", peopleNearby);
var count = peopleNearby.Count;
object[] argumentList = new object[5 + count + count];
argumentList[0] = 276215765;
argumentList[1] = "Geld geben";
argumentList[2] = "Spieler in der naehe:";
argumentList[3] = false;
argumentList[4] = count;
var i = 0;
foreach (Client c in peopleNearby)
{
argumentList[5 + i] = c.name;
argumentList[5 + count + i] = "";
i++;
}
API.triggerClientEvent(sender, "menu_handler_create_menu", argumentList);
}
else if (index == 2)
{
var itemsLen = AnimationList.Count;
object[] argumentList = new object[5 + itemsLen * 2];
argumentList[0] = CHAR_ANIM;
argumentList[1] = "Animationen";
argumentList[2] = "Waehle eine Animation aus";
argumentList[3] = false;
argumentList[4] = itemsLen;
var i = 0;
foreach (KeyValuePair<string, string> anim in AnimationList)
{
argumentList[5 + i] = anim.Key;
argumentList[5 + itemsLen + i] = "";
i++;
}
API.triggerClientEvent(sender, "menu_handler_create_menu", argumentList);
}
}
else if (callbackId == CHAR_ANIM)
{
API.playPlayerAnimation(sender, (int) AnimationFlags.Loop | (int) AnimationFlags.Cancellable, AnimationList[index].Value.Split()[0], AnimationList[index].Value.Split()[1]);
API.sendChatMessageToPlayer(sender,"Um die Animation zu beenden /stopanim oder /as");
}
else if(callbackId == 276215765)
{
API.triggerClientEvent(sender, "get_user_input", 48864, "Menge", 500, index);
}
} else if(eventName == "menu_handler_user_input")
{
int callback = (int) args[0];
if (callback == 48864)
{
string text = (string)args[1];
int wert;
bool isint = int.TryParse(text, out wert);
int index = (int)args[2];
if (isint == true)
{
if (wert > 0)
{
if (Environment.MONEY.Money.hasBarMoney(sender, wert) == true)
{
var nearbylist = API.getEntityData(sender, "NearbyList");
var reciever = nearbylist[index];
Environment.MONEY.Money.giveBarMoney(sender, -wert, API);
Environment.MONEY.Money.giveBarMoney(reciever, +wert, API);
TextLabel txt = API.createTextLabel(sender.name + " gibt $" + wert + " zu " + reciever.name, sender.position.Add(new Vector3(0, 0, 1)), 20, 0.7f, true, 0);
API.setTextLabelColor(txt, 0, 0, 255, 255);
API.consoleOutput("Spieler: " + sender.name + " gibt " + wert + "$ zu " + reciever.name);
API.attachEntityToEntity(txt, sender, "IK_HEAD", new Vector3(0, 0, 0.4), new Vector3(0, 0, 0));
API.delay(5000, true, () => { API.deleteEntity(txt); });
}
}
else
{
API.sendNotificationToPlayer(sender, "Der Wert darf nicht negativ sein!");
}
} else
{
API.sendNotificationToPlayer(sender, "Du musst eine gültige Zahl angeben!");
}
}
}
}
[Command("stopanim", Alias = "as")]
public void stopanim(Client player){
if(player.isAiming == false && player.isInCover == false && player.isInVehicle == false && player.isShooting == false){
API.stopPlayerAnimation(player);
}
}
//** Items
public const int ITEM_ID_SPRUNK = 1;
public const int ITEM_ID_ECOLA = 2;
public const int ITEM_ID_EWATER = 3;
public const int ITEM_ID_WEED = 4;
public const int ITEM_ID_WEED28 = 5;
public const int ITEM_ID_REPAIRKIT = 6;
public const int ITEM_ID_BANDAGE = 7;
public const int ITEM_ID_BANDAGE_PACKET = 8;
public const int ITEM_ID_KANISTER = 9;
public const int ITEM_ID_PIßWASSER = 10;
public const int ITEM_ID_PIßWASSER_PACK = 11;
public const int ITEM_ID_WEED_SAMEN = 12;
public const int ITEM_ID_HAMBURGER = 13;
public const int ITEM_ID_HOTDOG = 14;
public const int ITEM_ID_PIZZA = 15;
//**
public static List<Item> items = new List<Item>();
public const string INVENTORY_FOLDER = "wildland_inventories";
public void PopulateItems()
{
items.Add(new Drink(ITEM_ID_SPRUNK, "Sprunk", "Vielleicht Radioaktiv?", +7));
items.Add(new Drink(ITEM_ID_ECOLA, "E-Cola", "Achtung: Appetitlich ansteckend!", +10));
items.Add(new Drink(ITEM_ID_EWATER, "Flasche Wasser", "Gesundes Wasser", +5));
items.Add(new Alkohol(ITEM_ID_PIßWASSER, "Pißwasser", "Pißwasser", 0, 10));
items.Add(new Multipack(ITEM_ID_PIßWASSER_PACK, "Pißwasser Sixpack", "Pißwasser 6er Packet", 6, ITEM_ID_PIßWASSER));
items.Add(new Drug(ITEM_ID_WEED, "Joint", "La Bomba", 20, 30));
items.Add(new Multipack(ITEM_ID_WEED28, "Cannabis Paket", "10 Gramm La Bomba's", 30, ITEM_ID_WEED));
items.Add(new RepairKit(ITEM_ID_REPAIRKIT, "Fahrzeug Repair-kit", "Kann Fahrzeuge reparieren"));
items.Add(new Medic(ITEM_ID_BANDAGE, "Pflaster", "Kann dich heilen",20));
items.Add(new Multipack(ITEM_ID_BANDAGE_PACKET, "Pflaster Paket", "5 Stueck", 5, ITEM_ID_BANDAGE));
items.Add(new Kanister(ITEM_ID_KANISTER, "Treibstoff Kanister", "Fuellt dein Fahrzeug um 20% auf!"));
items.Add(new WeedSamen(ITEM_ID_WEED_SAMEN, "Cannabis Samen", "Hiermit kannst du Cannabis anpflanzen!"));
items.Add(new Food(ITEM_ID_HAMBURGER, "Hamburger","Ganzschön fettich",15));
items.Add(new Food(ITEM_ID_HOTDOG, "Hotdog", "Heisses Huendchen",10));
items.Add(new Food(ITEM_ID_PIZZA, "Pizza", "Pizza izz da",25));
}
public class Item
{
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Item(int id, string name, string description)
{
ID = id;
Name = name;
Description = description;
}
public virtual void use(Client c)
{
}
}
public class Drink : Item
{
private int Healthmodifier;
public Drink(int id, string name, string description, int healthmodifier) : base(id, name, description)
{
}
public override void use(Client c)
{
if(c.isInVehicle != true){
API.shared.playPlayerScenario(c,"WORLD_HUMAN_DRINKING");
API.shared.sleep(1000*5);
API.shared.setPlayerHealth(c, API.shared.getPlayerHealth(c) + Healthmodifier);
Environment.EssenTrinken.EssenTrinken.addTrinken(c,25);
API.shared.stopPlayerAnimation(c);
} else {
Environment.EssenTrinken.EssenTrinken.addTrinken(c,25);
API.shared.setPlayerHealth(c, API.shared.getPlayerHealth(c) + Healthmodifier);
}
}
}
public class Drug : Item
{
public int AmountToHeal { get; set; }
public int Armor { get; set; }
public Drug(int id, string name, string description, int amountToHeal, int armor) : base(id, name, description)
{
AmountToHeal = amountToHeal;
Armor = armor;
}
public override void use(Client c)
{
//API.shared.playPlayerScenario(c, "WORLD_HUMAN_SMOKING_POT");
//API.shared.delay(1000 * 5, true, () => {
// API.shared.stopPlayerAnimation(c);
//});
API.shared.playPlayerScenario(c,"WORLD_HUMAN_SMOKING_POT");
API.shared.sleep(1000*5);
API.shared.setPlayerHealth(c, API.shared.getPlayerHealth(c) + AmountToHeal);
API.shared.setPlayerArmor(c, API.shared.getPlayerArmor(c) + Armor);
ClientAPI.playScreenEffect(c, "DrugsMichaelAliensFight", 10000*15, false);
API.shared.stopPlayerAnimation(c);
}
}
public class Alkohol : Item
{
public int AmountToHeal { get; set; }
public int Armor { get; set; }
public Alkohol(int id, string name, string description, int amountToHeal, int armor) : base(id, name, description)
{
AmountToHeal = amountToHeal;
Armor = armor;
}
public override void use(Client c)
{
//API.shared.playPlayerScenario(c, "WORLD_HUMAN_DRINKING");
//API.shared.delay(1000 * 5, true, () => {
// API.shared.stopPlayerAnimation(c);
//});
API.shared.playPlayerScenario(c,"WORLD_HUMAN_DRINKING");
API.shared.sleep(1000*5);
API.shared.setPlayerHealth(c, API.shared.getPlayerHealth(c) + AmountToHeal);
API.shared.setPlayerArmor(c, API.shared.getPlayerArmor(c) + Armor);
ClientAPI.playScreenEffect(c, "ChopVision", 50000*3, false);
Environment.EssenTrinken.EssenTrinken.addTrinken(c,15);
API.shared.stopPlayerAnimation(c);
}
}
public class RepairKit : Item
{
public RepairKit(int id, string name, string description) : base(id, name, description)
{
}
public override void use(Client c)
{
if(c.isInVehicle == true)
{
c.vehicle.repair();
API.shared.sendNotificationToPlayer(c, "Fahrzeug repariert!");
}
else
{
InventoryHolder invh = API.shared.getEntityData(c,"InventoryHolder");
invh.AddItemToInventory(ItemByID(ITEM_ID_REPAIRKIT));
API.shared.sendNotificationToPlayer(c, "Du kannst dies nur in einem Fahrzeug benutzen!");
}
}
}
public class Food : Item
{
public float AmountToAddToFood { get; set; }
public Food(int id, string name, string description, float amounttoaddtofood) : base(id, name, description)
{
AmountToAddToFood = amounttoaddtofood;
}
public override void use(Client c)
{
Environment.EssenTrinken.EssenTrinken.addEssen(c,AmountToAddToFood);
API.shared.sendNotificationToPlayer(c,"Du hast etwas gegessen!");
}
}
public class Medic : Item
{
public int AmountToHeal { get; set; }
public Medic(int id, string name, string description, int amountToHeal) : base(id, name, description)
{
AmountToHeal = amountToHeal;
}
public override void use(Client c)
{
API.shared.setPlayerHealth(c, API.shared.getPlayerHealth(c) + AmountToHeal);
API.shared.sendNotificationToPlayer(c, "Du hast dich geheilt!");
}
}
public class Kanister : Item
{
public Kanister(int id, string name, string description) : base(id, name, description)
{
}
public override void use(Client c)
{
if (c.isInVehicle == true)
{
if (API.shared.hasEntitySyncedData(c.vehicle, "tank") == true)
{
API.shared.setEntitySyncedData(c.vehicle, "tank", API.shared.getEntitySyncedData(c.vehicle, "tank") + 20);
API.shared.sendNotificationToPlayer(c, "Fahrzeug Tank um 20% aufgefuellt!");
}
}
else
{
API.shared.sendNotificationToPlayer(c, "Du kannst dies nur in einem Fahrzeug benutzen!");
}
}
}
public class WeedSamen : Item
{
public WeedSamen(int id, string name, string description) : base(id, name, description)
{
}
public override void use(Client c)
{
Environment.Weedplantage.plantWeed(c);
}
}
public class Multipack : Item
{
public int Multiple { get; set; }
public int MId { get; set; }
public Multipack(int id, string name, string description, int multiple, int mid) : base(id, name, description)
{
Multiple = multiple;
MId = mid;
}
public override void use(Client c)
{
InventoryHolder ih = API.shared.getEntityData(c, "InventoryHolder");
for (var i = 0; i < Multiple; i++)
{
ih.AddItemToInventory(ItemByID(MId));
}
}
}
public void onStart()
{
PopulateItems();
}
public void clientEvent(Client sender, string eventName, object[] args)
{
if (eventName == "menu_handler_select_item")
{
var callbackId = (int)args[0];
var index = (int)args[1];
if (callbackId == 1)
{
InventoryHolder ih = API.getEntityData(sender, "InventoryHolder");
var item = ih.Inventory[index];
API.setEntityData(sender, "LastSelectedItem", item);
object[] argumentList = new object[15];
argumentList[0] = 2;
argumentList[1] = "Details";
argumentList[2] = item.Details.Name;
argumentList[3] = false;
argumentList[4] = 4;
argumentList[5] = "Benutzen";
argumentList[6] = "Beschreibung";
argumentList[7] = "Spieler geben";
argumentList[8] = "Zeigen";
for (var i = 0; i < 4; i++)
{
argumentList[9 + i] = "";
}
API.triggerClientEvent(sender, "menu_handler_create_menu", argumentList);
}
else if (callbackId == 2)
{
var item = API.getEntityData(sender, "LastSelectedItem");
if (index == 0)
{
item.Details.use(sender);
InventoryHolder ih = API.getEntityData(sender, "InventoryHolder");
ih.RemoveItemFromInventory(item.Details);
API.resetEntityData(sender, "LastSelectedItem");
}
if (index == 1)
{
object[] ar = new object[2];
ar[0] = item.Details.Description;
ar[1] = 2000;
API.triggerClientEvent(sender, "display_subtitle", ar);
}
else if (index == 2)
{
var peopleNearby = API.getPlayersInRadiusOfPlayer(4, sender);
peopleNearby.Remove(sender);
API.setEntityData(sender, "NearbyList", peopleNearby);
var count = peopleNearby.Count;
object[] argumentList = new object[5 + count + count];
argumentList[0] = 3;
argumentList[1] = "Spieler geben";
argumentList[2] = "Spieler in der naehe:";
argumentList[3] = false;
argumentList[4] = count;
var i = 0;
foreach (Client c in peopleNearby)
{
argumentList[5 + i] = c.name;
argumentList[5 + count + i] = "";
i++;
}
API.triggerClientEvent(sender, "menu_handler_create_menu", argumentList);
}
else if (index == 3)
{
TextLabel txt = API.createTextLabel(sender.name + " zeigt sein " + item.Details.Name, sender.position.Add(new Vector3(0,0,1)), 20, 0.7f,true,0);
API.setTextLabelColor(txt, 0, 0, 255, 255);
API.attachEntityToEntity(txt, sender, "IK_HEAD", new Vector3(0, 0, 0.4), new Vector3(0, 0, 0));
API.delay(5000, true, () => { API.deleteEntity(txt); });
}
}
else if (callbackId == 3)
{
var item = API.getEntityData(sender, "LastSelectedItem");
var nearbylist = API.getEntityData(sender, "NearbyList");
var reciever = nearbylist[index];
InventoryHolder senderinventory = API.getEntityData(sender, "InventoryHolder");
InventoryHolder recieverinventory = API.getEntityData(reciever, "InventoryHolder");
senderinventory.RemoveItemFromInventory(item.Details);
recieverinventory.AddItemToInventory(item.Details);
API.resetEntityData(sender, "LastSelectedItem");
API.resetEntityData(sender, "LastNearbyList");
TextLabel txt = API.createTextLabel(sender.name + " gibt " + item.Details.Name + " zu " + reciever.name, sender.position.Add(new Vector3(0, 0, 1)), 20, 0.7f, true, 0);
API.setTextLabelColor(txt, 0, 0, 255, 255);
API.attachEntityToEntity(txt, sender, "IK_HEAD", new Vector3(0, 0, 0.4), new Vector3(0, 0, 0));
API.delay(5000, true, () => { API.deleteEntity(txt); });
}
else if (callbackId == 4)
{
ItemSelected(sender, index);
}
else if (callbackId == 5)
{
UniqueItemSelected(sender, index);
}
}
}
public void ItemSelected(Client sender, int index)
{
var Products = API.getEntityData(sender, "ProductsOfUsingShop");
var item = ItemByID(Products[index].Key);
var price = Products[index].Value;
API.resetEntityData(sender, "ProductsOfUsingShop");
//Money.TakeMoney(sender, price)
if (Environment.MONEY.Money.hasBarMoney(sender,price) == true)
{
InventoryHolder ih = API.shared.getEntityData(sender, "InventoryHolder");
Environment.MONEY.Money.giveBarMoney(sender, -price, API);
ih.AddItemToInventory(item);
API.shared.triggerClientEvent(sender, "display_subtitle", "Item added to Inventory, press F1 to view", 3000);
}
else
{
API.shared.triggerClientEvent(sender, "display_subtitle", "Sorry, you don't have enough money", 3000);
}
}
public void UniqueItemSelected(Client sender, int index)
{
API.shared.triggerClientEvent(sender, "hideInfobox");
var Products = API.getEntityData(sender, "ProductsOfUsingShop");
var item = ItemByID(Products[index].Key);
var price = Products[index].Value;
API.resetEntityData(sender, "ProductsOfUsingShop");
InventoryHolder ih = API.shared.getEntityData(sender, "InventoryHolder");
if (!ih.Inventory.Exists(ii => ii.Details.ID == item.ID))
{
if (Environment.MONEY.Money.hasBarMoney(sender, price) == true)
{
Environment.MONEY.Money.giveBarMoney(sender, -price, API);
ih.AddItemToInventory(item);
API.shared.triggerClientEvent(sender, "display_subtitle", "Item added to Inventory, press F1 to view", 3000);
}
else
{
API.shared.triggerClientEvent(sender, "display_subtitle", "Sorry, you don't have enough money", 3000);
}
return;
}
API.shared.triggerClientEvent(sender, "display_subtitle", "You already have one.", 3000);
}
public void colShapeEvent(ColShape shape, NetHandle entity)
{
var player = API.getPlayerFromHandle(entity);
if (player == null) return;
if (shape.hasData("Shop"))
{
var ShopObject = shape.getData("Shop");
{
ShopObject.Show(player);
}
}
}
public static Item ItemByID(int id)
{
foreach (Item item in items)
{
if (item.ID == id)
{
return item;
}
}
return null;
}
public static void load(Client player)
{
var path = Path.Combine(INVENTORY_FOLDER, player.socialClubName);
if (!File.Exists(path))
{
InventoryHolder ih = new InventoryHolder();
ih.Owner = player.handle;
API.shared.setEntityData(player, "InventoryHolder", ih);
API.shared.sendNotificationToPlayer(player, "Du hast ein leeres Inventar!");
}
else
{
InventoryHolder ih = new InventoryHolder();
ih.Owner = player.handle;
ih.InventoryFromXML(path);
API.shared.setEntityData(player, "InventoryHolder", ih);
}
}
public static void saveVih(NetHandle V)
{
InventoryHolder ih = API.shared.getEntityData(V, "InventoryHolder");
if (ih == null)
{
API.shared.consoleOutput("ih is null");
return;
}
ih.VehicleInventoryToXML(V);
}
public static void loadVih(NetHandle V)
{
var path = Path.Combine(INVENTORY_FOLDER, API.shared.getEntityData(V, "OwnedVehicleID").ToString());
if (!File.Exists(path))
{
InventoryHolder ih = new InventoryHolder();
ih.Owner = V;
API.shared.setEntityData(V, "InventoryHolder", ih);
}
else
{
InventoryHolder ih = new InventoryHolder();
ih.InventoryFromXML(path);
ih.Owner = V;
API.shared.setEntityData(V, "InventoryHolder", ih);
}
}
public static void save(Client player)
{
InventoryHolder ih = API.shared.getEntityData(player, "InventoryHolder");
if (ih == null)
{
API.shared.consoleOutput("ih is null");
return;
}
ih.InventoryToXML(player);
}
public class InventoryItem
{
public Item Details { get; set; }
public int Quantity { get; set; }
public InventoryItem(Item details, int quantity)
{
Details = details;
Quantity = quantity;
}
}
public class InventoryHolder
{
public List<InventoryItem> Inventory { get; set; }
public NetHandle Owner { get; set; }
public InventoryHolder()
{
Inventory = new List<InventoryItem>();
}
public void AddItemToInventory(Item itemToAdd)
{
if (itemToAdd != null)
{
var player = API.shared.getPlayerFromHandle(Owner);
if (player != null) { }
foreach (InventoryItem ii in Inventory)
{
if (ii.Details.ID == itemToAdd.ID)
{
ii.Quantity++;
return;
}
}
Inventory.Add(new InventoryItem(itemToAdd, 1));
}
}
public void RemoveItemFromInventory(Item itemToDel)
{
InventoryItem item = Inventory.SingleOrDefault(ii => ii.Details.ID == itemToDel.ID);
if (item != null)
{
if (item.Quantity == 1)
{
Inventory.Remove(item);
}
else if(item.Quantity < 0)
{
Inventory.Remove(item);
}
else
{
item.Quantity--;
}
}
}
public bool hasItemInInventory(Item item)
{
bool state = false;
InventoryItem itemininventory = Inventory.SingleOrDefault(ii => ii.Details.ID == item.ID);
if(itemininventory != null){
if(itemininventory.Quantity > 0){
state = true;
}
}
return state;
}
public void InventoryToXML(Client player)
{
XDocument inventoryData = new XDocument(new XElement("InventoryItems"));
var inventoryItems = inventoryData.Element("InventoryItems");
foreach (InventoryItem i in Inventory)
{
inventoryItems.Add(new XElement("InventoryItem", new XAttribute("ID", i.Details.ID), new XAttribute("Quantity", i.Quantity)));
}
var path = Path.Combine(INVENTORY_FOLDER, player.socialClubName);
inventoryData.Save(path);
}
public void VehicleInventoryToXML(NetHandle Vehicle)
{
XDocument inventoryData = new XDocument(new XElement("InventoryItems"));
var inventoryItems = inventoryData.Element("InventoryItems");
foreach (InventoryItem i in Inventory)
{
inventoryItems.Add(new XElement("InventoryItem", new XAttribute("ID", i.Details.ID), new XAttribute("Quantity", i.Quantity)));
}
var path = Path.Combine(INVENTORY_FOLDER, API.shared.getEntityData(Vehicle, "OwnedVehicleID").ToString());
inventoryData.Save(path);
}
public void InventoryFromXML(string path)
{
XElement xelement = XElement.Load(path);
IEnumerable<XElement> InventoryItems = xelement.Elements();
foreach (var I in InventoryItems)
{
int id = Convert.ToInt32(I.Attribute("ID").Value);
if (items.Contains(ItemByID(id)))
{
int quantity = Convert.ToInt32(I.Attribute("Quantity").Value);
for (int i = 0; i < quantity; i++)
{
AddItemToInventory(ItemByID(id));
}
}
else { API.shared.consoleOutput("attempted to load null iventory item"); }
}
}
}
public static bool IsInRangeOf(Vector3 playerPos, Vector3 target, float range)
{
var direct = new Vector3(target.X - playerPos.X, target.Y - playerPos.Y, target.Z - playerPos.Z);
var len = direct.X * direct.X + direct.Y * direct.Y + direct.Z * direct.Z;
return range * range > len;
}
[Command("dropWeapon", Alias = "dw")]
public void dropWeapons(Client player)
{
if(API.getPlayerCurrentWeapon(player) != WeaponHash.Unarmed)
{
Pickup pb = API.createPickup(PickupHash.PortablePackage, player.position.Add(new Vector3(2,2,0)), player.rotation,1, 1000 * 600, 0);
ColShape cs = API.createCylinderColShape(pb.position, 1, 1);
cs.setData("weapon", API.getPlayerCurrentWeapon(player));
cs.setData("weapon:ammo", API.getPlayerWeaponAmmo(player, API.getPlayerCurrentWeapon(player)));
cs.setData("weapon:pickup", pb);
API.consoleOutput("Spieler: " + player.name + " hat die Waffe: " + API.getPlayerCurrentWeapon(player) + " gedroppt. Ammo: " + API.getPlayerWeaponAmmo(player, API.getPlayerCurrentWeapon(player)));
if(API.getPlayerWeaponAmmo(player, API.getPlayerCurrentWeapon(player)) > 9999){
API.consoleOutput("*Wildland ANTICHEAT* Player dropped Ammo over 9999 Shots!!!!");
}
API.sendNotificationToPlayer(player, "Du hast die Waffe fallengelassen!");
API.removePlayerWeapon(player,API.getPlayerCurrentWeapon(player));
}
}
private void onWeaponPackage(ColShape col, NetHandle ent)
{
if(col != null && ent != null)
{
if(col.hasData("weapon") && col.hasData("weapon:ammo") && col.hasData("weapon:pickup"))
{
if (API.getEntityType(ent) == EntityType.Player)
{
ColShape cs = col;
Pickup pb = cs.getData("weapon:pickup");
WeaponHash weapon = cs.getData("weapon");
Client player = API.getPlayerFromHandle(ent);
int ammo = cs.getData("weapon:ammo");
if(ammo > 9999){
API.sendNotificationToPlayer(player,"*Wildland Anticheat* Warning Weapon is currupt!");
pb.delete();
API.deleteColShape(cs);
return;
} else {
API.givePlayerWeapon(player, weapon, ammo, true, true);
pb.delete();
API.deleteColShape(cs);
API.sendNotificationToPlayer(player, "Du hast eine Waffe aufgehoben!");
}
}
}
}
}
}
}