Modafinil Posted December 1, 2020 Share Posted December 1, 2020 Hello, I would like some help. Imagine a hypothetical situation. I create 100 pickups on my server and each pickup sends a different message to the player. I came up with 2 ways to do this and I wish you could tell me which is the best in terms of resources. addEventHandler("onPickupHit", pickupSourceHere, function(player) outputChatBox("the message here", player) cancelEvent() end) addEventHandler("onPickupHit", resourceRoot, function(player) if source == pickupSourceHere then outputChatBox("the message here", player) cancelEvent() end end) Thanks! Oh, and sorry about my english. Link to comment
Addlibs Posted December 1, 2020 Share Posted December 1, 2020 (edited) If every pickup does a different message, it would be best to do something like messages = { [pickupSource1] = "message for hitting pickupSource1", [pickupSource2] = "message for hitting pickupSource2", ... } addEventHandler("onPickupHit", resourceRoot, function(player) if messages[source] then -- if a message is defined for this pickup element outputChatBox(messages[source], player) -- output that message to the player that hit it cancelEvent() end end ) Edited December 1, 2020 by Addlibs Link to comment
Modafinil Posted December 1, 2020 Author Share Posted December 1, 2020 How could i forget that? Thanks! 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