Adde Posted April 18, 2013 Share Posted April 18, 2013 Hello, I want to ask you if it´s possible to make a function to trigger when a player have register. Example make this happend when someone register: function onPlayerRegister () setElementPosition ( player, x, y, z ) SetPlayerTeam ( player, "team" ) SetElementModel ( player, 1 ) givePlayerMoney ( player, 1000 ) addEventHandler("???", getRootElement, onPlayerRegister) Anyone who knows how to do that or if it works? I tested to put it in registerpanel with the other things happend at register but it didn´t work. I found something on the forum that maybe helped me a bit. Can this work? addEventHandler("onPlayerLogin", root, function(_, account) if not getAccountData(account, "FirstTime") then setElementPosition ( player, x, y, z ) setPlayerTeam ( player, "team" ) setElementModel ( player, 1 ) givePlayerMoney ( player, 1000 ) setAccountData(account, "FirstTime", true) end end ) Link to comment
Castillo Posted April 18, 2013 Share Posted April 18, 2013 From your registration system you can trigger an event, then you can use it whenever you need, but such event doesn't exist by default. Link to comment
Adde Posted April 19, 2013 Author Share Posted April 19, 2013 So if I have this function registerHandler(username, password) local account = getAccount(username, password) if (account ~= false) then outputChatBox( "", root, 255, 255, 255 ) else account = addAccount(username, password) if (logIn(source, account, password) == true) then triggerClientEvent(source, "hideRegisterWindow", getRootElement()) end end end addEventHandler("submitRegister", root, registerHandler) I can do something like this Server side function registerHandler(username, password) local account = getAccount(username, password) if (account ~= false) then outputChatBox( "", root, 255, 255, 255 ) else account = addAccount(username, password) if (logIn(source, account, password) == true) then triggerClientEvent(source, "hideRegisterWindow", getRootElement()) triggerServerEvent(source, "playerSpawn", getRootElement()) end end end addEventHandler("submitRegister", root, registerHandler) function playerSpawn() setElementPosition(source, 232.23, 1904.39, 17.84) setPlayerTeam(source, "Army") setElementModel(source, 179) setPlayerNametagColor(source, 59, 166, 109) end Link to comment
Castillo Posted April 19, 2013 Share Posted April 19, 2013 After: if (logIn(source, account, password) == true) then You can add: triggerEvent ( "onPlayerRegister", source ) Link to comment
Adde Posted April 20, 2013 Author Share Posted April 20, 2013 Aha okay, so I shoould use that instead of the one I used from the beginning? and then add an event/create an event to the function? If I understand wiki right. Link to comment
MIKI785 Posted April 20, 2013 Share Posted April 20, 2013 I found something on the forum that maybe helped me a bit. Can this work? addEventHandler("onPlayerLogin", root, function(_, account) if not getAccountData(account, "FirstTime") then setElementPosition ( player, x, y, z ) setPlayerTeam ( player, "team" ) setElementModel ( player, 1 ) givePlayerMoney ( player, 1000 ) setAccountData(account, "FirstTime", true) end end ) That should work, you just have no "player" variable declared, use source instead. Link to comment
TAPL Posted April 21, 2013 Share Posted April 21, 2013 It will be better if you use spawnPlayer instead of setElementPosition and setPlayerTeam and setElementModel. For the team, you will need to get the team element, use getTeamFromName to get the team element from team name or the variable of the team if it was in same resource. Link to comment
Adde Posted April 21, 2013 Author Share Posted April 21, 2013 Aaah, thx guys. Now it works perfectly! 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