#Code not working
1 messages · Page 1 of 1 (latest)
do you have a stacktrace of one of these errors
one major issue i see is that your using Task.Run and then accessing unity components. use the async/await pattern instead. unity has a custom synchronization context which handles the async/await pattern in away thats safe if your task access unity components. you can search up UnitySynchronizationContext for details.
Could you tell me more?
strange, i dont see any code here which might causes something like that. might need more info
Well ask away lmao
do you have any other code or is that it
Nope, it's just that, and all that code is in the OnPlayerDeath event
https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/task-asynchronous-programming-model this has most of the info you need to be able to get started
essentially just use async/await and never use Task.Run unless you have a computationally expensive task that you must run on another thread(and also doesnt interact with unity at all)
Ah okay, how would you use async/await when executing commands?
you can fire and forget them, although i think its best to fire them, and use a continuation e.g. MyAsyncFunc().ContinueWith(x => Log.Error(c.Exception.ToString()), TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously);
if you dont use a continue, you may miss errors which is why i think you should use a continue if you cant await
Why's it so complicated to have a time delay ðŸ˜
hmmm
if you are after something simple, use MEC coroutines instead
e.g.
MEC.Timing.CallDelayed(delay,()=>
{
...
});
its all on the main thread so you dont have to think
infact if your not doing anything that requires async/await you should probably just use coroutines
MEC is in AssemblySharp-firstpass.dll
Alrighgt then, well what's something that might require using async/await (SL plugin related, not in general)?
hmm, MEC using async/await? or are you saying if you need to know async/await for plugin development
What I mean is, what is something that might require using async/await? I probably should know async/await for anything development in C# but yeah
ahh, anything thats I/O bound, most commonly Http requests and database queries
Ah okay, well lemme try using coroutines and see how we go
Okay so basically I've got no idea anymore lol, when that code runs, the winner is set to the tutorial role but not with the correct flags, none of the deadplayers are spawned in and after 30 seconds the event cleanup function does not run
not sure, the code you shared should of worked
something else might be going on, do you have any other plugins installed?
Nope, just the one I'm working on
So I start an event and try to end it and the things that goes wrong is winner is set to the tutorial role but not with the correct flags, none of the deadplayers are spawned in and after 30 seconds the event cleanup function does not run and I put the code into a command as well and the things that go wrong when I run it by a command is nothing past adding the candy runs and I get that long stacktrace in the RA
I've been going at that chunk of code for like 4 days now
First 2 days was with the nwapi, and now i'm using labapi but yea, same outcome
Dependencies I have are
- Assembly-CSharp-firstpass.dll
- Assembly-CSharp-Publicized.dll
- CommandSystem.Core.dll
- LabApi.dll
- Mirror.dll
- NorthwoodLib.dll
- Pooling.dll
- UnityEngine.CoreModule.dll
All from the server files
seems to be working, i spawed a bot and killed it and it did this
Did the event cleanup function go off?
ahh its not the dummy player, looks like it grabed the dedicated server host instead
Oh yeah, is it a problem with using dummy players then?
no i dont think it is, although i dont think they are being added to your lists
Well for me when i run that code and I kill a dummy, the dummy doesn't get spawned in and I get changed to tutorial role but I don't get tped to the tower
lemme check
add a check for the host here
List<Player> deadPlayers = Player.Dictionary.Values.ToList()
.Where(p => !p.IsHost && p.IsReady && !p.IsAlive && !p.IsOverwatchEnabled)
.ToList();
Yeah, they're included in the list
infact you should probably add that check everywhere(for now). we plan to fix the issue with host being in List soon. btw you can shorten your code by doing something like List<Player> deadPlayers = Player.List.Where(p => !p.IsHost && p.IsReady && !p.IsAlive && !p.IsOverwatchEnabled).ToList();
Ah, never saw that
Also, I just put this incsharp foreach (Player p in deadPlayers) { Logger.Debug($"{p.PlayerId}"); } just see what players were in the list and the dummues are actually listed like 2-4 times
Actually, just found the issue
It was the fact that I was using Player.Dictionary.Values.ToList()
Now the dummies are being spawned in the tower, and the eventcleanup function works
I feel so stupid lmao, I had it as Player.GetPlayers() in the old api but when I tried to use that here it said no and so I just went into the player class and Dictionary.Values.ToList() was the first thing I saw so I just used that
But now there is still one issue, when setting the role of the winner it doesn't use the corrent flags, like it doesn't spawn me in the tower
Oh and also, do you guys plan on adding a command in the console or something that will reload all plugins? I did ask that question before but I don't know if it got answered
that im not sure about
You're not sure about both?
the reloading one
Ah okay, what about the first one?
Nope, nothing like that just doesn't spawn in the spawn location, I'll try using another role maybe?
Yeah nope, doing a different role, spawning the player as a spectator then a tut doesn't work either
Yeah, it just ignores the flags :/
check the LocalAdminLog
? Where's that?
SCP Secret Laboratory\LocalAdminLogs
Ah i see
This is what I get cmd [2025-02-15 16:03:23.868 +10:00] [STDOUT] The referenced script (Interactables.Highlightable) on this Behaviour is missing! [2025-02-15 16:03:23.868 +10:00] [STDOUT] The referenced script on this Behaviour (Game Object 'MEDKIT_MODEL') is missing! [2025-02-15 16:03:23.869 +10:00] [STDOUT] The referenced script on this Behaviour (Game Object 'MEDKIT_MODEL') is missing! [2025-02-15 16:03:25.253 +10:00] [STDOUT] The referenced script (Interactables.Highlightable) on this Behaviour is missing! [2025-02-15 16:03:25.254 +10:00] [STDOUT] The referenced script on this Behaviour (Game Object 'MEDKIT_MODEL') is missing! [2025-02-15 16:03:25.254 +10:00] [STDOUT] The referenced script on this Behaviour (Game Object 'MEDKIT_MODEL') is missing! [2025-02-15 16:03:25.272 +10:00] [STDOUT] The referenced script on this Behaviour (Game Object '<null>') is missing! [2025-02-15 16:03:25.273 +10:00] [STDOUT] The referenced script on this Behaviour (Game Object 'Scp330') is missing! [2025-02-15 16:03:25.274 +10:00] [STDOUT] The referenced script on this Behaviour (Game Object 'Scp330') is missing!
you can ignore those, they are normal
find stuff that doesnt happen in a normal round
Thought so, since there's a lot of them, but that's all that was outputted when that chunk of code was ran, but yeah no I don't see anything out of the ordinary
And also, in the DoorName enum there is a door called DoorName.HczNukeArmory, what door is that referring to? Because there ain't no doors in Nuke room lol
outdated probably
Oh yeah, there used to be a door in nuke room, I already forgot the old layout lmao, to be fair I joined back after 2 years and it just happen to be 14.0 so yeah
But anyways, the tutorial spawning, any ideas?
the only thing i can think of would be that the assembly c# didnt download properly
try deleting your server download(dont bother verifying) and get steam to download it again
doesnt work in this case
Nope, didn't work, the winner is still spawned just not in the tower, they get assigned the inventory but not the spawn
This is actually the weirdest thing ever, and it sucks because it doesn't happen for you but it does for me
Also I really appreciate you helping, especially since you're a staff member and probably have alot of better things to do
Well I don't know what's going on but I think I can use a temporary fix of just setting the player position to that of the tutorial spawn because isn't the surface zone at the same position every seed
Setting the position doesn't even work??
Woahhh @late junco, wait a minute, I have this LabApi.Features.Console.Logger.Debug($"{winner.Position}"); and after my role has been changed the things that is outputted in the console is (40.00, 1014.08, -32.60) which is the location of the tutorial spawn, but I'm not in the tutorial tower, what's going on there
are you able to use the RA, like teleport/change class
sounds like desync which can happen if your game dies
RA wont work, interactions dont work e.g. doors wont open/close
yeah it didnt die then, but still odd that the pos is not matching up with what is logged
i can only assume you get teleported back afterwards
Could something be changing it back?
Yeah, probably that then, but what would be doing that?
its possible, are you denying and events?
?
e.g. ev.IsAllowed = false
I don't do anything with the ev variable
did you make any other changes apart from adding the check for the host player
The host thing, the Player.List thing and I removed a duplicate foreach loop when spawning dead players, other than that, nope
btw are you killing yourself or another player
Another player
i think if you set the role of the player thats died inside the death event it might explain it
so use ev.attacker?
either way try delaying things 1 frame
MEC.Timing.Calldelayed(0.0f,()=>
{
winner.SetRole(...);
});