1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Sign up for news, events and more!

    You're currently visiting the official DarkRP Forums as a guest. Sign up now to participate in our community and we'll let you know when we have news.

F4 Entity Pickup Timer

Discussion in 'DarkRP Modding Questions & Help' started by Jay Wood, Nov 19, 2019.

  1. Jay Wood

    Jay Wood New Member

    Hey, so I'm using XP books in my F4 menu and I want to make it so that only TEAM_X can pick up books/use the entity, and books can only be used every X seconds.

    Here is the use function, which currently says that anyone can use it as many times as they want. If there is no way to make it job-specific it's fine, but I would like to limt the uses to 1 every 600 seconds.

    https://pastebin.com/tWjeDdz3

    Thanks
     
  2. se7ensins

    se7ensins Member

    Make TEAM_X have the command "allow" and the *ID job* of the job so they can only do it.

    Set entity delay when bought to 600 simple, they gotta wait 600 sec now to rebuy it or use it
     
  3. Jay Wood

    Jay Wood New Member

    Appreciate that se7ensins, but this is what I meant:

    If I drop an XP book and someone uses it, this happens

    Code (Text):
    function ENT:Use( activator )
        if( self:Getexperience() == 0 ) then return end
        if( activator:IsValid() and activator:IsPlayer() ) then
            activator:addXP( self:Getexperience() or 0 )
            self:Setexperience( 0 )
           
            if self.Charges <= 0 then
                activator:ChatPrint("You have finished reading "..self:Gettitle().."!")
                self:Remove()
            else
                activator:ChatPrint("You have read a few chapters of "..self:Gettitle().."!")
            end
        end
    end
    and I want to add a 600 second delay before that person can use it again. I found this on delays and cooldowns, just not sure how to add it :/

    Code (Text):
    local cooldown = 86400 -- 24 hours in seconds ( 24*60*60 )

    local function myFunc()
        local nextUse = cookie.GetNumber( "myFuncNextUse", 0 )
        local time = os.time()

        if time < nextUse then
            print( "The event is on cooldown and has not been triggered" )
            local nextUseString = os.date( "%Y/%m/%d - %H:%M:%S" , nextUse ) -- Format the next use time nicely
            print( "The event will be available for use again on: " .. nextUseString )
        else
            print( "The event has been successfully triggered!" )
            cookie.Set( "myFuncNextUse", time + cooldown )
        end
    end
    Any help or guidance would be appreciated. Especially if I'm not even using the right event timer here. Thanks
     
  4. se7ensins

    se7ensins Member

    I mean can send me the addon your using
     

Share This Page