AnnaBelle Posted April 11, 2017 Share Posted April 11, 2017 (edited) 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 April 11, 2017 by AnnaBelle Link to comment
NeXuS™ Posted April 11, 2017 Share Posted April 11, 2017 (edited) 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 April 11, 2017 by NeXuS™ Link to comment
Mr.Loki Posted April 11, 2017 Share Posted April 11, 2017 (edited) 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. Edited April 11, 2017 by Mr.Loki 1 Link to comment
AnnaBelle Posted April 11, 2017 Author Share Posted April 11, 2017 Thank you, next time I use (<>). Link to comment
AnnaBelle Posted April 12, 2017 Author Share Posted April 12, 2017 (edited) Edited April 12, 2017 by AnnaBelle Link to comment
AnnaBelle Posted April 13, 2017 Author Share Posted April 13, 2017 You have to make a command that the player can see how many hours the pro VIP expires expire Link to comment
NeXuS™ Posted April 13, 2017 Share Posted April 13, 2017 Are you using my method, or @Mr.Loki's method? Link to comment
AnnaBelle Posted April 13, 2017 Author Share Posted April 13, 2017 Method of @Mr.loki Link to comment
NeXuS™ Posted April 13, 2017 Share Posted April 13, 2017 (edited) 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 April 13, 2017 by NeXuS™ Link to comment
AnnaBelle Posted April 13, 2017 Author Share Posted April 13, 2017 Your VIP expires in 03:185 ,Are you sure? Link to comment
NeXuS™ Posted April 13, 2017 Share Posted April 13, 2017 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
AnnaBelle Posted April 13, 2017 Author Share Posted April 13, 2017 (edited) The message that appears is the time your vip is already active, not the time left to expire,So show the time you already used. Your VIP expires in 00:22 Edited April 13, 2017 by AnnaBelle Link to comment
NeXuS™ Posted April 13, 2017 Share Posted April 13, 2017 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. Link to comment
AnnaBelle Posted April 13, 2017 Author Share Posted April 13, 2017 Now it's thanks. Do you understand anything experience and level? Link to comment
AnnaBelle Posted April 13, 2017 Author Share Posted April 13, 2017 https://forum.multitheftauto.com/topic/94781-help-me-patent-level/ System of level 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