SjoerdPSV Posted July 31, 2014 Share Posted July 31, 2014 Hello, I wanted to trigger the onPlayerLogin event, but I want it so that only the player who logs in will trigger the event. I tried to put source as the 2nd argument but that gives an error. Anyone knows what's wrong? function startUp() dbQuery(startUp2, speakerdb, "SELECT * FROM songs") dbQuery(startUp3, speakerdb, "SELECT * FROM radios") dbQuery(startUp4, speakerdb, "SELECT * FROM speakers") end addEventHandler("onResourceStart", resourceRoot, startUp) addEventHandler("onPlayerLogin", source, startUp) Thanks in advantage, Sjoerd Link to comment
Addlibs Posted July 31, 2014 Share Posted July 31, 2014 addEventHandler("onPlayerLogin", source, startUp) source isn't defined. You need do do addEventHandler("onPlayerLogin", root, function() startUp(source) --Call 'startUp' function sending the source of the 'onPlayerLogin' event end) function startUp( player ) -- 'player' is the player element that just logged in -- Your stuff end Link to comment
RottenFlesh Posted July 31, 2014 Share Posted July 31, 2014 (edited) the source variable is not always the player. It depends on what event is being triggered, in some events the source is the player and in others it may be a vehicle or something else. And it only works inside the scope of the function attached to the event. You have to do something like this: function my_function() -- here, the source variable is a player because the event of this function is triggered when a player logs in -- and the source variable will work only inside this function for this event end addEventHandler("onPlayerLogin", getRootElement(), my_function) this way the event will be triggered when every player logs in, as every player is below the root element in the element tree. read this: Element_tree and this: AddEventHandler Edited July 31, 2014 by Guest Link to comment
Addlibs Posted July 31, 2014 Share Posted July 31, 2014 I want it so that only the player who logs in will trigger the event. That's exactly how the event functions when when attached to root (or getElementRoot()) The player that logs in triggers the event, as the event's source. 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