#Code not working

1 messages · Page 1 of 1 (latest)

hushed ledge
#

Oh also, same errors would happen with nwapi as well

late junco
#

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.

late junco
#

strange, i dont see any code here which might causes something like that. might need more info

hushed ledge
#

Well ask away lmao

late junco
hushed ledge
#

Nope, it's just that, and all that code is in the OnPlayerDeath event

late junco
#

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)

hushed ledge
#

Ah okay, how would you use async/await when executing commands?

late junco
#

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

hushed ledge
#

Why's it so complicated to have a time delay 😭

late junco
#

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

hushed ledge
#

Alrighgt then, well what's something that might require using async/await (SL plugin related, not in general)?

late junco
#

hmm, MEC using async/await? or are you saying if you need to know async/await for plugin development

hushed ledge
#

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

late junco
#

ahh, anything thats I/O bound, most commonly Http requests and database queries

hushed ledge
#

Ah okay, well lemme try using coroutines and see how we go

hushed ledge
#

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

late junco
#

not sure, the code you shared should of worked

#

something else might be going on, do you have any other plugins installed?

hushed ledge
#

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

hushed ledge
#

First 2 days was with the nwapi, and now i'm using labapi but yea, same outcome

hushed ledge
#

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

late junco
#

seems to be working, i spawed a bot and killed it and it did this

hushed ledge
#

Did the event cleanup function go off?

late junco
#

ahh its not the dummy player, looks like it grabed the dedicated server host instead

hushed ledge
#

Oh yeah, is it a problem with using dummy players then?

late junco
#

no i dont think it is, although i dont think they are being added to your lists

hushed ledge
#

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

late junco
#

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();
hushed ledge
#

Yeah, they're included in the list

late junco
#

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();

hushed ledge
#

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

late junco
#

that im not sure about

hushed ledge
#

You're not sure about both?

late junco
#

the reloading one

hushed ledge
#

Ah okay, what about the first one?

late junco
#

it worked for me iirc

#

if thers any exceptions that happen post it here

hushed ledge
#

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 :/

late junco
#

check the LocalAdminLog

hushed ledge
#

? Where's that?

late junco
#

SCP Secret Laboratory\LocalAdminLogs

hushed ledge
#

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!

late junco
#

you can ignore those, they are normal

#

find stuff that doesnt happen in a normal round

hushed ledge
#

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

late junco
#

outdated probably

hushed ledge
#

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?

late junco
#

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

hushed ledge
#

Well using it other times works though

#

wdym by dont bother verifying?

late junco
#

doesnt work in this case

hushed ledge
#

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??

hushed ledge
#

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

late junco
#

are you able to use the RA, like teleport/change class

#

sounds like desync which can happen if your game dies

hushed ledge
#

Yeah, with the RA and text RA

#

How do I know if my game dies?

late junco
#

RA wont work, interactions dont work e.g. doors wont open/close

hushed ledge
#

And why would it happen every time?

#

Yeah RA still works and everything

late junco
#

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

hushed ledge
#

Could something be changing it back?

#

Yeah, probably that then, but what would be doing that?

late junco
#

its possible, are you denying and events?

hushed ledge
#

?

late junco
#

e.g. ev.IsAllowed = false

hushed ledge
#

I don't do anything with the ev variable

late junco
#

did you make any other changes apart from adding the check for the host player

hushed ledge
#

The host thing, the Player.List thing and I removed a duplicate foreach loop when spawning dead players, other than that, nope

late junco
#

btw are you killing yourself or another player

hushed ledge
#

Another player

late junco
#

i think if you set the role of the player thats died inside the death event it might explain it

hushed ledge
#

so use ev.attacker?

late junco
#

either way try delaying things 1 frame

MEC.Timing.Calldelayed(0.0f,()=>
{
    winner.SetRole(...);
});