Entity script that only "admin" users can activate?


#1

Is there a way to set a script in the url of an asset that only an admin user could activate? We want to have a zone like object that triggers an event but only if it is an admin user.


#2

Remember, Entity scripts run on all clients, and for any modifications to be done on the entity the entity needs to be unlocked.

Fortunately you can by default keep an object unlocked by default until an action is done to it by someone that has the rights to interact with it, you can also use a combination of an Entity Script (for interaction) and an Entity Server Script (for checking the rights) if you want to separate the integration from the action.

It depends on the rights the user has since you don’t have just admins. For High Fidelity it currently refers to users who can kick, but not for users who can unlock things.

Entity Script

If you want to define “admin” by kick ability you can just use Users.canKick Boolean to check if you have the permissions locally on where the script is run…

EntityServer Script / Client Script

If you want to do this check via EntityServer Script, or check someone elses permissions then you have to use Users.usernameFromIDReply signal which you get a response to when you request it via Users.requestUsernameFromID(sessionId)


function usernameFromIDReply(id, username, machineFingerprint, isAdmin){
  // Called when requestUsernameFromID is called, and response is ready,
  //  where as isAdmin (incorrectly) is defined by if the user can Kick (as There are many types of permissions)
}

Users.usernameFromIDReply.connect(usernameFromIDReply);
Users.requestUsernameFromID(sessionId)