Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with PayHit #6

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ build/
bld/
[Bb]in/
[Oo]bj/
.vs
bin/
obj/

# Roslyn cache directories
*.ide/
Expand Down
104 changes: 39 additions & 65 deletions CommandApay.cs
Original file line number Diff line number Diff line change
@@ -1,103 +1,77 @@
using System;
using System.Collections.Generic;

using System.Collections.Generic;
using fr34kyn01535.Uconomy;
using Rocket.API;
using Rocket.Unturned;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Commands;
using Rocket.Unturned.Player;
using fr34kyn01535.Uconomy;
using SDG.Unturned;
using Steamworks;

namespace Uconomy_Essentials
namespace ZaupUconomyEssentials
{
public class CommandApay : IRocketCommand
{
public AllowedCaller AllowedCaller => AllowedCaller.Player;

public string Name => "apay";

public string Help => "Allows an allowed person to pay someone else not using their own currency.";

public string Syntax => "<player name or id> <amt>";

public List<string> Aliases => new List<string>();

public List<string> Permissions => new List<string>();

public AllowedCaller AllowedCaller
{
get
{
return AllowedCaller.Player;
}
}
public string Name
{
get
{
return "apay";
}
}
public string Help
{
get
{
return "Allows an allowed person to pay someone else not using their own currency.";
}
}
public string Syntax
{
get
{
return "<player name or id> <amt>";
}
}
public List<string> Aliases
{
get { return new List<string>(); }
}
public List<string> Permissions
{
get { return new List<string>(); }
}
public void Execute(IRocketPlayer caller, string[] msg)
{
UnturnedPlayer playerid = (UnturnedPlayer)caller;
var playerid = (UnturnedPlayer) caller;
string message;
if (msg.Length == 0)
{
message = Uconomy_Essentials.Instance.Translate("apay_usage_msg", new object[] {});
message = UconomyEssentials.Instance.Translate("apay_usage_msg");
// We are going to print how to use
UnturnedChat.Say(playerid, message);
return;
}

if (msg.Length != 2)
{
message = Uconomy_Essentials.Instance.Translate("apay_usage_msg", new object[] { });
message = UconomyEssentials.Instance.Translate("apay_usage_msg");
// Print how to use
UnturnedChat.Say(playerid, message);
return;
}
UnturnedPlayer rp = UnturnedPlayer.FromName(msg[0]);

var rp = UnturnedPlayer.FromName(msg[0]);
if (rp == null)
{
ulong id;
ulong.TryParse(msg[0], out id);
if (!((CSteamID)id).IsValid())
ulong.TryParse(msg[0], out var id);
if (!((CSteamID) id).IsValid())
{
message = Uconomy_Essentials.Instance.Translate("not_valid_player_msg", new object[] {msg[0]});
message = UconomyEssentials.Instance.Translate("not_valid_player_msg", msg[0]);
UnturnedChat.Say(playerid, message);
return;
}
else
{
rp = UnturnedPlayer.FromCSteamID((CSteamID)id);
}


rp = UnturnedPlayer.FromCSteamID((CSteamID) id);
}
uint amt;
uint.TryParse(msg[1], out amt);

uint.TryParse(msg[1], out var amt);
if (amt <= 0)
{
message = Uconomy_Essentials.Instance.Translate("not_valid_amount", new object[] { msg[1] });
message = UconomyEssentials.Instance.Translate("not_valid_amount", msg[1]);
UnturnedChat.Say(playerid, message);
return;
}
decimal newbal = Uconomy.Instance.Database.IncreaseBalance(rp.CSteamID.ToString(), amt);
UnturnedChat.Say(rp.CSteamID, Uconomy_Essentials.Instance.Translate("apaid_msg", new object[] {playerid.CharacterName, amt, Uconomy.Instance.Configuration.Instance.MoneyName, newbal, Uconomy.Instance.Configuration.Instance.MoneyName}));
UnturnedChat.Say(playerid, Uconomy_Essentials.Instance.Translate("apay_msg", new object[] {rp.CharacterName, amt, Uconomy.Instance.Configuration.Instance.MoneyName}));
Uconomy_Essentials.HandleEvent(rp, amt, "paid");

var newbal = Uconomy.Instance.Database.IncreaseBalance(rp.CSteamID.ToString(), amt);
UnturnedChat.Say(rp.CSteamID,
UconomyEssentials.Instance.Translate("apaid_msg", playerid.CharacterName, amt,
Uconomy.Instance.Configuration.Instance.MoneyName, newbal,
Uconomy.Instance.Configuration.Instance.MoneyName));
UnturnedChat.Say(playerid,
UconomyEssentials.Instance.Translate("apay_msg", rp.CharacterName, amt,
Uconomy.Instance.Configuration.Instance.MoneyName));
UconomyEssentials.HandleEvent(rp, amt, "paid");
}
}
}
}
124 changes: 52 additions & 72 deletions CommandExchange.cs
Original file line number Diff line number Diff line change
@@ -1,134 +1,114 @@
using System;
using System.Collections.Generic;

using System.Collections.Generic;
using fr34kyn01535.Uconomy;
using Rocket.API;
using Rocket.Unturned;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Commands;
using Rocket.Unturned.Player;
using fr34kyn01535.Uconomy;
using SDG.Unturned;
using Steamworks;

namespace Uconomy_Essentials
namespace ZaupUconomyEssentials
{
public class CommandExchange : IRocketCommand
{
public AllowedCaller AllowedCaller => AllowedCaller.Player;

public string Name => "exchange";

public string Help => "Exchanges experience for economy currency.";

public string Syntax => "<amount> [money]";

public List<string> Aliases => new List<string>();

public List<string> Permissions => new List<string>();

public AllowedCaller AllowedCaller
{
get
{
return AllowedCaller.Player;
}
}
public string Name
{
get
{
return "exchange";
}
}
public string Help
{
get
{
return "Exchanges experience for economy currency.";
}
}
public string Syntax
{
get
{
return "<amount> [money]";
}
}
public List<string> Aliases
{
get { return new List<string>(); }
}
public List<string> Permissions
{
get { return new List<string>(); }
}
public void Execute(IRocketPlayer caller, string[] amt)
{
UnturnedPlayer playerid = (UnturnedPlayer)caller;
var playerid = (UnturnedPlayer) caller;
string message;
if (amt.Length == 0)
{
message = Uconomy_Essentials.Instance.Translate("exchange_usage_msg", new object[] { });
message = UconomyEssentials.Instance.Translate("exchange_usage_msg");
UnturnedChat.Say(playerid, message);
return;
}

if (amt.Length > 2)
{
message = Uconomy_Essentials.Instance.Translate("exchange_usage_msg", new object[] { });
message = UconomyEssentials.Instance.Translate("exchange_usage_msg");
UnturnedChat.Say(playerid, message);
return;
}
if (!Uconomy_Essentials.Instance.Configuration.Instance.ExpExchange && amt.Length == 1)

if (!UconomyEssentials.Instance.Configuration.Instance.ExpExchange && amt.Length == 1)
{
message = Uconomy_Essentials.Instance.Translate("experience_exchange_not_available", new object[] { });
message = UconomyEssentials.Instance.Translate("experience_exchange_not_available");
UnturnedChat.Say(playerid, message);
return;
}
if (!Uconomy_Essentials.Instance.Configuration.Instance.MoneyExchange && amt.Length == 2)

if (!UconomyEssentials.Instance.Configuration.Instance.MoneyExchange && amt.Length == 2)
{
message = Uconomy_Essentials.Instance.Translate("money_exchange_not_available", new object[] { });
message = UconomyEssentials.Instance.Translate("money_exchange_not_available");
UnturnedChat.Say(playerid, message);
return;
}

// Get expereience balance first
uint exp = playerid.Experience;
uint examt = 0;
UInt32.TryParse(amt[0], out examt);
var exp = playerid.Experience;
uint.TryParse(amt[0], out var examt);
if (examt <= 0)
{
message = Uconomy_Essentials.Instance.Translate("exchange_zero_amount_error", new object[] { });
message = UconomyEssentials.Instance.Translate("exchange_zero_amount_error");
UnturnedChat.Say(playerid, message);
return;
}

if (exp < examt && amt.Length == 1)
{
message = Uconomy_Essentials.Instance.Translate("exchange_insufficient_experience", new object[] { examt.ToString() });
message = UconomyEssentials.Instance.Translate("exchange_insufficient_experience", examt.ToString());
UnturnedChat.Say(playerid, message);
return;
}

// Get balance first
decimal bal = Uconomy.Instance.Database.GetBalance(playerid.CSteamID.ToString());
var bal = Uconomy.Instance.Database.GetBalance(playerid.CSteamID.ToString());
if (amt.Length > 1 && bal < examt)
{
message = Uconomy_Essentials.Instance.Translate("exchange_insufficient_money", new object[] { examt.ToString(), Uconomy.Instance.Configuration.Instance.MoneyName });
message = UconomyEssentials.Instance.Translate("exchange_insufficient_money", examt.ToString(),
Uconomy.Instance.Configuration.Instance.MoneyName);
UnturnedChat.Say(playerid, message);
return;
}

switch (amt.Length)
{
case 1:
decimal gain = (decimal)((float)examt * Uconomy_Essentials.Instance.Configuration.Instance.ExpExchangerate);
var gain = (decimal) (examt *
UconomyEssentials.Instance.Configuration.Instance.ExpExchangerate);
// Just to make sure to avoid any errors
gain = Decimal.Round(gain, 2);
decimal newbal = Uconomy.Instance.Database.IncreaseBalance(playerid.CSteamID.ToString(), gain);
message = Uconomy_Essentials.Instance.Translate("new_balance_msg", new object[] { newbal.ToString(), Uconomy.Instance.Configuration.Instance.MoneyName });
gain = decimal.Round(gain, 2);
var newbal = Uconomy.Instance.Database.IncreaseBalance(playerid.CSteamID.ToString(), gain);
message = UconomyEssentials.Instance.Translate("new_balance_msg", newbal,
Uconomy.Instance.Configuration.Instance.MoneyName);
UnturnedChat.Say(playerid, message);
playerid.Experience -= examt;
Uconomy_Essentials.HandleEvent(playerid, gain, "exchange", examt);
UconomyEssentials.HandleEvent(playerid, gain, "exchange", examt);
break;
case 2:
uint gainm = (uint)((float)examt * Uconomy_Essentials.Instance.Configuration.Instance.MoneyExchangerate);
var gainm = (uint) (examt *
UconomyEssentials.Instance.Configuration.Instance.MoneyExchangerate);
// Just to make sure to avoid any errors
newbal = Uconomy.Instance.Database.IncreaseBalance(playerid.CSteamID.ToString(), (examt * -1.0m));
message = Uconomy_Essentials.Instance.Translate("new_balance_msg", new object[] { newbal.ToString(), Uconomy.Instance.Configuration.Instance.MoneyName });
newbal = Uconomy.Instance.Database.IncreaseBalance(playerid.CSteamID.ToString(), examt * -1.0m);
message = UconomyEssentials.Instance.Translate("new_balance_msg", newbal,
Uconomy.Instance.Configuration.Instance.MoneyName);
UnturnedChat.Say(playerid, message);
playerid.Experience += gainm;
Uconomy_Essentials.HandleEvent(playerid, gainm, "exchange", examt, "money");
UconomyEssentials.HandleEvent(playerid, gainm, "exchange", examt, "money");
break;
}
playerid.Player.SteamChannel.send("tellExperience", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
{
playerid.Experience
});

playerid.Player.channel.send("tellExperience", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER,
playerid.Experience);
}
}
}
}
Loading