Jump to content

onPlayerLogin error


Recommended Posts

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
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

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 by Guest
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...