Esempio n. 1
0
 public bool ChangeMoney(int amount, MoneyEventFlags flags, bool announce = false)
 {
     MoneyEventArgs args = new MoneyEventArgs() {Amount = amount, CurrentMoney = this.money, PlayerIndex = this.TSPlayer.Index, PlayerName = this.TSPlayer.Name, EventFlags = flags};
     if (this.money >= amount * -1)
     {
         if (!Vault.InvokeEvent(args))
         {
             this.Money += amount;
             if (announce)
                 TSPlayer.SendMessage(String.Format("You've {1} {0}", Vault.MoneyToString(amount), amount >= 0 ? "gained" : "lost"), Color.DarkOrange);
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
 public static bool SetBalance(string Name, int amount, bool announce = true, MoneyEventFlags flags = (MoneyEventFlags)4)
 {
     try
     {
         var player = CurrentInstance.GetPlayerByName(Name);
         if (player != null)
         {
             int modAmount = amount - player.Money;
             if (!player.ChangeMoney(modAmount, flags))
                 return false;
             else if (announce)
                 player.TSPlayer.SendMessage(String.Format("Your balance has been set to {0}", MoneyToString(amount)), Color.DarkOrange);
             return true;
         }
         else
         {
             var Reader = CurrentInstance.Database.QueryReader("SELECT money FROM vault_players WHERE username = @0 AND worldID = @1", Name, Main.worldID);
             if (Reader.Read())
             {
                 MoneyEventArgs args = new MoneyEventArgs() { Amount = amount - Reader.Get<int>("money"), CurrentMoney = Reader.Get<int>("money"), PlayerName = Name, PlayerIndex = -1, EventFlags = flags };
                 Reader.Dispose();
                 if (!Vault.InvokeEvent(args))
                 {
                     CurrentInstance.Database.Query("UPDATE vault_players SET money = @0 WHERE username = @1 AND worldID = @2", amount, Name, Main.worldID);
                     return true;
                 }
             }
             else
                 Reader.Dispose();
         }
     }
     catch (Exception ex) { Log.ConsoleError(ex.ToString()); }
     return false;
 }
Esempio n. 3
0
 public static bool ModifyBalance(string Name, int amount, bool announce = true, MoneyEventFlags flags = (MoneyEventFlags)4)
 {
     try
     {
         var player = CurrentInstance.GetPlayerByName(Name);
         if (player != null)
         {
             if (player.ChangeMoney(amount, flags, announce))
                 return true;
         }
         else
         {
             var Reader = CurrentInstance.Database.QueryReader("SELECT money FROM vault_players WHERE username = @0 AND worldID = @1", Name, Main.worldID);
             if (Reader.Read() && Reader.Get<int>("money") >= amount * -1)
             {
                 MoneyEventArgs args = new MoneyEventArgs() { Amount = amount, CurrentMoney = Reader.Get<int>("money"), PlayerName = Name, PlayerIndex = -1, EventFlags = flags };
                 int Newamount = Reader.Get<int>("money") + amount;
                 Reader.Dispose();
                 if (!Vault.InvokeEvent(args))
                 {
                     CurrentInstance.Database.Query("UPDATE vault_players SET money = @0 WHERE username = @1 AND worldID = @2", Newamount, Name, Main.worldID);
                     return true;
                 }
             }
             else
                 Reader.Dispose();
         }
     }
     catch (Exception ex) { Log.ConsoleError(ex.ToString()); }
     return false;
 }