kieran Posted August 13, 2017 Share Posted August 13, 2017 I am working on some script, thinking of making it iron miner, anywat here is the problem. Basically, I am creating markers etc client side, so I am trying to set element data on client and get it on server, but I am having troubles with any ways of getting it to save as an amount... Client Progress_Window = {} function ProGUI(hitElement, matchingDimension) if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if getPlayerTeam(hitElement) and getTeamFromName("Job 1") then playerTeam = getPlayerTeam(hitElement) checkTeam = getTeamFromName("Job 1") if tostring(playerTeam) == tostring(checkTeam) then if isPedOnGround ( hitElement ) then Progress_Window = guiCreateWindow(0.25, 0.9, 0.55, 0.05, "Testing Progress", true) guiWindowSetSizable(Progress_Window, false) guiSetProperty(Progress_Window, "CaptionColour", "FFFF0000") somebar = guiCreateProgressBar( 0.01, 0.4, 1, 1, true, Progress_Window ) if ( somebar ) then setProgress = setTimer(function() progress = guiProgressBarGetProgress(somebar) if (progress) >= (tonumber (100)) then --I want it to save when bar is 100. guiSetProperty(Progress_Window, "CaptionColour", "FF00FF00") setElementData (hitElement, "Iron.pres", ?+1)--I want to save this as an amount, here is where I am stuggling. killTimer(setProgress) CompletedProgress = setTimer(function() guiSetVisible(Progress_Window, false) destroyElement(Progress_Window) destroyElement(ProMark) killTimer(CompletedProgress) end, 10000, 0) elseif (progress) <= (tonumber (100)) then guiProgressBarSetProgress(somebar, progress+50) end end, 2000, 0) else outputChatBox ("Something went wrong!") end end end end end end function ProStart( hitElement ) ProMark = createMarker (-3293, 2216, 1517, "checkpoint", 1, 0, 200, 55, 255, hitElement) addEventHandler("onClientMarkerHit", ProMark, ProGUI) end addEvent( "GoPro", true ) addEventHandler( "GoPro", resourceRoot, ProStart ) Server GoProMark = createMarker (-497.0654296875, -196.90234375, 78.404663085938, "cylinder", 1, 0, 200, 55, 255) local GoProTeam = createTeam("Job 1", 20, 100, 150) function GoProTrigger ( hitElement, matchingDimension ) if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if getTeamFromName("Job 1") then local J1T = getTeamFromName("Job 1") if J1T then if isPedOnGround ( hitElement ) then setPlayerTeam(hitElement, J1T) triggerClientEvent ( "GoPro", resourceRoot ) triggerClientEvent ( "ShowIron", resourceRoot ) elseif not isPedOnGround ( hitElement ) then outputChatBox("You must be on foot to change team!", hitElement, 255, 0, 0) end end end end end addEventHandler("onMarkerHit", GoProMark, GoProTrigger) function SaveIron(quitType, reason, responsibleElement) if not (isGuestAccount (getPlayerAccount (source))) then account = getPlayerAccount (source) if (account) then MyIron = getElementData( source, "Iron.pres" ) if (MyIron) then setAccountData (account, "Iron.saved", MyIron) end end end end addEventHandler("onPlayerQuit", getRootElement(), SaveIron) As you see, GUI pops up, progress bar is complete, then I want to set the player to have 1 under the string Iron, but how can I do that? I had the idea of doing setElementData (hitElement, "Iron.pres", ?+1) where "?" would be something like getElementData (hitElement, "Iron.pres", ?) but didn't know what to put in "?" Sorry if it's not clear, it is the first time I am ever trying to make a script for a job... Link to comment
NeXuS™ Posted August 13, 2017 Share Posted August 13, 2017 setElementData(hitElement, "Iron.pres", (getElementData(hitElement, "Iron.pres") or 0)+1) Try it like this. 1 Link to comment
!#NssoR_) Posted August 13, 2017 Share Posted August 13, 2017 Note : The size of the marker should be greater than number 1. Progress_Window = {} Progress_Window = guiCreateWindow(0.25, 0.9, 0.55, 0.05, "Testing Progress", true) guiSetVisible(Progress_Window,false) guiWindowSetSizable(Progress_Window, false) guiSetProperty(Progress_Window, "CaptionColour", "FFFF0000") somebar = guiCreateProgressBar( 0.01, 0.4, 1, 1, true, Progress_Window ) function ProGUI(hitElement, matchingDimension) if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then local checkTeam = getTeamFromName("Job 1") if ( checkTeam and not ( setProgress or CompletedProgress ) ) then local playerTeam = getPlayerTeam(hitElement) if ( playerTeam == checkTeam ) then if isPedOnGround ( hitElement ) then guiSetVisible(Progress_Window,true) guiProgressBarSetProgress(somebar,0) guiSetProperty(Progress_Window, "CaptionColour", "FF00FF00") setProgress = setTimer(function(hitElement) local progress = guiProgressBarGetProgress(somebar) if ( progress >= 100 ) then setElementData (hitElement, "Iron.pres",(getElementData (hitElement, "Iron.pres")or 0 ) + 1) killTimer(setProgress) CompletedProgress = setTimer(function() guiSetVisible(Progress_Window, false) destroyElement(ProMark) killTimer(CompletedProgress) end, 10000, 1) elseif ( progress <= 100 ) then guiProgressBarSetProgress(somebar, progress+50) end end, 2000, 0,hitElement) else outputChatBox ("Something went wrong!") end end end end end function ProStart( ) ProMark = createMarker (-3293, 2216, 1517, "checkpoint", 2, 0, 200, 55, 255) addEventHandler("onClientMarkerHit", ProMark, ProGUI) end addEvent( "GoPro", true ) addEventHandler( "GoPro", root, ProStart ) GoProMark = createMarker (-497.0654296875, -196.90234375, 78.404663085938, "cylinder", 2, 0, 200, 55, 255) local GoProTeam = createTeam("Job 1", 20, 100, 150) function GoProTrigger ( hitElement, matchingDimension ) if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if ( GoProTeam ) then if isPedOnGround ( hitElement ) then setPlayerTeam(hitElement, GoProTeam) triggerClientEvent ( "GoPro", hitElement ) triggerClientEvent ( "ShowIron", hitElement ) else outputChatBox("You must be on foot to change team!", hitElement, 255, 0, 0) end end end end addEventHandler("onMarkerHit", GoProMark, GoProTrigger) function SaveIron(quitType, reason, responsibleElement) if not (isGuestAccount (getPlayerAccount (source))) then local account = getPlayerAccount (source) if (account) then local MyIron = getElementData( source, "Iron.pres" ) if (MyIron) then setAccountData (account, "Iron.saved", MyIron) end end end end addEventHandler("onPlayerQuit", getRootElement(), SaveIron) function getIron(_,acc) -- i did that function to restore your iron when rejoin to server. local MyIron = getAccountData( acc, "Iron.saved" ) if (MyIron) then setElementData (source, "Iron.pres", MyIron) end end addEventHandler("onPlayerLogin", getRootElement(), getIron) 1 Link to comment
kieran Posted August 14, 2017 Author Share Posted August 14, 2017 @!#NssoR_) and @NeXuS™ works perfect, thanks! but one more question... I also wish to set marker only visible/collidable with the player that spawns it as the position will be random later, will it already do this as it triggers client side or will the whole server be able to interact with it? Link to comment
NeXuS™ Posted August 14, 2017 Share Posted August 14, 2017 triggerClientEvent(hitElement, "GoPro", hitElement) triggerClientEvent(hitElement, "ShowIron", hitElement) Link to comment
kieran Posted August 14, 2017 Author Share Posted August 14, 2017 @NeXuS™ Will this trigger it so that the marker itself may only be used by "hitElement" or will all players be able to use that marker? I am just asking as I tried a similar thing in a script before, but the marker and blip shown to all players. Link to comment
NeXuS™ Posted August 14, 2017 Share Posted August 14, 2017 If you use my example, it'll only trigger the client-sided script for the hitElement. 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