Jump to content

Which one is better?


Modafinil

Recommended Posts

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

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 by Addlibs
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...