Needing help on why it always does 60 instead of 120.

11 Replies
RejectModders
RejectModdersOP6mo ago
Yes im new to c# but I am just confused on why it won't work. If anyone can help, that will be great.
Buddy
Buddy6mo ago
What is it ?
RejectModders
RejectModdersOP6mo ago
Its just a plugin for Unturned, yes I should be asking in their support server, but their support server is not really fond on "new" c# users. So I thought my best bet was to come here n see if anyone could help tbh.
Buddy
Buddy6mo ago
Your title. What is it in this context? What is always 60?
RejectModders
RejectModdersOP6mo ago
c#

private async Task OnPlayerSpawned(IServiceProvider serviceProvider, object? sender, UnturnedPlayerSpawnedEvent @event)
{
var user = await _userManager.FindUserAsync(KnownActorTypes.Player, @event.Player.SteamId.ToString(), UserSearchMode.FindById);
if (user == null)
{
Logger.LogWarning($"Could not find user for player {@event.Player.SteamId}");
return;
}

var hasDonatorPermission = await _permissionChecker.CheckPermissionAsync(user, "InvulnerablePlayers:sp.donator");
var invulnerabilityPeriod = hasDonatorPermission == PermissionGrantResult.Grant ? TimeSpan.FromSeconds(120) : TimeSpan.FromSeconds(60);

_invulnerablePlayers[@event.Player.SteamPlayer] = (DateTime.UtcNow, invulnerabilityPeriod);

int invulnerabilitySeconds = (int)invulnerabilityPeriod.TotalSeconds;
ChatManager.serverSendMessage($"You have {invulnerabilitySeconds} seconds of invulnerability from PvP.", Color.green, null, @event.Player.SteamPlayer, EChatMode.SAY, null, true);
}
c#

private async Task OnPlayerSpawned(IServiceProvider serviceProvider, object? sender, UnturnedPlayerSpawnedEvent @event)
{
var user = await _userManager.FindUserAsync(KnownActorTypes.Player, @event.Player.SteamId.ToString(), UserSearchMode.FindById);
if (user == null)
{
Logger.LogWarning($"Could not find user for player {@event.Player.SteamId}");
return;
}

var hasDonatorPermission = await _permissionChecker.CheckPermissionAsync(user, "InvulnerablePlayers:sp.donator");
var invulnerabilityPeriod = hasDonatorPermission == PermissionGrantResult.Grant ? TimeSpan.FromSeconds(120) : TimeSpan.FromSeconds(60);

_invulnerablePlayers[@event.Player.SteamPlayer] = (DateTime.UtcNow, invulnerabilityPeriod);

int invulnerabilitySeconds = (int)invulnerabilityPeriod.TotalSeconds;
ChatManager.serverSendMessage($"You have {invulnerabilitySeconds} seconds of invulnerability from PvP.", Color.green, null, @event.Player.SteamPlayer, EChatMode.SAY, null, true);
}
Buddy
Buddy6mo ago
$code
MODiX
MODiX6mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
RejectModders
RejectModdersOP6mo ago
This part is supposed to do a check to see if you have the permission sp.donator but its doing something wrong and always returns 60 instead of 120 even tho I have the permission sp.donator https://paste.pythondiscord.com/F5RQ its on here line 91 - 121 Idk if its possible to help me since its related to plugins/modding/apis but im giving it a shot here lol
Buddy
Buddy6mo ago
I would suggest to use the debugger
RejectModders
RejectModdersOP6mo ago
alr
Buddy
Buddy6mo ago
You can possibly call
if (!Debugger.IsAttached)
{
Debugger.Launch();
}
if (!Debugger.IsAttached)
{
Debugger.Launch();
}
if you can't directly use the debugger
Want results from more Discord servers?
Add your server