fairyoggy Posted May 23, 2019 Share Posted May 23, 2019 --client function HudOpening () local meatn = getElementData(localPlayer, "meat") or 0 dxDrawText("Meat: "..math.floor(meatn).." ед", 1800*x, 750*y, 1670*x, 25*y, tocolor(255, 255, 255, 255), 2, "Arial", "center", "center", false, false, true, true, false) end addEventHandler("onClientRender",root,HudOpening) function initGUI( ) btnOutput = DGS:dgsCreateButton( 0.7, 0.1, 0.2, 0.1, "+", true ) addEventHandler ( "onDgsMouseClick", btnOutput, outputEditBox ) end addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) function outputEditBox ( button, state ) if button == "left" and state == "down" then triggerServerEvent( "m9cko", getLocalPlayer(), 0, 24, 35 ) end end --server function hhh () takePlayerMoney(client,2) setElementData(client, "meat", (getElementData(client, "meat") or 0) + 10) end addEvent("m9cko",true) addEventHandler("m9cko",getRootElement(),hhh) ElementData = meatn When I press the button, it is added +10 (meat) for localplayer Everything works as it should, but how do I bind to some object or marker, or create a separate variable for this ElementData(not localPlayer) local meatn = getElementData(localPlayer, "meat") or 0 I mean Instead "localplayer" Create a variable instead or bind to an object. How to do it? --client local meatn = getElementData(localPlayer, "meat") or 0 --server setElementData(client, "meat", (getElementData(client, "meat") or 0) + 10) I just need instead "localPlayer", "client" create a variable that is not bound to the Localplayer. Link to comment
Moderators IIYAMA Posted May 23, 2019 Moderators Share Posted May 23, 2019 @slapz0r You can use also: root -- attach to the mother element of all elements resourceRoot -- attached to the resource which it is currently executed in local newElement = createElement("elementName") -- attach to a new element of your choice 1 Link to comment
fairyoggy Posted May 23, 2019 Author Share Posted May 23, 2019 59 minutes ago, IIYAMA said: @slapz0r You can use also: root -- attach to the mother element of all elements resourceRoot -- attached to the resource which it is currently executed in local newElement = createElement("elementName") -- attach to a new element of your choice local newElement = createElement("elementName") local meatn = getElementData(localPlayer, "meat") or 0 -- old local meatn = getElementData(elementName, "meat") or 0 -- new -- setElementData(client, "meat", (getElementData(client, "meat") or 0) + 10) -- old with localplayer setElementData(elementName, "meat", (getElementData(elementName, "meat") or 0) + 10) -- new And how to use it correctly? Link to comment
Moderators IIYAMA Posted May 23, 2019 Moderators Share Posted May 23, 2019 (edited) 42 minutes ago, slapz0r said: local newElement = createElement("elementName") local meatn = getElementData(localPlayer, "meat") or 0 -- old local meatn = getElementData(elementName, "meat") or 0 -- new -- setElementData(client, "meat", (getElementData(client, "meat") or 0) + 10) -- old with localplayer setElementData(elementName, "meat", (getElementData(elementName, "meat") or 0) + 10) -- new And how to use it correctly? Use newElement, that is a variable. not elementName which is just a "string". Or in this case an empty variable. Edited May 23, 2019 by IIYAMA 1 Link to comment
fairyoggy Posted May 24, 2019 Author Share Posted May 24, 2019 14 hours ago, IIYAMA said: Use newElement, that is a variable. not elementName which is just a "string". Or in this case an empty variable. I do not understand how I use it to work like for Locaplayer but now for new variable. Link to comment
justn Posted May 24, 2019 Share Posted May 24, 2019 Basically: --Client local newElement = createMarker(0,0,0,"cylinder",1,255,255,255,255) if ( newElement ) then setElementData(newElement, "meat", (getElementData(newElement, "meat") or 0) + 10) end As long as this is client-sided it should work as intended. 1 Link to comment
fairyoggy Posted May 24, 2019 Author Share Posted May 24, 2019 (edited) 1 hour ago, Shux said: Basically: --Client local newElement = createMarker(0,0,0,"cylinder",1,255,255,255,255) if ( newElement ) then setElementData(newElement, "meat", (getElementData(newElement, "meat") or 0) + 10) end As long as this is client-sided it should work as intended. Did as you wrote, and used for display number dxDrawText("Мясо: "..math.floor(meatnz).." ед", 1800*x, 750*y, 1670*x, 25*y, tocolor(255, 255, 255, 255), 2, "Arial", "center", "center", false, false, true, true, false) newElement = createPickup (1322.2575683594,358.23822021484,19.5546875, 3, 2663, 1, 1 ) function HudOpening () local meatn = getElementData(localPlayer, "meat") or 0 local meatnz = getElementData(newElement, "meat") or 0 dxDrawText("Мясо: "..math.floor(meatnz).." ед", 1800*x, 750*y, 1670*x, 25*y, tocolor(255, 255, 255, 255), 2, "Arial", "center", "center", false, false, true, true, false) end addEventHandler("onClientRender",root,HudOpening) local player = getLocalPlayer() function initGUI( ) --showCursor(true) btnOutput = DGS:dgsCreateButton( 0.7, 0.1, 0.2, 0.1, "+", true ) addEventHandler ( "onDgsMouseClick", btnOutput, outputEditBox ) end addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) function outputEditBox ( button, state) if button == "left" and state == "down" then if (newElement) then setElementData(newElement, "meat", (getElementData(newElement, "meat") or 0) + 10) --triggerServerEvent( "m9cko", root, 0, 24, 35 ) end end end Not working, what am I doing wrong or again I do not understand It works as intended for localplayer and used in server part: function hhh () takePlayerMoney(client,2) setElementData(client, "meat", (getElementData(client, "meat") or 0) + 10) end addEvent("m9cko",true) addEventHandler("m9cko",root,hhh) 7 minutes ago, slapz0r said: Did as you wrote, and used for display number dxDrawText("Мясо: "..math.floor(meatnz).." ед", 1800*x, 750*y, 1670*x, 25*y, tocolor(255, 255, 255, 255), 2, "Arial", "center", "center", false, false, true, true, false) newElement = createPickup (1322.2575683594,358.23822021484,19.5546875, 3, 2663, 1, 1 ) function HudOpening () local meatn = getElementData(localPlayer, "meat") or 0 local meatnz = getElementData(newElement, "meat") or 0 dxDrawText("Мясо: "..math.floor(meatnz).." ед", 1800*x, 750*y, 1670*x, 25*y, tocolor(255, 255, 255, 255), 2, "Arial", "center", "center", false, false, true, true, false) end addEventHandler("onClientRender",root,HudOpening) local player = getLocalPlayer() function initGUI( ) --showCursor(true) btnOutput = DGS:dgsCreateButton( 0.7, 0.1, 0.2, 0.1, "+", true ) addEventHandler ( "onDgsMouseClick", btnOutput, outputEditBox ) end addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) function outputEditBox ( button, state) if button == "left" and state == "down" then if (newElement) then setElementData(newElement, "meat", (getElementData(newElement, "meat") or 0) + 10) --triggerServerEvent( "m9cko", root, 0, 24, 35 ) end end end Not working, what am I doing wrong or again I do not understand It works as intended for localplayer and used in server part: function hhh () takePlayerMoney(client,2) setElementData(client, "meat", (getElementData(client, "meat") or 0) + 10) end addEvent("m9cko",true) addEventHandler("m9cko",root,hhh) UPDATE: SOLVED. Your example helped me a lot. Did everything as intended. Thank you all very much for the answers. Edited May 24, 2019 by slapz0r Link to comment
fairyoggy Posted May 24, 2019 Author Share Posted May 24, 2019 Another question, how to make the numbers saved? On the local player, they are saved after restarting the script, but on "NewElement" not save How to save these numbers for variable "NewElement" or create xml file and to keep these numbers there, and then read. The main thing to do is save, the method is not important Link to comment
fairyoggy Posted May 24, 2019 Author Share Posted May 24, 2019 and how to make it work on the server side? Ie other players do not see the change in these numbers Link to comment
justn Posted May 25, 2019 Share Posted May 25, 2019 1- For data saving on objects I'd suggest using SQLite(or MySQL) 2- You could use tables. 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