Delryn Posted April 1, 2018 Share Posted April 1, 2018 Hi! First of all, I got some issues with the interior system. I’d like to make a script: if someone enter (e.g: ID5 ) interior, then make a text: you entered the ID5 interior. I was looking for in the interior system, but I can’t find the line, where the entering part is located. I’d be grateful if you could tell me, how to do this. I don’t want to make this script inside the interior system but as a new resource. Thank u in advance! Link to comment
myonlake Posted April 1, 2018 Share Posted April 1, 2018 (edited) There's a couple ways you can do this. a) A render loop and see if the interior has changed in a frame by storing the current interior ID into a variable outside of the render loop, and then next frame checking if it has changed, triggering an event, and then overwriting it with the new interior ID. Heavy way of doing a check, and it's only client-side, hence insecure. Just works doesn't matter which resource sets the interior. b) Wrap the setElementInterior function with your own function and trigger an event or something when it's called. Perhaps more lightweight compared to a render loop. Can be implemented both client and server-side (with server-side validation, more secure). Requires you to implement this wrapper function everywhere in your code, so it's a bit of a pain if you use third-party scripts a lot. Edited April 1, 2018 by myonlake Link to comment
Delryn Posted April 1, 2018 Author Share Posted April 1, 2018 Can u send me an example please? A code which shows How to start or How to do it:) Link to comment
myonlake Posted April 1, 2018 Share Posted April 1, 2018 (edited) Something like this should do the trick. -- Start by setting the interiorId variable to the player element's current interior ID local interiorId = getElementInterior(localPlayer) addEventHandler("onClientRender", root, function() -- The the player element's current interior ID local currentInteriorId = getElementInterior(localPlayer) -- Compare if the last saved interior ID has changed by the current player element interior ID if (interiorId ~= currentInteriorId) then -- Trigger a client-side event "onClientPlayerInteriorChanged" -- addEventHandler("onClientPlayerInteriorChanged", root, function(oldInteriorId, newInteriorId) --[[ your code ]] end) triggerEvent("onClientPlayerInteriorChanged", localPlayer, interiorId, currentInteriorId) -- Save the new interior ID to the variable interiorId = currentInteriorId end end) Tested and working using the following snippet: addEvent("onClientPlayerInteriorChanged") addEventHandler("onClientPlayerInteriorChanged", localPlayer, function(oldInteriorId, newInteriorId) -- Bound to only the localPlayer element in this example outputChatBox(oldInteriorId .. " => " .. newInteriorId) end) addCommandHandler("int", function(_, interiorId) setElementInterior(localPlayer, math.max(0, math.min(255, tonumber(interiorId) or 0))) end) You can implement this further by doing a full scan over a table of elements, such as all players, and triggering that event whenever someone changes their interior. Right now it only checks the local player. Edited April 1, 2018 by myonlake Link to comment
Delryn Posted April 1, 2018 Author Share Posted April 1, 2018 Thank u so much! I will test my script with your help at midnight. Thank u so much! ? 1 Link to comment
myonlake Posted April 1, 2018 Share Posted April 1, 2018 1 minute ago, Delryn said: Thank u so much! I will test my script with your help at midnight. Thank u so much! ? You're welcome! Link to comment
Delryn Posted April 1, 2018 Author Share Posted April 1, 2018 (edited) I tried it with dimensions, and didn't work properly. Any ideas? Quote local dimensionId = getElementDimension(localPlayer) local currentDimensionId = getElementDimension(localPlayer) if (dimensionId ~= currentDimensionId) then triggerEvent("onClientPlayerDimChanged", localPlayer, dimensionId, currentDimensionId) dimensionId = currentDimensionId end end) addEvent("onClientPlayerDimChanged") addEventHandler("onClientPlayerDimChanged", localPlayer, function(oldDimensionId, newDimensionId) local dimensionId = getElementDimension(localPlayer) outputChatBox(oldDimensionId.. "--> " ..newDimensionId) end end) addCommandHandler("int", function(_, dimensionId) setElementDimension(localPlayer, math.max(0, math.min(255, tonumber(dimensionId) or 0))) end) PS: worked with interiors Edited April 1, 2018 by Delryn Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now