Castillo Posted June 11, 2011 Posted June 11, 2011 To get a player's name you need to use getPlayerName San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
JR10 Posted June 11, 2011 Posted June 11, 2011 he wanted to get the name from a gui Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 11, 2011 Author Posted June 11, 2011 It's still not working, when I press Change the GUI is still open and My Nick/Name doesn't change. here is my script: Client-side function afterLogin() nickName() if (GUIEditor_Window[3] ~= nil) then guiSetVisible(GUIEditor_Window[3], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",change_but, changeNick, false) addEventHandler("onClientGUIClick",leave_but, DONE, false) end addEvent ( "after",true) addEventHandler ( "after", getRootElement(), afterLogin) function changeNick() if (button == "left") then local nickname = guiGetText(GUIEditor_Edit[3]) if nickName then triggerServerEvent ("changeNick", getRootElement(), nickname) else outputChatBox ("Please enter a NICKNAME.") cancelEvent() end end end Server-side function Nickname() setPlayerName( client, nickName) outputChatBox ( "YOUR HAVE CHANGED YOUR NICKNAME!", client, 0, 255, 0) triggerClientEvent ( "Done", getRootElement()) end addEvent ( "changeNick",true) addEventHandler ( "changeNick", getRootElement(), Nickname) then it goes back to the Client-side: function DONE() -- hide the gui, hide the cursor and return control to the player guiSetVisible(GUIEditor_Window[2], false) guiSetVisible(GUIEditor_Window[1], false) guiSetVisible(GUIEditor_Window[3], false) --guiSetVisible(back_Ground, false) showCursor(false) guiSetInputEnabled(false) --triggerServerEvent ( "onPlayer", getRootelement()) end addEvent("Done",true) addEventHandler("Done", getRootElement(), DONE) My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
JR10 Posted June 11, 2011 Posted June 11, 2011 function Nickname(nickName) setPlayerName( client, nickName) outputChatBox ( "YOUR HAVE CHANGED YOUR NICKNAME!", client, 0, 255, 0) triggerClientEvent ( "Done", getRootElement()) end addEvent ( "changeNick",true) addEventHandler ( "changeNick", getRootElement(), Nickname) i added the nickName in the function arguments and at your change nick function client side you better add if nickname ~= '' so he doesn't just leave it blank he must type something in it. and you must do this triggerClientEvent(thePlayerToTriggerFot, 'event', getRootElement()) or the event will trigger for all players and im sure you dont want this in a login gui Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 11, 2011 Author Posted June 11, 2011 it still doesn't work though After when I put in the Nickname I want and press the button to change it, nothing happens. Do you want me to post my whole Login GUI script? My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
SDK Posted June 11, 2011 Posted June 11, 2011 If there's an error in your script, but you don't know where, use outputChatBox or outputDebugString to know where it stops. So add some texts like 'Player clicked CHANGE button' , 'client sending event to server', 'server received event from client with name: your_name', etc ... You can even add the values from your variables so you know where they might get 'lost'. This is one way to debug broken scripts, more examples and explanation: https://wiki.multitheftauto.com/wiki/Deb ... s_executed Learn Lua - Learn to script - GUI scripting Scripter tools - Find/fix errors yourself(!) Don't pm me for scripting help, keep it for the Scripting subforum!
JR10 Posted June 11, 2011 Posted June 11, 2011 function afterLogin() nickName() if (GUIEditor_Window[3] ~= nil) then guiSetVisible(GUIEditor_Window[3], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",change_but, changeNick, false) addEventHandler("onClientGUIClick",leave_but, DONE, false) end nickName() what is this? is that a function? you didnt post it you may post your same code again with the changes but no need for the login script Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 11, 2011 Author Posted June 11, 2011 It's the function for the GUI window. Client-side: --THE GUI----------------- function nickName() GUIEditor_Window[3] = guiCreateWindow(191,297,425,153,"Nickname",false) -- Buttons change_but = guiCreateButton(38,106,137,38,"CHANGE",false,GUIEditor_Window[3]) leave_but = guiCreateButton(265,107,122,37,"LEAVE",false,GUIEditor_Window[3]) -- Edit GUIEditor_Edit[3] = guiCreateEdit(93,60,262,31,"",false,GUIEditor_Window[3]) -- LABEL guiCreateLabel(38,32,373,22,"Please enter your nickname and press CHANGE or press LEAVE",false,GUIEditor_Window[3]) end --SCRIPT------ function afterLogin() nickName() if (GUIEditor_Window[3] ~= nil) then guiSetVisible(GUIEditor_Window[3], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",change_but, changeNick, false) addEventHandler("onClientGUIClick",leave_but, DONE, false) end addEvent ( "after",true) addEventHandler ( "after", getRootElement(), afterLogin) function changeNick() if (button == "left") then local nickname = guiGetText(GUIEditor_Edit[3]) if nickname ~= '' then triggerServerEvent ("changeNick", getRootElement(), nickname) else outputChatBox ("Please enter a NICKNAME.") cancelEvent() end end end Server-side function Nickname(nickName) if (nickname ~= nil and nickname ~= "") then setPlayerName( client, nickname) outputChatBox ( "YOU HAVE CHANGED YOUR NICKNAME!", client, 0, 255, 0) triggerClientEvent(thePlayerToTriggerFot, 'event', getRootElement()) triggerClientEvent ( "Done", getRootElement()) else outputChatBox ( "Sorry something is wrong, Please try again later!.",client) cancelEvent() end end addEvent ( "changeNick",true) addEventHandler ( "changeNick", getRootElement(), Nickname) My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
JR10 Posted June 11, 2011 Posted June 11, 2011 1- remove all the cancelEvent functions from your code its useless its for a diffrent thing 2- triggerClientEvent(thePlayerToTriggerFot, 'event', getRootElement()) what did i tell you about copy pasting every thing? that was just to explain how to trigger it for one player and its useless unless you edit it triggerClientEvent (client,"Done", getRootElement()) 3- in your nickName() function you didnt hide the gui when you create a gui its visible by default so you hide it then show it again function nickName() GUIEditor_Window[3] = guiCreateWindow(191,297,425,153,"Nickname",false) -- Buttons change_but = guiCreateButton(38,106,137,38,"CHANGE",false,GUIEditor_Window[3]) leave_but = guiCreateButton(265,107,122,37,"LEAVE",false,GUIEditor_Window[3]) -- Edit GUIEditor_Edit[3] = guiCreateEdit(93,60,262,31,"",false,GUIEditor_Window[3]) -- LABEL guiCreateLabel(38,32,373,22,"Please enter your nickname and press CHANGE or press LEAVE",false,GUIEditor_Window[3]) guiSetVisible(GUIEditor_Window[3], false) end 4- function Nickname(nickName) if (nickname ~= nil and nickname ~= "") then setPlayerName( client, nickname) outputChatBox ( "YOU HAVE CHANGED YOUR NICKNAME!", client, 0, 255, 0) triggerClientEvent(thePlayerToTriggerFot, 'event', getRootElement()) triggerClientEvent ( "Done", getRootElement()) else outputChatBox ( "Sorry something is wrong, Please try again later!.",client) cancelEvent() end end its nickName not nickname should be like this function Nickname(nickName) if (nickName ~= nil and nickName ~= "") then setPlayerName( client, nickName) outputChatBox ( "YOU HAVE CHANGED YOUR NICKNAME!", client, 0, 255, 0) triggerClientEvent ( "Done", getRootElement()) else outputChatBox ( "Sorry something is wrong, Please try again later!.",client) end end 5- you really need to stop copy pasting and start to learn https://wiki.multitheftauto.com/wiki/Main_Page Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 11, 2011 Author Posted June 11, 2011 I just copy and pasted 1 time plus you told me at the top to copy it, and where else did I copy and paste? AND IT STILL DOESN'T WORK! My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
JR10 Posted June 11, 2011 Posted June 11, 2011 i never told you to copy and paste did you do what i told you in the last post? Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 11, 2011 Author Posted June 11, 2011 nevermind I found the problem, I just needed to add the button in the function, here: function Nick() if (button == "left") then local nickName = guiGetText(GUIEditor_Edit[3]) if nickName ~= '' then triggerServerEvent ("changeNick", getRootElement(), nickName) else outputChatBox ("Please enter a NICKNAME.") end end end NOW: function Nick(button) if (button == "left") then local nickName = guiGetText(GUIEditor_Edit[3]) if nickName ~= '' then triggerServerEvent ("changeNick", getRootElement(), nickName) else outputChatBox ("Please enter a NICKNAME.") end end end Thanks anyway. My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
Jaysds1 Posted June 11, 2011 Author Posted June 11, 2011 I need help with a Spawn/Logout GUI, When the person presses the spawn button it's suppose to spawn them but it doesn't , and when the person presses the logout button it's suppose to log them out but it doesn't here is my script Client-side: function spawn() CreateSpawn() -- if the GUI was successfully created, then show the GUI to the player if (swnwdw ~= nil) then guiSetVisible(swnwdw, true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",GUIEditor_Button[1], spawnHere, false) addEventHandler("onClientGUIClick",GUIEditor_Button[2], logOut,false) end addEvent("spawn",true) addEventHandler("spawn", getRootElement(), spawn) function logOut(button) if (button == "left") then triggerServerEvent("logOut", getRootElement()) end end function spawnHere(button) if (button == "left") then triggerServerEvent("spawnHere", getRootElement()) end end Server-side: function logOut() local source = getPlayerAccount (client) logOut( source ) -- Log them out. end addEvent("logOut",true) addEventHandler("logOut", getRootElement(), logOut) function spawnHere() spawnPlayer (source, x, y, z, 0, math.random (1,288), 0, 0) end addEvent("spawnHere",true) My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
JR10 Posted June 11, 2011 Posted June 11, 2011 there is a logOut function already so change its name also the event change its name and dont make the events same name as functions. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 11, 2011 Author Posted June 11, 2011 it say's [2011-06-11 18:56:14] WARNING: JS\server.lua:173: Bad 'player' pointer @ 'logOut'(1) My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
JR10 Posted June 11, 2011 Posted June 11, 2011 there is a function called logOut so you cant use it on your custom functions change your logOut function name and event and post the line 173 i think its because what i said you cant name a function the same name as a function that already exists Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 11, 2011 Author Posted June 11, 2011 ok here: logOut( source ) -- Log them out. My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
JR10 Posted June 11, 2011 Posted June 11, 2011 source is a account not a player logOut use a player so do this logOut(client) Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 11, 2011 Author Posted June 11, 2011 thanks Now I need help with the spawn part. My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
JR10 Posted June 11, 2011 Posted June 11, 2011 (edited) function spawnHere() spawnPlayer (source, x, y, z, 0, math.random (1,288), 0, 0) end addEvent("spawnHere",true) you forgot addEventHandler function spawnHere() spawnPlayer (source, x, y, z, 0, math.random (1,288), 0, 0) end addEvent("spawnHere",true) addEventHandler("spawnHere", root, spawnHere) also function spawnHere() spawnPlayer (source, x, y, z, 0, math.random (1,288), 0, 0) end addEvent("spawnHere",true) addEventHandler("spawnHere", root, spawnHere) where is the source and x, y, z are defined change source to client and define x, y, z function spawnHere() local x, y, z = coordX, coordY, coordZ spawnPlayer (client, x, y, z, 0, math.random (1,288), 0, 0) end addEvent("spawnHere",true) addEventHandler("spawnHere", root, spawnHere) and ofc change coordX,Y,Z to your coordinates. if this didnt work change the name of the event of the function so they are not the same. good luck. EDIT: It is recommended to create all GUI when the client resource starts, hide them, and show them to the player later when needed. Edited June 12, 2011 by Guest Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 12, 2011 Author Posted June 12, 2011 it didn't work but after I fixed it. I needed to replace source to client: spawnPlayer (source, x, y, z, 0, math.random (1,288), 0, 0) replaced spawnPlayer (client, x, y, z, 0, math.random (1,288), 0, 0) EDIT: OK My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
JR10 Posted June 12, 2011 Posted June 12, 2011 i edited my post and told you to do so then you replied , sorry Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Jaysds1 Posted June 12, 2011 Author Posted June 12, 2011 it's ok. My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
Jaysds1 Posted June 12, 2011 Author Posted June 12, 2011 How do you make a resource, check if it's an admin that logged in? My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
JR10 Posted June 12, 2011 Posted June 12, 2011 if isObjectInACLGroup ( "user." .. playerName, aclGetGroup ( "Admin" ) ) then thats how to check if the player is an admin Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
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