Jump to content

[HELP-ME]Remove vip after one day


AnnaBelle

Recommended Posts

Player can buy VIP with play money for one day and after that one day VIP is automatically removed

server:

addEvent("addVIP",true)
addEventHandler("addVIP",getRootElement(),function(source)
    local account = getPlayerAccount(source)
    local accName = getAccountName(account)
    aclGroupAddObject(aclGetGroup("VIP"),"user."..accName)
    
end)

 

Client:

if source == Botao["buy8"] then
    if getElementData(localPlayer,"MoneyMT")MTA >= 150000 then 
        triggerServerEvent("addVIP",getRootElement(),localPlayer)
        outputChatBox("You have vip for one day.",255,255,255,true)
        else
        outputChatBox("You do not have enough money
",255,0,0,true)
    end
end    

 

Edited by AnnaBelle
Link to comment

Can you use the code (<>) tags please?

addEvent("addVIP",true)
addEventHandler("addVIP",getRootElement(),function(source)
	local account = getPlayerAccount(source)
	local accName = getAccountName(account)
	aclGroupAddObject(aclGetGroup("VIP"), "user."..accName)
	setAccountData(account, "vipBought", getRealTime().timestamp)
end)

addEventHandler("onPlayerLogin", getRootElement(), function(_, theAccount)
	if getAccountData(theAccount, "vipBought") then
		if getRealTime().timestamp > getAccountData(theAccount, "vipBought") + 86400 then
			outputChatBox("Your VIP has expired.", source, 0, 0, 0, true)
			aclGroupRemoveObject(aclGetGroup("VIP"), "user." .. getAccountName(theAccount))
		end
	end
end)

 

Edited by NeXuS™
Link to comment

Use getRealTime().timestamp this will return the current date of the client/server depending on which u run this function on as a UNIX timestamp.

Google UNIX Timestamp converter to have a better understanding of what it is.

Since we don't want players to adjust their time on their PC so they have infinite VIP we will make this function server sided.

addEvent("addVIP",true)
addEventHandler("addVIP",getRootElement(),function(source)
    local account = getPlayerAccount(source)
    local accName = getAccountName(account)
    aclGroupAddObject(aclGetGroup("VIP"),"user."..accName)
    -- This returns a table of the time including hour, minutes, seconds etc...
    -- we just need the timestamp in the table so we use ".timestamp" which is the current date in seconds (UNIX timestamp).
    local currentDate = getRealTime().timestamp
    -- now we must store that data (currentDate) into the player's account on a key called "VIPPurchaseDate".
    setAccountData("VIPPurchaseDate", currentDate)
end)

function checkPlayersVIP( )
    -- Now we make a loop through all the players in the server.
    local plrs = getElementsByType'player'
    for i=1,#plrs do
        -- We get the player's account and their VIP purchase date.
        local account = getPlayerAccount( plrs[i] )
        local purchaseDate = getAccountData( account, "VIPPurchaseDate" )
        -- We now check if they have purchased vip on the account.
        if purchaseDate then
            -- We get the current time of the server,
            local currentDate = getRealTime().timestamp
            -- and minus the player's purchased date from it. 3600 seconds = 1 hour so we just multiply it by 24 to get a day.
            if currentDate - purchaseDate >= 3600*24 then
                -- If it is greater than or equals to 24 hours we remove the vip from the player's account.
                aclGroupRemoveObject( aclgaclGetGroup("VIP"), "user."..getAccountName(account) )
                outputChatBox( "the message you may want to tell the player that his VIP has finished", plrs[i], 255, 100, 100 )
                setAccountData("VIPPurchaseDate", false)
            end
        end
    end
end
-- we add a timer to check the players every minute of their VIP status
setTimer( checkPlayersVIP, 60000, 0 )

 

P.S: Please use the code <> button when posting code. It just makes things much easier to read and identify.

QnVj4fE.png

Edited by Mr.Loki
  • Like 1
Link to comment
addCommandHandler("checktime", function(thePlayer)
	local purchaseDate = getAccountData(getPlayerAccount(thePlayer), "VIPPurchaseDate")
	if purchaseDate then
		local realTime = getRealTime().timestamp
		local remainingTime = realTime - purchaseDate
		local minutesLeft = remainingTime/60
		local hoursLeft = minutesLeft/60
		outputChatBox("Your VIP expires in " .. string.format("%02d", math.floor(hoursLeft)) .. ":" .. string.format("%02d", math.floor(minutesLeft)), thePlayer)
	else
		outputChatBox("You haven't bought VIP in the past.", thePlayer)
	end
end)

I think this one should work.

Edited by NeXuS™
Link to comment
addCommandHandler("checktime", function(thePlayer)
	local purchaseDate = getAccountData(getPlayerAccount(thePlayer), "VIPPurchaseDate")
	if purchaseDate then
		local realTime = getRealTime().timestamp
		local remainingTime = realTime - purchaseDate
		local minutesLeft = remainingTime/60
		local hoursLeft = minutesLeft/60
		outputChatBox("Your VIP expires in " .. string.format("%02d", math.floor(hoursLeft)) .. ":" .. string.format("%02d", math.floor(minutesLeft)%60), thePlayer)
	else
		outputChatBox("You haven't bought VIP in the past.", thePlayer)
	end
end)

 

Link to comment

Ahh, right.

addCommandHandler("checktime", function(thePlayer)
	local purchaseDate = getAccountData(getPlayerAccount(thePlayer), "VIPPurchaseDate")
	if purchaseDate then
		local realTime = getRealTime().timestamp
		local remainingTime = purchaseDate + 86400 - realTime
		local minutesLeft = remainingTime/60
		local hoursLeft = minutesLeft/60
		outputChatBox("Your VIP expires in " .. string.format("%02d", math.floor(hoursLeft)) .. ":" .. string.format("%02d", math.floor(minutesLeft)%60), thePlayer)
	else
		outputChatBox("You haven't bought VIP in the past.", thePlayer)
	end
end)

Try this one. :D

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