Dzsozi (h03) Posted April 18, 2014 Share Posted April 18, 2014 Hello! So today I made a script which is about robbing a shop. Everything works fine, except a click function. When I click on 'Rob' nothing happens, but I triggered a server side event which is gives you random money between 30 and 70k. But nothing. Can someone help me please? Here's this part of the code ("kassza" means cash register): -- client kassza = createObject ( 1514, 1924.4658203125, -1787.0101318359, 13.8, 180, 180, 0 ) setElementData(kassza, "message", "Kassza") wRightClick = nil bKirabol = nil bCloseKassza = nil ax, ay = nil localPlayer = getLocalPlayer() kassza = nil function kirablas() if (source==bKirabol) then triggerServerEvent("onKasszaKirablasa", getLocalPlayer()) end end function clickKassza(button, state, absX, absY, wx, wy, wz, element) if getElementData(getLocalPlayer(), "exclusiveGUI") then return end if element and getElementType( element ) == "object" and button == "right" and state == "down" and getElementModel(element) == 1514 then local x, y, z = getElementPosition(localPlayer) if getDistanceBetweenPoints3D(x, y, z, wx, wy, wz) <= 3 then if (wRightClick) then hideKassza() end showCursor(true) ax = absX ay = absY kassza = element showKassza() end end end addEventHandler("onClientClick", getRootElement(), clickKassza, true) function showKassza() wRightClick = guiCreateWindow(ax, ay, 150, 100, "Kassza", false) bKirabol = guiCreateButton(0.05, 0.23, 0.87, 0.2, "Kassza kirablása", true, wRightClick) addEventHandler("onClientGUIClick", bKirabol, kirablas, false) bCloseKassza = guiCreateButton(0.05, 0.63, 0.87, 0.2, "Menü bezárása", true, wRightClick) addEventHandler("onClientGUIClick", bCloseKassza, hideKassza, false) end function hideKassza() if (isElement(bCloseKassza)) then destroyElement(bCloseKassza) end bCloseKassza = nil if (isElement(wRightClick)) then destroyElement(wRightClick) end wRightClick = nil ax = nil ay = nil showCursor(false) triggerEvent("cursorHide", localPlayer) setElementData(localPlayer, "exclusiveGUI", false, false) end -- server addEvent("onKasszaKirablasa", true) addEventHandler("onKasszaKirablasa", getRootElement(), function (jatekos, thePlayer, boltos) exports.global:giveMoney(thePlayer, math.random(30000,70000)) end ) Why is it not working? As I have already mentioned, it should give money between 30000 and 70000 when you click on the button "Kassza kirablása" (it means "Rob"). Link to comment
Moderators IIYAMA Posted April 18, 2014 Moderators Share Posted April 18, 2014 addEvent("onKasszaKirablasa", true) addEventHandler("onKasszaKirablasa", getRootElement(), function () exports.global:giveMoney(source, math.random(30000,70000)) end ) Because you don't send parameters, you only send the source. Link to comment
Dzsozi (h03) Posted April 18, 2014 Author Share Posted April 18, 2014 addEvent("onKasszaKirablasa", true) addEventHandler("onKasszaKirablasa", getRootElement(), function () exports.global:giveMoney(source, math.random(30000,70000)) end ) Because you don't send parameters, you only send the source. Thank you very much! Link to comment
Dzsozi (h03) Posted April 18, 2014 Author Share Posted April 18, 2014 Now I have another problem. It's the same, I don't know how to trigger server side event to client side. Can you help me please? I don't know what am I made wrong. Here's a part of the codes: -- server function halAdas (thePlayer) exports.global:giveItem(thePlayer, 149, 1) end addEvent("halKifogas", true) addEventHandler("halKifogas", getRootElement(), halAdas) -- client triggerServerEvent("halKifogas", getLocalPlayer()) What's wrong with my script? I doesn't gives me the item with ID 146. Link to comment
pa3ck Posted April 18, 2014 Share Posted April 18, 2014 -- server function halAdas () exports.global:giveItem(client, 149, 1) end addEvent("halKifogas", true) addEventHandler("halKifogas", getRootElement(), halAdas) Link to comment
Castillo Posted April 18, 2014 Share Posted April 18, 2014 'thePlayer' is not being sent from the client side. function halAdas ( ) exports.global:giveItem(client, 149, 1) end addEvent("halKifogas", true) addEventHandler("halKifogas", getRootElement(), halAdas) Link to comment
Dzsozi (h03) Posted April 18, 2014 Author Share Posted April 18, 2014 Thank you guys, you are awesome! 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