Jump to content

/duty not working


BiteeeMe

Recommended Posts

I have this weird problem - I try and change the co-ordinates to a new location and attempt to execute the command /duty. It pops up with the message "There is no duty available for you at this spot!. Here is the code - if you guys can 'explain' the problem and fix it for me, that would be much appreciated as I'm attempting to learn LUA and I'm learning more and more everyday. Here is the code.

c_duty -

  
local thePlayer = getLocalPlayer() 
  
function openDutyWindow() 
    local availablePackages = fetchAvailablePackages( thePlayer ) 
         
    if #availablePackages > 0 then 
        local dutyLevel = getElementData( thePlayer, "duty") 
        if not dutyLevel or dutyLevel == 0 then 
            selectPackageGUI_open(availablePackages) 
        else 
            triggerServerEvent("duty:offduty", thePlayer) 
        end 
    else 
        outputChatBox("There is no duty available for you at this spot!") 
    end 
end 
addCommandHandler("duty", openDutyWindow) 

g_duty

function createDutyColShape(posX, posY, posZ, size, interior, dimension)  
    tempShape = createColSphere(posX, posY, posZ, size) 
    --exports.pool:allocateElement(tempShape) 
    setElementDimension(tempShape, dimension) 
    setElementInterior(tempShape, interior) 
    return tempShape 
end 
  
local swatVehicles = { [427] = true } 
     
local fcpdColShapes = { } 
table.insert(fcpdColShapes, createDutyColShape( 323.7744140625, 305.857421875, 999.1484375, 3, 5, 1) ) 
--table.insert(spdColShapes, createDutyColShape( 1751.3662109375, -2523.8876953125, 15.936504364014, 6, 1, 1006) )  
--table.insert(spdColShapes, createDutyColShape( 1772.8642578125, -2523.73828125, 15.936504364014, 6, 1, 1006) )  
  
local lsesColShapes = { } 
--table.insert(lsesColShapes, createDutyColShape( 867.8193359375, -1679.8251953125, -36.163124084473, 5, 1, 161) ) -- LS Hospital Duty room 
table.insert(lsesColShapes, createDutyColShape( 1444.8486328125, 1400.0615234375, 11.159375190735, 6, 1, 2279) ) -- EMS County general room 
  
local lsfdColShapes = { } 
table.insert(lsfdColShapes, createDutyColShape( 2230.4912109375, -1164.0619140625, 929.00006103516, 6, 3, 10631) ) --  
  
local courtColShapes = { } 
table.insert(courtColShapes, createDutyColShape(343.2958984375, 194.7607421875, 1014.5885620117, 5, 3, 100) ) --  
  
local hexColShapes = { } 
table.insert(hexColShapes, createDutyColShape(2206.3935546875, 1646.646484375, 991.11834716797, 15, 1, 1472) ) -- 
  

If you need any more code, please let me know! Thanks in advance,

BiteeeMe!

Link to comment

Fair enough, I completely understand. I didn't 'steal' the script though, it was given to me by a friend - I wasn't planning on opening a server either, I just figured that the script is advance so I wanted to study into it. /duty is an important command so I thought I could get some help as this is purely local host - but fair enough I guess you have a point. :/

Link to comment
  
function isPlayerInFaction(targetPlayer, factionID) 
    return tonumber( getElementData(targetPlayer, "faction") ) == factionID 
end 
  
function fetchAvailablePackages( targetPlayer ) 
    local availablePackages = { } 
     
    for index, factionTable in ipairs ( factionDuty ) do    -- Loop all the factions 
        if isPlayerInFaction(targetPlayer, factionTable["factionID"]) then 
            for index, factionPackage in ipairs ( factionTable["packages"] ) do -- Loop all the faction packages 
                local found = false 
                for index, packageColShape in ipairs ( factionPackage["colShape"] ) do -- Loop all the colshapes of the factionpackage 
                    if isElementWithinColShape( targetPlayer, packageColShape ) then 
                        found = true 
                        break  -- We found this package already, no need to search the other colshapes 
                    end 
                end 
                 
                if factionPackage.vehicle and getPedOccupiedVehicle( targetPlayer ) and factionPackage.vehicle[ getElementModel( getPedOccupiedVehicle( targetPlayer ) ) ] then 
                    found = true 
                end 
                 
                if found and canPlayerUseDutyPackage(targetPlayer, factionPackage) then 
                    table.insert(availablePackages, factionPackage) 
                end 
            end 
        end 
    end 
     
    return availablePackages 
end 
  
function fetchAllPackages( ) 
    local availablePackages = { } 
     
    for index, factionTable in ipairs ( factionDuty ) do    -- Loop all the factions 
        table.insert(availablePackages, factionPackage) 
    end 
     
    return availablePackages 
end 
  
function canPlayerUseDutyPackage(targetPlayer, factionPackage) 
    local playerPackagePermission = getElementData(targetPlayer, "factionPackages") 
    if playerPackagePermission then 
        for index, permissionID in ipairs(playerPackagePermission) do 
            if (permissionID == factionPackage["grantID"]) then 
                return true 
            end 
        end 
    end 
    return false 
end 
  
function getFactionPackages( factionID ) 
    if not factionID or not tonumber( factionID ) then 
        return factionDuty 
    end 
     
    for index, factionTable in ipairs ( factionDuty ) do    -- Loop all the factions 
        if tonumber(factionTable["factionID"]) == tonumber( factionID ) then 
            return factionTable["packages"] 
        end 
    end 
     
    return {}    
end 
  
addEvent("onPlayerDuty", true) 
  

Here is some more code - why lock it? You can just ask for more code and I would happily give it to you. Help would be much appreciated, if I have gave you the wrong code, or you need anything more - please tell me.

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