Hugo_Almeidowski Posted January 28, 2019 Share Posted January 28, 2019 So, I made this script that whenever I type /armas, it opens a window with two text box, one to input a weapon ID and another to input the bullets (this one is still deactivated). When I press the button, it trigger a server event to give the player a weapon, but the problem is that I can only give weapons to root, if I try to give it to the player, it returns: Bad Argument @ expect element at argument 1, got nil after the giveWeapon function. I tried multiple ways but I can't seem to make it work CLIENT: DGS = exports.dgs function armasJanela() janelaArmas = DGS:dgsCreateWindow (0.015, 0.18, 0.10, 0.15, "Armas", true) DGS:dgsWindowSetCloseButtonEnabled(janelaArmas, false) showCursor(true) DGS:dgsSetInputMode("no_binds_when_editing") DGS:dgsWindowSetSizable(janelaArmas, false) IDArma = DGS:dgsCreateEdit(0.1, 0.09, 0.8, 0.20, "ID da Arma [0-46]", true, janelaArmas) guiEditSetMaxLength (IDArma, 20) Balas = DGS:dgsCreateEdit(0.1, 0.33, 0.8, 0.20, "Balas [0-10000]", true, janelaArmas) guiEditSetMaxLength (Balas, 6) buttonC = DGS:dgsCreateButton(0.53, 0.65, 0.37, 0.20, "Cancelar", true, janelaArmas) addEventHandler ("onDgsMouseClick", buttonC, cancelamentoJanelaArmas) buttonE = DGS:dgsCreateButton(0.1, 0.65, 0.37, 0.20, "Escolher", true, janelaArmas) addEventHandler ("onDgsMouseClick", buttonE, escolhaJanelaArmas) end addCommandHandler("armas", armasJanela) function cancelamentoJanelaArmas() local destruirArmasJanela = DGS:dgsCloseWindow(janelaArmas) destroyElement(destruirArmasJanela) showCursor(false) end function escolhaJanelaArmas() local textoIDArma = DGS:dgsGetText(IDArma) outputChatBox(tostring(textoIDArma)) triggerServerEvent("darArmaClient", resourceRoot, textoIDArma) outputChatBox("Olas") end SERVER: function darArmaClient(textoIDArma) outputChatBox("Ola" ..textoIDArma, player) nomeA = getWeaponNameFromID(textoIDArma) outputChatBox(nomeA) giveWeapon(root, textoIDArma, 999) outputChatBox("Erro") end addEvent("darArmaClient", true) addEventHandler("darArmaClient", root, darArmaClient) If in the event handler I switch root to player, it returns that he is expecting an element. Link to comment
WorthlessCynomys Posted January 28, 2019 Share Posted January 28, 2019 Put the word client to where the root is now. Link to comment
Mr.Loki Posted January 28, 2019 Share Posted January 28, 2019 (edited) in your escolhaJanelaArmas() function change resourceRoot in the triggerServerEvent function to localPlayer. Then in your server code the "source" will be your player. function darArmaClient(textoIDArma) outputChatBox("Ola" ..textoIDArma, getPlayerName(source)) nomeA = getWeaponNameFromID(textoIDArma) outputChatBox(nomeA) giveWeapon(source, textoIDArma, 999) outputChatBox("Erro") end addEvent("darArmaClient", true) addEventHandler("darArmaClient", root, darArmaClient) Edited January 28, 2019 by Mr.Loki 1 Link to comment
Hugo_Almeidowski Posted January 28, 2019 Author Share Posted January 28, 2019 10 minutes ago, Mr.Loki said: in your escolhaJanelaArmas() function change resourceRoot in the triggerServerEvent function to localPlayer. Then in your server code the "source" will be your player. function darArmaClient(textoIDArma) outputChatBox("Ola" ..textoIDArma, getPlayerName(source)) nomeA = getWeaponNameFromID(textoIDArma) outputChatBox(nomeA) giveWeapon(source, textoIDArma, 999) outputChatBox("Erro") end addEvent("darArmaClient", true) addEventHandler("darArmaClient", root, darArmaClient) Thanks! 1 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