unknooooown Posted June 14, 2011 Share Posted June 14, 2011 (edited) Hi. Wauw.. My 2'nd topic of the day.. Hope I dont make a habit out of this! I have been trying to solve a problem for about 5 hours now. I have asked a few people that have some Lua experience, but I still have no idea how to fix the problem. I have used Google and MTA.Wiki as much as I can, so I have to turn to you guys once again! My problem: I got a script where I want to give the player a certain amount of money, which is defined in a guiCreateEdit box. The function on the serverside, gets the amount of money the player shall get, from the clientside guiCreateEdit. ( Hope this makes sense) But when I run the script I keep getting the error: WARNING: Bad arguement @ 'givePlayerMoney' I'm sure its something very basic that I am missing. I am still new at this and learning! I have outlined the areas in the scripts that needs to be looked at.. Client: -- Creates the admin window -- function createAdminControlWindow() showCursor(true) local X = 0.375 local Y = 0.375 local Width = 0.55 local Height = 0.55 wdwAdminControl = guiCreateWindow(X, Y, Width, Height, "Admin Control Window", true) X = 0.0800 Y = 0.10 Width = 0.15 Height = 0.08 guiCreateLabel(X, Y, Width, Height, "Player Options:", true, wdwAdminControl) -- Slay the player -- Y = 0.20 slayPlayerButton = guiCreateButton(X, Y, Width, Height, "Slay Player", true, wdwAdminControl) addEventHandler("onClientGUIClick", slayPlayerButton, slayPlayerFunction, false) ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ -- Give player X money -- Y = 0.30 giveMoneyButton = guiCreateButton(X, Y, Width, Height, "Give Money", true, wdwAdminControl) addEventHandler("onClientGUIClick", giveMoneyButton, givePlayerMoneyFunction, false) Y = 0.40 giveMoneyEdit = guiCreateEdit(X, Y, Width, Height, "", true, wdwAdminControl) ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ -- Find Player Position -- X = 0.750 Y = 0.10 playerPositionButton = guiCreateButton(X, Y, Width, Height, "Get Player Pos", true, wdwAdminControl) addEventHandler("onClientGUIClick", playerPositionButton, playerPositionFunction, false) Y = 0.20 guiCreateLabel(X, Y, Width, Height, "X: ", true, wdwAdminControl) Y = 0.26 guiCreateLabel(X, Y, Width, Height, "Y: ", true, wdwAdminControl) Y = 0.32 guiCreateLabel(X, Y, Width, Height, "Z: ", true, wdwAdminControl) X = 0.800 Y = 0.20 pX = guiCreateLabel(X, Y, Width, Height, "Pos", true, wdwAdminControl) Y = 0.26 pY = guiCreateLabel(X, Y, Width, Height, "Pos", true, wdwAdminControl) Y = 0.32 pZ = guiCreateLabel(X, Y, Width, Height, "Pos", true, wdwAdminControl) -- Set new Player Position -- X = 0.750 Y = 0.42 setPlayerPositionButton = guiCreateButton(X, Y, Width, Height, "Set New Pos", true, wdwAdminControl) addEventHandler("onClientGUIClick", setPlayerPositionButton, setPlayerPositionFunction, false) Y = 0.52 guiCreateLabel(X, Y, Width, Height, "X: ", true, wdwAdminControl) Y = 0.58 guiCreateLabel(X, Y, Width, Height, "Y: ", true, wdwAdminControl) Y = 0.64 guiCreateLabel(X, Y, Width, Height, "Z: ", true, wdwAdminControl) X = 0.800 Y = 0.52 Height = 0.05 npX = guiCreateEdit(X, Y, Width, Height, "", true, wdwAdminControl) Y = 0.58 npY = guiCreateEdit(X, Y, Width, Height, "", true, wdwAdminControl) Y = 0.64 npZ = guiCreateEdit(X, Y, Width, Height, "", true, wdwAdminControl) end -- Get Player X,Y,Z, Position -- function playerPositionFunction(thePlayer) local x,y,z = getElementPosition(getLocalPlayer()) guiSetText (pX, x) guiSetText (pY, y) guiSetText (pZ, z) guiSetText (npX, x) guiSetText (npY, y) guiSetText (npZ, z) end -- Set New Player X,Y,Z Position -- function setPlayerPositionFunction() local npX = guiGetText (npX) local npY = guiGetText (npY) local npZ = guiGetText (npZ) triggerServerEvent("movePlayerToPosition",getLocalPlayer(), npX, npY, npZ) end -- Slay The Player -- function slayPlayerFunction() triggerServerEvent("slayPlayer",getLocalPlayer(), getLocalPlayer()) end ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ -- Give The Player X Money -- function givePlayerMoneyFunction() local xAmount = guiGetText (giveMoneyEdit) triggerServerEvent("giveMoney", getLocalPlayer(), xAmount) end ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ function closeAdminControlWindow() guiSetVisible(wdwAdminControl, false) showCursor(false) end addCommandHandler("aO", createAdminControlWindow) addCommandHandler("aC", closeAdminControlWindow) Server: -- Spawn Player on join -- function joinHandler( theplayer ) local x = 1959.55 local y = -1714.46 local z = 18 spawnPlayer(source, x, y, z) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("#FFFF66Welcome to the server", getRootElement(), 255, 0, 0, true) end -- Get Player X,Y,Z positions with /myPos command -- function getPlayerPosition(thePlayer, command) local x,y,z = getElementPosition(thePlayer) outputChatBox("#FF0000--- Your X, Y, Z positions are: ---", getRootElement(), 255, 0, 0, true) outputChatBox("X: " .. x) outputChatBox("Y: " .. y) outputChatBox("Z: " .. z) end -- Moved the player to new position, defined in gui.lua -- function moveThePlayer(npX,npY,npZ) spawnPlayer(source,npX,npY,npZ) setCameraTarget(source,source) end -- Slay the player, triggered in gui.lua -- function slayPlayer(sourcePlayer) killPed (sourcePlayer, sourcePlayer) end ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ -- Give the Player money, triggered in gui.lua function giveMoney ( source, xAmount ) givePlayerMoney ( thePlayer, xAmount ) end ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ addEventHandler("onPlayerJoin", getRootElement(), joinHandler) addCommandHandler("myPos", getPlayerPosition) addEvent("movePlayerToPosition",true) addEventHandler("movePlayerToPosition",root,moveThePlayer) addEvent("slayPlayer",true) addEventHandler("slayPlayer",root,killPed) addEvent("giveMoney",true) addEventHandler("giveMoney", getRootElement(), giveMoney) I hope someone can help me solve the problem, and teach me something too! If you read this, TY for looking Edited June 14, 2011 by Guest Link to comment
Castillo Posted June 14, 2011 Share Posted June 14, 2011 -- Spawn Player on join -- function joinHandler( theplayer ) local x = 1959.55 local y = -1714.46 local z = 18 spawnPlayer(source, x, y, z) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("#FFFF66Welcome to the server", getRootElement(), 255, 0, 0, true) end -- Get Player X,Y,Z positions with /myPos command -- function getPlayerPosition(thePlayer, command) local x,y,z = getElementPosition(thePlayer) outputChatBox("#FF0000--- Your X, Y, Z positions are: ---", getRootElement(), 255, 0, 0, true) outputChatBox("X: " .. x) outputChatBox("Y: " .. y) outputChatBox("Z: " .. z) end -- Moved the player to new position, defined in gui.lua -- function moveThePlayer(npX,npY,npZ) spawnPlayer(source,npX,npY,npZ) setCameraTarget(source,source) end -- Slay the player, triggered in gui.lua -- function slayPlayer(sourcePlayer) killPed (sourcePlayer, sourcePlayer) end ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ -- Give the Player money, triggered in gui.lua function giveMoney ( xAmount ) givePlayerMoney ( source, tonumber(xAmount) ) end ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ addEventHandler("onPlayerJoin", getRootElement(), joinHandler) addCommandHandler("myPos", getPlayerPosition) addEvent("movePlayerToPosition",true) addEventHandler("movePlayerToPosition",root,moveThePlayer) addEvent("slayPlayer",true) addEventHandler("slayPlayer",root,killPed) addEvent("giveMoney",true) addEventHandler("giveMoney", getRootElement(), giveMoney) Link to comment
unknooooown Posted June 14, 2011 Author Share Posted June 14, 2011 -- Spawn Player on join -- function joinHandler( theplayer ) local x = 1959.55 local y = -1714.46 local z = 18 spawnPlayer(source, x, y, z) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("#FFFF66Welcome to the server", getRootElement(), 255, 0, 0, true) end -- Get Player X,Y,Z positions with /myPos command -- function getPlayerPosition(thePlayer, command) local x,y,z = getElementPosition(thePlayer) outputChatBox("#FF0000--- Your X, Y, Z positions are: ---", getRootElement(), 255, 0, 0, true) outputChatBox("X: " .. x) outputChatBox("Y: " .. y) outputChatBox("Z: " .. z) end -- Moved the player to new position, defined in gui.lua -- function moveThePlayer(npX,npY,npZ) spawnPlayer(source,npX,npY,npZ) setCameraTarget(source,source) end -- Slay the player, triggered in gui.lua -- function slayPlayer(sourcePlayer) killPed (sourcePlayer, sourcePlayer) end ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ -- Give the Player money, triggered in gui.lua function giveMoney ( xAmount ) givePlayerMoney ( source, tonumber(xAmount) ) end ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------ addEventHandler("onPlayerJoin", getRootElement(), joinHandler) addCommandHandler("myPos", getPlayerPosition) addEvent("movePlayerToPosition",true) addEventHandler("movePlayerToPosition",root,moveThePlayer) addEvent("slayPlayer",true) addEventHandler("slayPlayer",root,killPed) addEvent("giveMoney",true) addEventHandler("giveMoney", getRootElement(), giveMoney) Ty Snake. I have also tried that earlier today, and it gives me the following error: WARNING: RL\playerSettings.lua:34: Bad argument @ 'givePlayerMoney' There is something on line 34 thats totally messed up, but I just cant see what it is. Link to comment
Castillo Posted June 14, 2011 Share Posted June 14, 2011 Have you copied my latest code? you can see that I changed something else. Link to comment
unknooooown Posted June 14, 2011 Author Share Posted June 14, 2011 Have you copied my latest code? you can see that I changed something else. Thank you very much Snake! Could you please tell me exactly what I did wrong and what you edited? I notice the changes in the function, but other than that? Again thank you! Link to comment
Castillo Posted June 14, 2011 Share Posted June 14, 2011 Well, your problem was a really small one, you we'rent passing thePlayer element at all, so I just changed thePlayer to source, source = the player who triggered the event. Link to comment
unknooooown Posted June 14, 2011 Author Share Posted June 14, 2011 Well, your problem was a really small one, you we'rent passing thePlayer element at all, so I just changed thePlayer to source, source = the player who triggered the event. I see Thanks a lot. It really helped me Link to comment
Castillo Posted June 14, 2011 Share Posted June 14, 2011 No problem, fell free to ask for help in this forum whenever you need it . Link to comment
unknooooown Posted June 14, 2011 Author Share Posted June 14, 2011 Trust me.. There is a lot more of me to come! 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