Skip to content

Commit

Permalink
Add credit distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Oct 24, 2024
1 parent e8b59da commit f620c53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"menu.format.invitation": "%color.special%{0}%color.default% invited %color.target%{1}%color.default% on %color.emph%{2}%color.default%.",
"menu.format.request": "%color.target%{0}%color.default% requested to join on %color.emph%{1}%color.default%.",
"raffle.begin": "%prefix%A raffle for %color.currency%{0} %currency%%s%%color.default% has begun. Type %color.command%/raffle %color.default% to enter.",
"raffle.preannounce": "%prefix%Raffle closed! Collected %color.currency%{0} %currency%%s% across %color.number%{1}%color.default% entrant%s%.",
"raffle.preannounce": "%prefix%Raffle closed! Collected %color.currency%{0} %currency%%s%%color.default% across %color.number%{1}%color.default% entrant%s%.",
"raffle.winner": "%prefix%%color.target%{0}%color.default% won the raffle with a %color.number%{1}%color.default% chance!",
"raffle.notactive": "%prefix%There is no active raffle.",
"raffle.notopen": "%prefix%The raffle closed entries and is currently drawing."
Expand Down
10 changes: 10 additions & 0 deletions src/CS2/Raffle/RaffleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Cvars;
using GangsAPI;
using GangsAPI.Data;
using GangsAPI.Services;
using GangsAPI.Services.Commands;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
Expand Down Expand Up @@ -39,6 +41,8 @@ public class RaffleManager(IServiceProvider provider)
private readonly IStringLocalizer locale =
provider.GetRequiredService<IStringLocalizer>();

private readonly IEcoManager eco = provider.GetRequiredService<IEcoManager>();

public void Start(BasePlugin? plugin, bool hotReload) {
Console.WriteLine($"Start called on RaffleManager, plugin: {plugin}");
if (plugin == null) return;
Expand Down Expand Up @@ -92,6 +96,12 @@ public void DrawWinner() {
var name = Utilities.GetPlayerFromSteamId(winner.Value)?.PlayerName
?? winner.ToString() ?? "";

var wrapper = new PlayerWrapper(winner.Value, name);

Task.Run(async () => {
await eco.Grant(wrapper, Raffle.Value, true, "Raffle");
});

Server.PrintToChatAll(locale.Get(MSG.RAFFLE_WINNER, name,
(1.0f / (Raffle.TotalPlayers + 1)).ToString("P1")));
Raffle = null;
Expand Down
7 changes: 1 addition & 6 deletions src/CS2/Raffle/StartRaffleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ public async Task<CommandResult> Execute(PlayerWrapper? executor,
if (!int.TryParse(info.Args[1], out amo))
return CommandResult.PRINT_USAGE;

var result = false;
await Server.NextFrameAsync(() => { result = raffle.StartRaffle(amo); });

info.ReplySync(result ?
"Raffle started with a prize of $" + amo :
"Raffle already in progress");
await Server.NextFrameAsync(() => { raffle.StartRaffle(amo); });
return CommandResult.SUCCESS;
}
}

0 comments on commit f620c53

Please sign in to comment.