Dzsozi (h03) Posted June 3, 2014 Share Posted June 3, 2014 Hello guys! I have the basketball that you can download from community and I want to edit this a little bit. I want it work with gui, so you can pickup the ball by clicking on a button. My only problem is that it doesn't want to work in the way I want to and I can't fix it. Where is the problem? When the button appears and if I click it nothing happens. Can anybody help me please? Client side script: local x, y = guiGetScreenSize() function drawNotice( ) pickupBtn = guiCreateButton(x-208, y-215, 50, 50, "Pick up", false) addEventHandler("onClientGuiClick", pickupBtn, pickup) end addEvent("notify:basket", true) addEventHandler("notify:basket", getLocalPlayer(), drawNotice) function removeNotice( ) guiSetVisible(pickupBtn, false) end addEvent("removenotify:basket", true) addEventHandler("removenotify:basket", getLocalPlayer(), removeNotice) function pickup( thePlayer ) triggerServerEvent(root, "pickupBall", thePlayer) end The pickupBall function from the server side script: function pickupBall( thePlayer, commandName ) if (isElementWithinColShape(thePlayer, ballCol1) or isElementWithinColShape(thePlayer, ballCol2) or isElementWithinColShape(thePlayer, ballCol3) or isElementWithinColShape(thePlayer, ballCol4)) then exports.global:applyAnimation( thePlayer, "BSKTBALL", "BBALL_pickup", 1000, false, true, true) exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "throwing:ball", 0, true) setTimer(function() local playerX, playerY, playerZ = getElementPosition( thePlayer ) local basketball = createObject(3065, playerX, playerY, playerZ) ball[thePlayer] = basketball -- Place the ball near his right hand attachElements( ball[thePlayer], thePlayer, 0.40, .30, -0.10) -- Animation exports.global:applyAnimation( thePlayer, "BSKTBALL", "BBALL_walk", -1, true, true, true) -- He is playing.. exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "playing:ball", 1, true) -- Start dribbling dribbleDown( thePlayer ) -- Movement binds bindKey(thePlayer, "a", "down", turnLeft) bindKey(thePlayer, "a", "up", stopLeft) bindKey(thePlayer, "d", "down", turnRight) bindKey(thePlayer, "d", "up", stopRight) bindKey(thePlayer, "w", "down", run) bindKey(thePlayer, "s", "down", walk) -- Shoot binds bindKey(thePlayer, "mouse2", "down", shootShort) bindKey(thePlayer, "mouse1", "down", shootMedium) bindKey(thePlayer, "h", "down", shootLong) -- Pass bindKey(thePlayer, "z", "down", passBall) bindKey(thePlayer, "x", "down", passStance) -- Run/walk identifiers exports['anticheat-system']:changeProtectedElementDataEx(thePlayer, "basketball:walk", 1, true) end, 1500, 1) end end addEventHandler("pickupBall", true) addEventHandler("pickupBall", thePlayer, pickupBall) So how can I make it work with gui? Thanks in advance! Link to comment
Atton Posted June 3, 2014 Share Posted June 3, 2014 There is a big problem here you are trying to trigger a server event that is an element. Root is an element not a server event the player should be localPlayer. function pickup( thePlayer ) triggerServerEvent(root, "pickupBall", thePlayer) end So try this. function pickup() triggerServerEvent( "pickupBall", localPlayer, localPlayer) end Link to comment
Dzsozi (h03) Posted June 3, 2014 Author Share Posted June 3, 2014 It's still not working. Link to comment
Den. Posted June 3, 2014 Share Posted June 3, 2014 The event name is "onClientGUIClick" and not "onClientGuiClick". You also didn't need to pass any arguments to the pickup function, because the player who clicked the button would be localPlayer in all cases. Use this client-side code. local x, y = guiGetScreenSize() local pickupBtn function drawNotice( ) pickupBtn = guiCreateButton(x-208, y-215, 50, 50, "Pick up", false) addEventHandler("onClientGUIClick", pickupBtn, function(button, state) if button == "left" and state == "down" then pickup() end end) end addEvent("notify:basket", true) addEventHandler("notify:basket", getLocalPlayer(), drawNotice) function removeNotice( ) guiSetVisible(pickupBtn, false) end addEvent("removenotify:basket", true) addEventHandler("removenotify:basket", getLocalPlayer(), removeNotice) function pickup() triggerServerEvent("pickupBall", localPlayer, localPlayer) end You should also remove commandName from the server-side function arguments, as well as use source in pickupBall instead of sending the localPlayer twice as source and as an argument. EDIT: I think this is also the vG/rG script. Link to comment
Dzsozi (h03) Posted June 4, 2014 Author Share Posted June 4, 2014 It's still not working, I removed commandName from server side function arguments, but still not working. What could be the problem? Link to comment
Den. Posted June 4, 2014 Share Posted June 4, 2014 Line 49 in your server-side snippet. addEventHandler("pickupBall", true) should be corrected to: addEvent("pickupBall", true) You should also type /debugscript 3, ingame for info and errors. Link to comment
TAPL Posted June 4, 2014 Share Posted June 4, 2014 We don't give support with leaked scripts. Link to comment
Woovie Posted June 4, 2014 Share Posted June 4, 2014 I locked it, but please make your report a little more informative next time, also I would like to know what it is a leak from, more than just a leak. Link to comment
Recommended Posts