Jump to content

Payday on everyday


Recommended Posts

well, no specific, you have to set a timer using setTimer(function, timeInterval, timestoexecute)

and then run the script at 7:00AM and set time interval to 1000*60*60*24 and the times to execute to 0

this will work for you

  • Like 1
Link to comment
setTimer(function()
	local time = getRealTime()
	local hours = time.hour
	local minutes = time.minute
	if hours == 7 and minutes == 00 then
		outputChatBox("Time: "..hours..":"..minute"", source, 255, 0, 0)
		givePlayerMoney(source, 1500)
	end
end, 1000, 0)

i have not tried it

Link to comment
12 minutes ago, Steven'Bc said:

setTimer(function()
	local time = getRealTime()
	local hours = time.hour
	local minutes = time.minute
	if hours == 7 and minutes == 00 then
		outputChatBox("Time: "..hours..":"..minute"", source, 255, 0, 0)
		givePlayerMoney(source, 1500)
	end
end, 1000, 0)

i have not tried it

Actually, if you increase the time interval it would be better and it will save CPU usage, so each 1second? what about adding each one hour?

setTimer(function()
    local time = getRealTime()
    local hours = time.hour
    local minutes = time.minute
    if hours == 7 and minutes == 00 then
        outputChatBox("Time: "..hours..":"..minute"", source, 255, 0, 0)
        givePlayerMoney(source, 1500)
    end
end, 60000*60, 0)

This would work fine and comfortable
 

 

Link to comment
2 hours ago, UDC said:

Actually, if you increase the time interval it would be better and it will save CPU usage, so each 1second? what about adding each one hour?


setTimer(function()
    local time = getRealTime()
    local hours = time.hour
    local minutes = time.minute
    if hours == 7 and minutes == 00 then
        outputChatBox("Time: "..hours..":"..minute"", source, 255, 0, 0)
        givePlayerMoney(source, 1500)
    end
end, 60000*60, 0)

This would work fine and comfortable
 

 

Put the second you want if it appears in 30 seconds or whatever seconds you want

Link to comment
  • Administrators

I'm not sure if I'd rely on using that timer. I see a flaw in the logic of setting the timer to 1 per hour, what if the script was initiated at 5 minutes past the hour? If the timer is only then checking once per hour, it'll never work.

Here's how I'd prefer to do it

 

Clientside:

local paydayValid = true

local function realtime()
	local time = getRealTime()
	local hours = time.hour
	local minutes = time.minute
	if paydayValid == true then
		if hours == 7 and minutes == 0 then
			outputChatBox("Payday, ka-ching!")	
			triggerServerEvent("onClientPayday", resourceRoot)
			paydayValid = false
		end
	else
		if hours == 6 and minutes == 59 then
			paydayValid = true
		end
	end
end
addEventHandler("onClientRender", getRootElement(), realtime)

 

Serverside:

local function payday()
	givePlayerMoney(client, 1500)
end
addEvent("onClientPayday", true)
addEventHandler("onClientPayday", getRootElement(), payday)

Not tested, but it's not exactly a complicated script ;)

excuse the indenting, the forum code editor uses 2 spaces whereas I use tab

Edited by LopSided_
  • Like 1
Link to comment
2 hours ago, LopSided_ said:

I'm not sure if I'd rely on using that timer. I see a flaw in the logic of setting the timer to 1 per hour, what if the script was initiated at 5 minutes past the hour? If the timer is only then checking once per hour, it'll never work.

Here's how I'd prefer to do it

 

Clientside:


local paydayValid = true

local function realtime()
	local time = getRealTime()
	local hours = time.hour
	local minutes = time.minute
	if paydayValid == true then
		if hours == 7 and minutes == 0 then
			outputChatBox("Payday, ka-ching!")	
			triggerServerEvent("onClientPayday", resourceRoot)
			paydayValid = false
		end
	else
		if hours == 6 and minutes == 59 then
			paydayValid = true
		end
	end
end
addEventHandler("onClientRender", getRootElement(), realtime)

 

Serverside:


local function payday()
	givePlayerMoney(client, 1500)
end
addEvent("onClientPayday", true)
addEventHandler("onClientPayday", getRootElement(), payday)

Not tested, but it's not exactly a complicated script ;)

excuse the indenting, the forum code editor uses 2 spaces whereas I use tab

lol forget the onClientRender sorry event :P

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