Skip to content

Commit

Permalink
Adding optional Dependency to Uconomy, making prices & giving money p…
Browse files Browse the repository at this point in the history
…ossible. To set a price, simply set the Money amount to a negative value.
  • Loading branch information
fr34kyn01535 committed Mar 11, 2016
1 parent f3d6051 commit 4a3aff1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
24 changes: 24 additions & 0 deletions CommandKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ public void Execute(IRocketPlayer caller, string[] command)
}
}

bool cancelBecauseNotEnoughtMoney = false;

if (kit.Money.HasValue && kit.Money.Value != 0)
{
Kits.ExecuteDependencyCode("Uconomy",(IRocketPlugin plugin) =>
{
Uconomy.Uconomy Uconomy = (Uconomy.Uconomy)plugin;
if(kit.Money<0){
if ((Uconomy.Database.GetBalance(player.CSteamID.ToString()) - kit.Money) < 0)
{
cancelBecauseNotEnoughtMoney = true;
UnturnedChat.Say(caller, Kits.Instance.Translations.Instance.Translate("command_kit_no_money", kit.Money,Uconomy.Configuration.Instance.MoneyName));
return;
}
}
Uconomy.Database.IncreaseBalance(player.CSteamID.ToString(), kit.Money.Value);
});
}

if (cancelBecauseNotEnoughtMoney)
{
return;
}

foreach (KitItem item in kit.Items)
{

Expand Down
18 changes: 16 additions & 2 deletions Kits.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Rocket.API.Collections;
using Rocket.API;
using Rocket.API.Collections;
using Rocket.Core;
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
using System;
using System.Collections.Generic;
Expand All @@ -15,6 +18,14 @@ public class Kits : RocketPlugin<KitsConfiguration>
protected override void Load()
{
Instance = this;
if (IsDependencyLoaded("Uconomy"))
{
Logger.Log("Optional dependency Uconomy is present.");
}
else
{
Logger.Log("Optional dependency Uconomy is not present.");
}
}

public override TranslationList DefaultTranslations
Expand All @@ -29,7 +40,10 @@ public override TranslationList DefaultTranslations
{"command_kit_cooldown_kit","You have to wait {0} seconds to get this kit again"},
{"command_kit_failed_giving_item","Failed giving a item to {0} ({1},{2})"},
{"command_kit_success","You just received the kit {0}" },
{"command_kits","You have access to the following kits: {0}" }
{"command_kits","You have access to the following kits: {0}" },
{"command_kit_no_money","You can't afford this kit. You need atleast {0} {1}." }


};
}
}
Expand Down
6 changes: 5 additions & 1 deletion Kits.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\Desktop\Unturned\Servers\test\Rocket\Plugins\</OutputPath>
<OutputPath>..\..\..\Desktop\Unturned\Servers\cobra1\Rocket\Plugins\</OutputPath>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
Expand Down Expand Up @@ -65,6 +65,10 @@
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Uconomy">
<HintPath>lib\Uconomy.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\UnityEngine.dll</HintPath>
Expand Down
5 changes: 3 additions & 2 deletions KitsConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public void LoadDefaults()
GlobalCooldown = 10;
Kits = new List<Kit>() {
new Kit() { Cooldown = 10, Name = "Survival", XP = 0,Items = new List<KitItem>() { new KitItem(245, 1), new KitItem(81, 2), new KitItem(16, 1) }},
new Kit() { Cooldown = 10, Name = "Brute Force", XP = 0, Vehicle = 57,Items = new List<KitItem>() { new KitItem(112, 1), new KitItem(113, 3), new KitItem(254, 3) }},
new Kit() { Cooldown = 10, Name = "Watcher", XP = 200, Items = new List<KitItem>() { new KitItem(109, 1), new KitItem(111, 3), new KitItem(236, 1) }}
new Kit() { Cooldown = 10, Name = "Brute Force", XP = 0,Money = 30, Vehicle = 57,Items = new List<KitItem>() { new KitItem(112, 1), new KitItem(113, 3), new KitItem(254, 3) }},
new Kit() { Cooldown = 10, Name = "Watcher", XP = 200,Money=-20, Items = new List<KitItem>() { new KitItem(109, 1), new KitItem(111, 3), new KitItem(236, 1) }}
};
}
}
Expand All @@ -28,6 +28,7 @@ public Kit() { }

public string Name;
public uint? XP = null;
public decimal? Money = null;
public ushort? Vehicle = null;

[XmlArrayItem(ElementName = "Item")]
Expand Down
Binary file modified lib/Rocket.Core.dll
Binary file not shown.
Binary file modified lib/Rocket.Unturned.dll
Binary file not shown.

0 comments on commit 4a3aff1

Please sign in to comment.