Jump to content

[Question] Setting Element Data for client on server


kieran

Recommended Posts

I made a super simple weather script that changes weather and rain, but I am having some issues as I want to add a command to allow players to stop rain until they log off.... 

Server

weather = {}
weathers = 3

--1,2,3
weather[1] = 0
weather[2] = 3
weather[3] = 7

--rain

rain = {}
Therain = 3

--1,2,3
rain[1] = 0
rain[2] = 10
rain[3] = 5
	
	
setTimer(
	function (thePlayer)
			local Wacc = getPlayerAccount(thePlayer)
			if Wacc then
			local CheckWeather = getElementData( thePlayer, "tempdata.ChkWeath" )
			if ( CheckWeather == false ) then
			randomWeather = math.random (1, weathers)
			randomRain = math.random (1, Therain)
	
			local cusweather = setWeather (weather[randomWeather]) 
			local cusrain = setRainLevel (rain[randomRain]) 
			elseif ( CheckWeather == true ) then
			return
			end
		end
	end, 
300000, 1)


function stopTheRain ( thePlayer, command )
	local Wacc = getPlayerAccount(thePlayer)
	if Wacc then
	local setElementData ( thePlayer, "tempdata.ChkWeath", Wacc )
end
end
addCommandHandler("norain", stopTheRain)

Basically it works on server if it's just cycling weather, but I wanted players to have choice for it to never rain as it can be a little FPS consuming.

 

Error: [2017-07-13 03:02:19] SCRIPT ERROR: WeatherStuff\Weather.lua:63: ')' expected near ','

 

Why does it expect a bracket on line 63?  Oh!  And while I'm at it...  Am I even setting element data correctly? :/  Thanks in advance! 

P.S Reason it is server is because I tried it client (just changing weather and rain level (set for 10 secs) ) and it didn't work.

Edited by kieran
Link to comment

my bad @pro-mos, I meant line 42, I forgot I had stuff at start. (Is commented, so won't matter if it's there.) 

never mind, I put local where local shouldn't be...

 

Fixed that problem....  But now I have another problem: Weather.lua:23: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil]

Spoiler

weather = {}
weathers = 3

--1,2,3
weather[1] = 0
weather[2] = 3
weather[3] = 7

--rain

rain = {}
Therain = 3

--1,2,3
rain[1] = 0
rain[2] = 10
rain[3] = 5
	
	
setTimer(
	function (thePlayer)
			local Wacc = getPlayerAccount(thePlayer)
			if Wacc then
			CheckWeather = getElementData( thePlayer, "tempdata.ChkWeath" )
			if ( CheckWeather == false ) then
			randomWeather = math.random (1, weathers)
			randomRain = math.random (1, Therain)
	
			local cusweather = setWeather (weather[randomWeather]) 
			local cusrain = setRainLevel (rain[randomRain]) 
			elseif ( CheckWeather == true ) then
			return
			end
		end
	end, 
300000, 1)


function stopTheRain ( thePlayer, command )
	local Wacc = getPlayerAccount(thePlayer)
	if Wacc then 
	setElementData ( thePlayer, "tempdata.ChkWeath", Wacc )
	outputDebugString ( "User changed weather settings." )
end
end
addCommandHandler("antirain", stopTheRain)

 

Starting to think it would just be easier to set the data and timers client side.....

Edited by kieran
Link to comment

If you turn off the rain server side, it will be turned off for everybody else as well. @ line 42 use setAccountData to save the "ChkWeath" state on the user account and also use setElementData which you can use on the client side. Use onPlayerLogin event to get the accountData and save it to setElementData again to be able to use it client side.

You can also just implement the command client side and use xmlCreateFile / xmlLoadFile to create a settings XML where you can save things like this..

When you create a timer, there's no thePlayer parameter either, you can only pass values into it manually. 

  • Like 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...