Jump to content

COLShape problem[FIXED]


Price.

Recommended Posts

Done fixed

local timersTable = {} 
local islandCOL = createColRectangle (3528.18994, -326.39496, 1000, 300 ) 
  
function Island (player) 
    if player and isElement(player) and (getElementType(player) == "player") then  
        local player = (isPedInVehicle(player) and getVehicleController (getPedOccupiedVehicle (player))) or player  
        local account = getPlayerAccount(player) 
        if account and not isGuestAccount(account) then 
            local accName = getAccountName(account) 
            if ( isObjectInACLGroup ("user."..accName, aclGetGroup ("Admin"))) then return false end 
            if eventName == "onColShapeHit" then 
                if not(timersTable[player]) then  
                    timersTable[player] = setTimer(killPed, 20000, 1, player) 
                    outputChatBox("You have entered Staff Island, you have 20 seconds to leave or you'll be killed.", player, 255, 0, 0, true) 
                end 
            elseif eventName == "onColShapeLeave" then 
                if isTimer(timersTable[player]) then  
                    killTimer(timersTable[player]) 
                    timersTable[player] = nil 
                    outputChatBox("You have left the area.", player, 0, 200, 0) 
                end  
            end  
        end  
    end  
end 
addEventHandler ( "onColShapeHit", islandCOL, Island) 
addEventHandler ( "onColShapeLeave", islandCOL, Island) 
  
addEventHandler( "onPlayerWasted", getRootElement( ), 
    function() 
        if isTimer(timersTable[source]) then  
            killTimer(timersTable[source]) 
            timersTable[source] = nil 
        end  
    end 
) 

Link to comment

when I enter the col shape, I pretty much think it doesn't let the timer go on from where it left off when I entered first time, I entered a lot and every time I go out and go on several times, I don't die so I pretty much think the timer doesnt save where it left off

Link to comment
when I enter the col shape, I pretty much think it doesn't let the timer go on from where it left off when I entered first time, I entered a lot and every time I go out and go on several times, I don't die so I pretty much think the timer doesnt save where it left off

The timer will be killed when you leave the colship. read my code again

Link to comment
I want it to be saved so when the player keeps getting out and inside the col shape it continues from where it left off so the player doesn't abuse going out and it

So all what you need is:

getTimerDetails () 
setElementData() 
getElementData() 

Link to comment
getElement data doesn't save if he logs out of the server and logs in too, I honestly don't like to use element data, isn't there a way around to save it using account, same style you used?

bro it's only 20 seconds , anyways you can use

setAccountData() 
getAccountData() 

For more information , Check my answer, they already asked the same question Here

Link to comment
is it possible to save using getPlayerAccount? bec its already there and I think I saved a time before using it instead of accountdata
still can't figure out how to save the time so when he enters again the timer continues where it left off

Here is all what you need:

local timersTable = {} 
local islandCOL = createColRectangle (3528.18994, -326.39496, 1000, 300 ) 
  
function Island (player) 
    if player and isElement(player) and (getElementType(player) == "player") then 
        local player = (isPedInVehicle(player) and getVehicleController (getPedOccupiedVehicle (player))) or player 
        local account = getPlayerAccount(player) 
        if account and not isGuestAccount(account) then 
            local accName = getAccountName(account) 
            if ( isObjectInACLGroup ("user."..accName, aclGetGroup ("Admin"))) then return false end 
            if eventName == "onColShapeHit" then 
                local timer = getAccountData(account, "timer") -- get the timer using getAccountData 
                if (timer) then 
                    timersTable[player] = setTimer(killPed, tonumber(timer), 1, player) 
                else 
                    if not(timersTable[player]) then 
                        timersTable[player] = setTimer(killPed, 20000, 1, player) 
                    end 
                end  
                outputChatBox("You have entered Staff Island, you have 20 seconds to leave or you'll be killed.", player, 255, 0, 0, true) 
            elseif eventName == "onColShapeLeave" then 
                if isTimer(timersTable[player]) then 
                    local remaining = getTimerDetails(timersTable[player])  
                    setAccountData(account,  "timer", tonumber(remaining)) 
                    killTimer(timersTable[player]) 
                    timersTable[player] = nil 
                    outputChatBox("You have left the area.", player, 0, 200, 0) 
                end 
            end 
        end 
    end 
end 
addEventHandler ( "onColShapeHit", islandCOL, Island) 
addEventHandler ( "onColShapeLeave", islandCOL, Island) 
  
addEventHandler( "onPlayerWasted", getRootElement( ), 
    function() 
        local account = getPlayerAccount(source) 
        if account and not isGuestAccount(account) then  
            if isTimer(timersTable[source]) then 
                killTimer(timersTable[source]) 
                timersTable[source] = nil 
                setAccountData(account,  "timer",false) 
            end 
        end  
    end 
) 
  
function save () 
        local playerAccount = getPlayerAccount ( source )  
        if (isTimer(timersTable[source])) then  
        local remaining = getTimerDetails(timersTable[source])  
        if playerAccount and not isGuestAccount(playerAccount) then  
            setAccountData(playeraccount,  "timer", tonumber(remaining))  
            killTimer(timersTable[source]) -- kill the timer 
            timersTable[source] = nil 
        end 
    end 
end 
addEventHandler ("onPlayerQuit", root, save ) 

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