Jump to content

Job system


Smart.

Recommended Posts

So, this is basically an uncompiled version of viewtopic.php?f=108&t=50510 but it hasn't been tested in months and may not work (although if my memory serves me right it should work flawlessly) but if there are any bugs they should be easy to fix.

Client:

------------------------------------------------------------------------------------ 
--  RIGHTS:      All rights reserved by developers 
--  FILE:        jobs/jobs.lua 
--  PURPOSE:     Job System Client 
--  DEVELOPERS:  Smart (Sebbe) 
------------------------------------------------------------------------------------ 
  
local sx, sy = guiGetScreenSize() 
  
function makeJobGUI() 
    jobWnd = guiCreateWindow((sx / 1) - (364 / 1), (sy / 2) - (458 / 2), 364, 458, "", false) 
    guiWindowSetSizable(jobWnd, false) 
    guiSetVisible(jobWnd, false) 
    guiSetAlpha(jobWnd, 1) 
  
    jobDescLbl = guiCreateLabel(7, 23, 347, 332, "Job Desc", false, jobWnd) 
    guiSetFont(jobDescLbl, "clear-normal") 
    selectJobButton = guiCreateButton(9, 415, 94, 33, "Have Job", false, jobWnd) 
    exitJobButton = guiCreateButton(260, 415, 94, 33, "Close Window", false, jobWnd) 
    addEventHandler("onClientGUIClick", selectJobButton, wantsJob, false) 
    addEventHandler("onClientGUIClick", exitJobButton, exitJob, false) 
     
     
    skinWnd = guiCreateWindow((sx / 1) - (436 / 1), (sy / 2) - (178 / 2), 436, 178, "Skin Selection", false) 
    guiSetAlpha(skinWnd, 1) 
    guiWindowSetSizable(skinWnd, false) 
    guiSetVisible(skinWnd, false) 
  
    skinLbl = guiCreateLabel(6, 24, 420, 57, "Please select what skin you want to work in.", false, skinWnd) 
    guiSetFont(skinLbl, "clear-normal") 
    guiLabelSetHorizontalAlign(skinLbl, "center", false) 
    --guiCreateComboBox(132, 142, 238, 150, "Select Punishment", false, punishWnd) 
    skinCombo = guiCreateComboBox(10, 50, 416, 1500, "Select Skin..", false, skinWnd) 
    skinSelectBttn = guiCreateButton(10, 139, 416, 29, "Select Skin", false, skinWnd) 
     
    addEventHandler("onClientGUIClick", skinCombo, previewModel, false) 
    addEventHandler("onClientGUIClick", skinSelectBttn, youHaveSelectedSkin, false) 
end 
addEventHandler("onClientResourceStart", resourceRoot, makeJobGUI) 
  
--[[selectJobButton = guiCreateButton((sx / 1680) * 1352,  (sy / 1050) * 757,  (sx / 1680) * 99,  (sy / 1050) * 30, "Have Job", false) 
exitJobButton = guiCreateButton((sx / 1680) * 1576,  (sy / 1050) * 757,  (sx / 1680) * 99,  (sy / 1050) * 30, "Exit", false) 
guiSetVisible(selectJobButton, false) 
guiSetVisible(exitJobButton, false)--]] 
  
function enteredMarker(t, d, s) 
    jobTitle = t 
    jobDesc = d 
    jobSkins = s 
    mySkin = getElementModel(localPlayer) 
    jobTitle = jobTitle:gsub("#%x%x%x%x%x%x", "") 
    showCursor(true) 
    guiSetVisible(jobWnd, true) 
    guiSetText(jobWnd, jobTitle) 
    guiSetText(jobDescLbl, jobDesc) 
end 
addEvent("jobs.enteredMarker", true) 
addEventHandler("jobs.enteredMarker", root, enteredMarker) 
  
function exitJob() 
    guiSetVisible(jobWnd, false) 
    showCursor(false) 
    --removeEventHandler("onClientRender", root, drawJobText) 
    drawing = false 
end 
  
function previewModel() 
    local mod = guiGetText(source) 
    if (tonumber(mod)) then 
        setElementModel(localPlayer, mod) 
    end 
end 
  
function wantsJob() 
    guiSetVisible(jobWnd, false) 
    showCursor(false) 
    --windowSelection =  
    --removeEventHandler("onClientRender", root, drawJobText) 
    drawing = false 
     
    if (jobSkins and #jobSkins > 0) then 
        guiSetVisible(skinWnd, true) 
        showCursor(true) 
    end 
     
    guiComboBoxClear(skinCombo) 
     
    for ind, dat in pairs(jobSkins) do 
        guiComboBoxAddItem(skinCombo, dat) 
    end 
    --local jobTitle = jobTitle:gsub("#%x%x%x%x%x%x", "") 
    --triggerServerEvent("jobs.wantJob", root, jobTitle) 
end 
  
function youHaveSelectedSkin()   
    for ind, dat in pairs(jobSkins) do 
        if (not getElementModel(localPlayer) == dat) then 
            --exports.texts:message("You can't use this skin for this job", 255, 0, 0, "defualt-bold", true, 0.1) 
            outputChatBox("You cannot use this this skin for this job", 255, 0, 0) 
            return 
        end 
    end 
     
    guiSetVisible(skinWnd, false) 
    showCursor(false) 
    triggerServerEvent("jobs.wantJob", root, _, jobTitle, getElementModel(localPlayer)) 
end 

Server:

------------------------------------------------------------------------------------ 
--  RIGHTS:      All rights reserved by developers 
--  FILE:        jobs/jobs.slua 
--  PURPOSE:     Jobs Server 
--  DEVELOPERS:  Smart (Sebbe) 
------------------------------------------------------------------------------------ 
  
mrkr = {} 
jobPed = {} 
  
jobsLocation = { 
    {job = "#454545FBI", rotation = 90, x = 1547, y = -1670, z = 12.5, r = 105, g = 105, b = 105, team = "Government", skin = {286}, jobEvent = "event", maxWL = 3, description = "This is the Federal Bureau of Investigation.\nMore description will be available soon.\n\nGroup is led by NOBODY.", group = "FBI"}, 
} 
  
function makeJobs() 
    for ind, data in pairs(jobsLocation) do 
        --local title = data.job:gsub("#%x%x%x%x%x%x", "") 
        local m = createMarker(data.x, data.y, data.z, "cylinder", 1.5, data.r, data.g, data.b, 75) 
        blip = createBlipAttachedTo(m, 56) 
        setBlipVisibleDistance(blip, 300) 
        mrkr[m] = data.job 
        if (data.skin) then 
            for ind, model in pairs(data.skin) do 
                jobPed[data.job] = createPed(model, data.x, data.y, data.z + 1) 
                setElementFrozen(jobPed[data.job], true) 
                setElementData(jobPed[data.job], "immortalPed", true) 
                setElementRotation(jobPed[data.job], 0, 0, data.rotation) 
                break 
            end 
        end 
        addEventHandler("onMarkerHit", m, enteredMarker) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, makeJobs) 
  
function wantJob(jobName, player, model) 
    if (not player) then player = client end 
    for ind, data in pairs(jobsLocation) do 
        local realTitle = data.job:gsub("#%x%x%x%x%x%x", "") 
        if (realTitle == jobName) then 
            --exports.texts:message(player, "You are working as "..jobName, data.r, data.g, data.b, "default-bold", true, 0.15) 
            --exports.teams:setPlayerTeam(player, data.team) 
            outputChatBox("You are now working as "..jobname, player, data.r, data.g, data.b) 
            setPlayerTeam(player, getTeamFromName(data.team)) 
            if (data.skin and not model) then 
                for ind, model in pairs(data.skin) do 
                    setElementModel(player, model) 
                    break 
                end 
            else 
                setElementModel(player, model) 
            end 
        end 
    end 
end 
addEvent("jobs.wantJob", true) 
addEventHandler("jobs.wantJob", root, wantJob) 
  
  
function enteredMarker(plr, match) 
    if (not match) then return end 
    if (not mrkr[source]) then return end 
    if (not isElement(plr) or getElementType(plr) ~= "player") then return end 
     
    if (isPedInVehicle(plr)) then  
        outputChatBox("You cannot be inside a vehicle when entering this marker", plr, 255, 0, 0) 
        --exports.texts:message(plr, "You can not be inside a vehicle when entering this marker", 255, 0, 0, "default-bold", true, 0.2) 
        return  
    end 
     
    local name = mrkr[source] 
    for ind, data in pairs(jobsLocation) do 
        if (data.job == name) then 
            local wl = getPlayerWantedLevel(plr) or 0 
            if (wl > data.maxWL) then 
                outputChatBox("You cannot take this job with "..wl.." stars", plr, 255, 0, 0) 
                --exports.texts:message(plr, "You can not take this job with "..wl.." stars", 255, 0, 0, "default-bold", true, 0.2) 
                return 
            end 
             
            triggerClientEvent(plr, "jobs.enteredMarker", plr, name, data.description, data.skin) 
             
            return 
        end 
    end 
end 

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