#How to create AdminToys?
1 messages · Page 1 of 1 (latest)
you shouldn't instantiate unity objects with constructors
loop through NetworkClient.prefabs.Values and find the one you need
(check how SpawnToyCommand does it)
Would this be correct then?
internal GameObject GetSpeakerPrefab()
{
if(SpeakerPrefab != null) return SpeakerPrefab;
foreach (GameObject prefabsValue in NetworkClient.prefabs.Values)
{
if (prefabsValue.GetComponent<SpeakerToy>() == null) continue;
SpeakerPrefab = prefabsValue;
return prefabsValue;
}
return null;
}```
ideally you'd cache the component instead of the game object, so
if (!prefabsValue.TryGetComponent(out SpeakerToy toy)) continue;
SpeakerPrefab = toy;
return toy;
if SpeakerPrefab is a field, you can pass that as the out parameter
I want to create a new speaker though, not use an existing one
this way you can instantiate the speaker toy without having to call GetComponent upon instantiation
how can I instantiate without the game object?
instantiate the component, that instantiates the entire object
and it returns the component on the clone directly
SpeakerToy toy = Instantiate(toyPrefabGameObject).GetComponent<SpeakerToy>() vs SpeakerToy toy = Instantiate(toyPrefab)
so you can do that? ok
yea
SpeakerToy speaker = UnityEngine.Object.Instantiate(Plugin.Instance.GetSpeakerPrefab());
internal SpeakerToy GetSpeakerPrefab()
{
if(SpeakerPrefab != null) return SpeakerPrefab;
foreach (GameObject prefabsValue in NetworkClient.prefabs.Values)
{
if (!prefabsValue.TryGetComponent(out SpeakerToy toy)) continue;
SpeakerPrefab = toy;
return toy;
}
return null;
}```
correct?
looks good
you can also specify the parent, position and rotation in Instantiate()
the nanoseconds are important

because when you hover over the method it'll show the current signature
when you're typing Object.Instantiate, it should show the overloads
yeah
also why tf does ItemSpawningEventArgs only give the item type
not the item
cuz it's spawning and not spawned
it doesn't exist at that time (based on the naming at least)
exiled and labapi a lot different smh
nah i realistically only need after
you can't cancel it after
ik
that part is obvious lol
this plugin is gunna take a bit of testing smh
*now i need to find the event for when an item is given to a player via RA :c
InventoryExtensions.OnItemAdded
then check ItemBase.ServerAddReason
i don't see a labapi event for that atm
:c
you could still use Exiled on lab API (UwU)
that's only if exiled is installed though 😭
im building all my labapi versions with the intent that exiled wont be on the server
why 
because a lot of servers might not use exiled anymore
@gusty dome sorry to ping, but how do you play audio through SpeakerToys?
i just looked how exiled did it just now lol
didnt need to ping
AudioMessage msgToSend = new(speakerPair.Value.ControllerId, encodedData, dataLen);
foreach (Player target in Player.List)
{
target.Connection.Send(msgToSend);
}```
pretty much nothing
yeah lol
if Player.List contains unauthenticated players, it could be an issue
oh wait so I don't even need to check every player in the list? I just can run SendToAuthenticated on the msg?
damn
easier to write than a loop
also what is channelId? do i need to change it?
channelId?
Player.Dictionary perhaps?

why is there no tryget on ref hub 😭
#if EXILED
if (!Player.TryGet(msg.Speaker, out Player player)) return false;
#else
if(!Player.Dictionary.TryGetValue(msg.Speaker, out Player player)) return false;
#endif```
wasn't that hard
make an issue or a feedback post
ye will do
Do you need tryget for refhub? its always going to return unless the refhub was null
i don’t need it, will it be useful? yeah
wdym
if you get do Player.Get that covers all cases
also doesnt EXILED have player.Get for refhub?
¯_(ツ)_/¯