#How to create AdminToys?

1 messages · Page 1 of 1 (latest)

dapper steppe
#

I am so used to Exiled that usually it's smth like Toy.Create but I can't seem to find out how to do it myself. What I am doing right now is UnityEngine.Object.Instantiate<SpeakerToy>(new ()); but I feel like that is too easy compared to how EXILED does it, is this correct? Or what is the better method?

gusty dome
dapper steppe
gusty dome
#

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

dapper steppe
#

I want to create a new speaker though, not use an existing one

gusty dome
#

this way you can instantiate the speaker toy without having to call GetComponent upon instantiation

dapper steppe
#

how can I instantiate without the game object?

gusty dome
#

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)

dapper steppe
#

so you can do that? ok

gusty dome
#

yea

dapper steppe
#

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?

gusty dome
#

looks good

#

you can also specify the parent, position and rotation in Instantiate()

#

the nanoseconds are important

dapper steppe
#

me when

#

it doesnt tell me that

#

at all

gusty dome
#

because when you hover over the method it'll show the current signature
when you're typing Object.Instantiate, it should show the overloads

dapper steppe
#

yeah

#

also why tf does ItemSpawningEventArgs only give the item type

#

not the item

gusty dome
#

cuz it's spawning and not spawned
it doesn't exist at that time (based on the naming at least)

dapper steppe
#

exiled and labapi a lot different smh

gusty dome
#

i think it's good to have events both before and after

dapper steppe
#

nah i realistically only need after

gusty dome
#

you can't cancel it after

dapper steppe
#

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

gusty dome
#

i don't see a labapi event for that atm

dapper steppe
deep crystal
dapper steppe
#

im building all my labapi versions with the intent that exiled wont be on the server

deep crystal
#

why ClassDBlobSad

dapper steppe
#

@gusty dome sorry to ping, but how do you play audio through SpeakerToys?

gusty dome
#

AudioMessage

dapper steppe
#

didnt need to ping

#
AudioMessage msgToSend = new(speakerPair.Value.ControllerId, encodedData, dataLen);
                foreach (Player target in Player.List)
                {
                    target.Connection.Send(msgToSend);
                }```
gusty dome
#

ye

#

or msgToSend.SendToAuthenticated()

dapper steppe
#

difference?

#

other than sending to authed people

gusty dome
#

pretty much nothing

dapper steppe
#

yeah lol

gusty dome
#

if Player.List contains unauthenticated players, it could be an issue

dapper steppe
#

oh wait so I don't even need to check every player in the list? I just can run SendToAuthenticated on the msg?

#

damn

gusty dome
#

easier to write than a loop

dapper steppe
#

also what is channelId? do i need to change it?

gusty dome
#

channelId?

dapper steppe
gusty dome
#

on Send()?

#

that should be the default

dapper steppe
#

ok

#

now ima punch a tree because i dont wanna turn on null 😭

gusty dome
#

Player.Dictionary perhaps?

dapper steppe
#

wait yeah i just realised actually that it's not null

#

it's RefHub

gusty dome
dapper steppe
#

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

gusty dome
dapper steppe
#

ye will do

calm torrent
#

Do you need tryget for refhub? its always going to return unless the refhub was null

dapper steppe
calm torrent
#

wdym

#

if you get do Player.Get that covers all cases

#

also doesnt EXILED have player.Get for refhub?

dapper steppe
#

it does, but it also has tryget

#

i don’t know why they do, but they do

calm torrent
#

ill have a look at why they do that

#

seem weird to me

dapper steppe
#

¯_(ツ)_/¯