maky55 Posted April 6, 2015 Share Posted April 6, 2015 Hello again. Thinking I might change my name to scripting newb. I'm pretty slow at this. Heres my problem, I want to make it so that if a player logs in and has a certain account name (terminator), he will spawn in SF airpot. But if he has a different account name (maky55) then he spawns at ls docks. Here are the 3 scripts I have: Server 1: local thePlayer = source function registerHandler(username, password) local account = getAccount ( username ) if ( not account ) then local register = addAccount(username, password) if ( register ) then outputChatBox("You have registered your account", source) end end end addEvent("submitRegister", true) addEventHandler("submitRegister", getRootElement(), registerHandler) function loginHandler(username, password) local account = getAccount(username, password) if ( account ) then local loggin = logIn(source, account, password) if ( loggin ) then triggerClientEvent(source, "hideLoginWindow", source) end else outputChatBox("Invalid username or password!",source) end end addEvent("submitLogin", true) addEventHandler("submitLogin", getRootElement(), loginHandler) Server 2: local posX1, posY1, posZ1 = 2584.9523925781, -2209.318359375, 1.9927320480347 local posX2, posY2, posZ2 = -1370.1851806641, -205.50845336914, 6 function joinHandler1() local account = getPlayerAccount(source) local accountName = getAccountName(account) if accountName == "maky55" then spawnPlayer(source, posX1, posY1, posZ1) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerLogin", getRootElement(), joinHandler1) end function joinHandler2() local account = getPlayerAccount(source) local accountName = getAccountName(account) if accountName == "terminator" then spawnPlayer(source, posX2, posY2, posZ2) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerLogin", getRootElement(), joinHandler2) end function deathHandler1() local account = getPlayerAccount(source) local accountName = getAccountName(account) if accountName == "maky55" then spawnPlayer(source, posX1, posY1, posZ1) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler1) end function deathHandler2() local account = getPlayerAccount(source) local accountName = getAccountName(account) if accountName == "terminator" then spawnPlayer(source, posX2, posY2, posZ2) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler2) end Client: local playerName = getPlayerName(localPlayer) local guiElements = { } function clientSubmitLogin() local username = guiGetText(guiElements["edit_user"]) local password = guiGetText(guiElements["edit_pass"]) if ( username ~= "" and password ~= "" ) then triggerServerEvent("submitLogin", localPlayer, username, password) else outputChatBox("Please enter a username and password.") end end function clientSubmitRegister() local username = guiGetText(guiElements["edit_user"]) local password = guiGetText(guiElements["edit_pass"]) if ( username ~= "" and password ~= "" ) then triggerServerEvent("submitRegister", localPlayer, username, password) else outputChatBox("Please enter a username and password to create an account.") end end function createLoginWindow() guiElements["login_window"] = guiCreateWindow(0.375, 0.375, 0.25, 0.25, "Please enter your Username and Password", true) guiCreateLabel(0.0825, 0.225, 0.25, 0.25, "Username", true, guiElements["login_window"]) guiCreateLabel(0.0825, 0.425, 0.25, 0.25, "Password", true, guiElements["login_window"]) guiElements["edit_user"] = guiCreateEdit(0.415, 0.2, 0.5, 0.15, "", true, guiElements["login_window"]) guiElements["edit_pass"] = guiCreateEdit(0.415, 0.4, 0.5, 0.15, "", true, guiElements["login_window"]) guiEditSetMasked ( guiElements["edit_pass"], true ) guiEditSetMaxLength(guiElements["edit_user"], 20) guiEditSetMaxLength(guiElements["edit_pass"], 20) guiElements["register_button"] = guiCreateButton(0.715, 0.7, 0.25, 0.20, "Register", true, guiElements["login_window"]) guiElements["login_button"] = guiCreateButton(0.415, 0.7, 0.25, 0.20, "Log In", true, guiElements["login_window"]) addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitLogin, false) addEventHandler("onClientGUIClick", guiElements["register_button"], clientSubmitRegister, false) end addEventHandler("onClientResourceStart", resourceRoot, function () createLoginWindow() outputChatBox("Welcome to My MTA:SA Server, please log in.") showCursor(true) guiSetInputEnabled(true) end ) function hideLoginWindow() guiSetInputEnabled(false) showCursor(false) if ( isElement ( guiElements["login_window"] ) ) then destroyElement ( guiElements["login_window"] ) end end addEvent("hideLoginWindow", true) addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) the second code is the one that is the most intrest. Instaid of spawning the player with the account name 'terminator' at SF airport and 'maky55' at the docks, it just stays on a black screen. Link to comment
Enargy, Posted April 7, 2015 Share Posted April 7, 2015 you wrote wrong on finishing the function -- server 2 end addEventHandler(...) end it is end end addEventHandler(...) EDIT Instaid of spawning the player with the account name 'terminator' at SF airport and 'maky55' at the docks, it just stays on a black screen. I don't know if i understood but are you trying to do something like this? function joinHandler1(_, currentAccount) local accountName = getAccountName(currentAccount) if accountName == "maky55" then spawnPlayer(source, posX1, posY1, posZ1) fadeCamera(source, true) setCameraTarget(source, source) elseif accountName == "terminator" then spawnPlayer(source, posX2, posY2, posZ2) fadeCamera(source, true) setCameraTarget(source, source) else spawnPlayer(X_POSITION, Y_POSITION, Z_POSITION) -- Your coordinates where the player gets spawned fadeCamera(source, true) setCameraTarget(source, source) end end addEventHandler("onPlayerLogin", getRootElement(), joinHandler1) Link to comment
maky55 Posted April 7, 2015 Author Share Posted April 7, 2015 Yeah thats what I'm trying to do. Ill try your script, thanks. Edit: I've tested the script, and it works just as I wanted to. It looks alot easier then I was trying to do. Thank you. 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