Jump to content

[Question] Saving element data to account data


kieran

Recommended Posts

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
  • Moderators
  • 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)

 

  • Thanks 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...