Jump to content

OnMarkerHit


Absence2

Recommended Posts

Hello, I've been trying to script a Marker, adding the marker itself wasn't very hard, but now I need to add some handlers.

So this is what I got:

local jobmarker = createMarker ( 1192.25390625, -1324.5009765625, 13.3984375, "cylinder", 1.0, 0, 255, 255, 50 ) 
  
function jobmarker (thePlayer) 
  
            outputChatBox("This is a test message", thePlayer, 255, 153, 0) 
        outputChatBox("This is a second test message", thePlayer, 255, 153, 0) 
  
    end 
addEventHandler( "onMarkerHit", jobmarker, jobmarker1 ) 
  
function useJob(thePlayer, matchingDimension) 
 if isElementWithinMarker(thePlayer, jobmarker) then 
 local localPlayer = getLocalPlayer ( ) 
          if exports.global:hasMoney(player, 50) then 
                exports.global:giveMoney(player, 50) 
                outputChatBox("You have been given 50$ due to testing purposes.", player, 0, 255, 0) 
  
 else 
    outputChatBox("You are not at the right place!", thePlayer, 255, 0, 0) 
 end 
end 
end 
addCommandHandler("job", useJob) 
  
  
  
  

attempt to call global 'GuiGetScreenSize' (a nil value)

14:bad argument @ 'isElementWithinMarker'

11: bad argument @ 'addeventhandler' [expected element at argument 2, got function]

The outputChatBox messages doesn't show either.

The whole thing is basically f*****'d

Link to comment

u have server and client functions messed up, decide which it will be...

onMarkerHit - server side, onClientMarkerHit - clientside

getLocalPlayer - clientside, source - server side

u have the right idea, u just need to work out which u wanna use then swap the above^

also, line 3 needs to be called: function jobmarker1 like in ur handler because of the marker variable above with the same name.

and remember MarkerHit passes the element that hit the marker to the function, so if u use 'thePlayer' this may also be

a vehicle, if the player is in a car at the time he hits the marker.

so u should include if getElementType(element) == "player" then.....

this will prevent it from giving errors when it tries to get player info from a vehicle.

Edited by Guest
Link to comment
local jobmarker = createMarker ( 1192.25390625, -1324.5009765625, 13.3984375, "cylinder", 1.0, 0, 255, 255, 50 ) 
  
function jobmarkerFunction (thePlayer) 
    outputChatBox("This is a test message", thePlayer, 255, 153, 0) 
    outputChatBox("This is a second test message", thePlayer, 255, 153, 0)  
end 
addEventHandler( "onMarkerHit", jobmarker, jobmarkerFunction ) 
  
function useJob(thePlayer) 
    if isElementWithinMarker(thePlayer, jobmarker) then 
        if exports.global:hasMoney(thePlayer, 50) then 
            exports.global:giveMoney(thePlayer, 50) 
            outputChatBox("You have been given 50$ due to testing purposes.", thePlayer, 0, 255, 0) 
        else 
            outputChatBox("You are not at the right place!", thePlayer, 255, 0, 0) 
        end 
    end 
end 
addCommandHandler("job", useJob) 

First: You have used localPlayer in a server side script, when that function is only client side.

Second: You are trying to add a event handler to a non existing function.

Third: You're using the argument 'player' in 'useJob' function but your player argument is 'thePlayer'

Link to comment

Hehe, I figured half of it out after Scooby's post but not the second part, so I'll be using yours, Solid. But

10:bad argument @ 'isElementWithinMarker'

that error still occurs after using /job, but it works.. Is it something I should be worried about?

Also I guess I'm mixing client & server functions again, but,

how do I add dxDrawings upon markerhit?

like

        dxDrawRectangle ( x/3.8, y/3.8, x/2.02, y/2, tocolor ( 0, 0, 0, 150 ) ) 

Also, why does the every text duplicate upon markerhit? :S

Edited by Guest
Link to comment
DX drawing functions are client side only, and they also require 'onClientRender' event to render them.

use: triggerClientEvent to add the event handler to render it.

Like this?

local jobmarker = createMarker ( 1192.25390625, -1324.5009765625, 13.3984375, "cylinder", 1.0, 0, 255, 255, 50 ) 
  
  
function jobmarkerFunction (thePlayer) 
local rootElement = getRootElement() 
local x,y = guiGetScreenSize()  -- Get players resolution. 
addEventHandler("onClientRender",root, 
    function() 
        dxDrawRectangle(226.0,97.0,387.0,402.0,tocolor(255,255,255,255),false) 
    end 
) 
    outputChatBox("This is a test message", thePlayer, 255, 153, 0) 
    outputChatBox("This is a second test message", thePlayer, 255, 153, 0) 
end 
addEventHandler( "onClientMarkerHit", jobmarker, jobmarkerFunction ) 
  
function useJob(thePlayer, matchingDimension) 
    if isElementWithinMarker(thePlayer, jobmarker) then 
        if exports.global:hasMoney(thePlayer, 50) then 
            exports.global:giveMoney(thePlayer, 50) 
            outputChatBox("You have been given 50$ due to testing purposes.", thePlayer, 0, 255, 0) 
        else 
            outputChatBox("You are not at the right place!", thePlayer, 255, 0, 0) 
        end 
    end 
end 
addCommandHandler("job", useJob) 
  

The Rectangle shows but it doesn't hide after leaving the marker :/

Link to comment
local jobmarker = createMarker ( 1192.25390625, -1324.5009765625, 13.3984375, "cylinder", 1.0, 0, 255, 255, 50 ) 
local x,y = guiGetScreenSize()  -- Get players resolution. 
  
function renderRectangle() 
    dxDrawRectangle(226.0,97.0,387.0,402.0,tocolor(255,255,255,255),false) 
end 
  
function jobmarkerHit () 
    addEventHandler("onClientRender",root,renderRectangle) 
    outputChatBox("This is a test message", 255, 153, 0) 
    outputChatBox("This is a second test message", 255, 153, 0) 
end 
addEventHandler( "onClientMarkerHit", jobmarker, jobmarkerHit ) 
  
function jobmarkerLeave () 
    removeEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker, jobmarkerLeave ) 
  
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker) then 
        if exports.global:hasMoney(localPlayer, 50) then 
            exports.global:giveMoney(localPlayer, 50) 
            outputChatBox("You have been given 50$ due to testing purposes.", 0, 255, 0) 
        else 
            outputChatBox("You are not at the right place!", 255, 0, 0) 
        end 
    end 
end 
addCommandHandler("job", useJob) 

Link to comment

Thanks, works :D

But I think I've put water over my head, the useJob function was merely a test on how to add a command within a Marker.

local jobmarker = createMarker ( 1192.25390625, -1324.5009765625, 12.3984375, "cylinder", 1.2, 255, 255, 153, 50 ) 
  
  
function renderRectangle() 
local x,y = guiGetScreenSize()  -- Get players resolution. 
        dxDrawRectangle(233.0,472.0,363.0,125.0,tocolor(0,0,0,150),false) 
        dxDrawText("Jim's Rings Donut Delivery Job",241.0,477.0,588.0,499.0,tocolor(255,255,255,255),0.6,"bankgothic","left","top",false,false,false) 
        dxDrawLine(586.0,502.0,241.0,502.0,tocolor(255,255,255,255),1.0,false) 
end 
  
function jobmarkerHit () 
    addEventHandler("onClientRender",root,renderRectangle) 
    outputChatBox("This is a test message", 255, 153, 0) 
    outputChatBox("This is a second test message", 255, 153, 0) 
end 
addEventHandler( "onClientMarkerHit", jobmarker, jobmarkerHit ) 
  
function jobmarkerLeave () 
    removeEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker, jobmarkerLeave ) 
  
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker) then 
        if exports.global:hasMoney(localPlayer, 50) then 
            exports.global:giveMoney(localPlayer, 50) 
            outputChatBox("You have been given 50$ due to testing purposes.", 0, 255, 0) 
        else 
            outputChatBox("You are not at the right place!", 255, 0, 0) 
        end 
    end 
end 
addCommandHandler("job", useJob) 

I'm trying to get the useJob function to a "givejob" thingy, but I have no idea what so ever on how to do it.

This is the Job script I'm using,

Client:

wEmployment, jobList, bAcceptJob, bCancel = nil 
  
local jessie = createPed( 141, 359.712890625, 173.5654296875, 1008.3893432617 ) 
--local jessie = createPed( 141, 359.7060, 173.5371, 1008.3828 ) 
setPedRotation( jessie, 271 ) 
setElementDimension( jessie, 5 ) 
setElementInterior( jessie , 3 ) 
setElementData( jessie, "talk", 1 ) 
setElementData( jessie, "name", "Jessie Smith" ) 
setPedAnimation ( jessie, "INT_OFFICE", "OFF_Sit_Idle_Loop", -1, true, false, false ) 
setElementFrozen(jessie, true) 
  
function showEmploymentWindow() 
     
    -- Employment Tooltip 
    if(getResourceFromName("tooltips-system"))then 
        triggerEvent("tooltips:showHelp",getLocalPlayer(),7) 
    end 
     
    triggerServerEvent("onEmploymentServer", getLocalPlayer()) 
    local width, height = 300, 400 
    local scrWidth, scrHeight = guiGetScreenSize() 
    local x = scrWidth/2 - (width/2) 
    local y = scrHeight/2 - (height/2) 
     
    wEmployment = guiCreateWindow(x, y, width, height, "Job Pinboard", false) 
     
    jobList = guiCreateGridList(0.05, 0.05, 0.9, 0.8, true, wEmployment) 
    local column = guiGridListAddColumn(jobList, "Job Title", 0.9) 
  
    -- TRUCKER 
    local row = guiGridListAddRow(jobList) 
    guiGridListSetItemText(jobList, row, column, "Delivery Driver", false, false) 
     
    -- TAXI 
    local row = guiGridListAddRow(jobList) 
    guiGridListSetItemText(jobList, row, column, "Taxi Driver", false, false) 
     
    -- BUS 
    local row = guiGridListAddRow(jobList) 
    guiGridListSetItemText(jobList, row, column, "Bus Driver", false, false) 
     
    -- CITY MAINTENACE 
    local team = getPlayerTeam(getLocalPlayer()) 
    local ftype = getElementData(team, "type") 
    if ftype ~= 2 then 
        local rowmaintenance = guiGridListAddRow(jobList) 
        guiGridListSetItemText(jobList, rowmaintenance, column, "City Maintenance", false, false) 
    end 
     
    -- MECHANIC 
    local row = guiGridListAddRow(jobList) 
    guiGridListSetItemText(jobList, row, column, "Mechanic", false, false) 
     
    -- LOCKSMITH 
    local row = guiGridListAddRow(jobList) 
    guiGridListSetItemText(jobList, row, column, "Locksmith", false, false) 
     
    bAcceptJob = guiCreateButton(0.05, 0.85, 0.45, 0.1, "Accept Job", true, wEmployment) 
    bCancel = guiCreateButton(0.5, 0.85, 0.45, 0.1, "Cancel", true, wEmployment) 
     
    showCursor(true) 
     
    addEventHandler("onClientGUIClick", bAcceptJob, acceptJob) 
    addEventHandler("onClientGUIDoubleClick", jobList, acceptJob) 
    addEventHandler("onClientGUIClick", bCancel, cancelJob) 
end 
addEvent("onEmployment", true) 
addEventHandler("onEmployment", getRootElement(), showEmploymentWindow) 
  
function acceptJob(button, state) 
    if (button=="left") then 
        local row, col = guiGridListGetSelectedItem(jobList) 
        local job = getElementData(getLocalPlayer(), "job") 
         
        if (row==-1) or (col==-1) then 
            outputChatBox("Please select a job first!", 255, 0, 0) 
        elseif (job>0) then 
            outputChatBox("You are already employed, please quit your other job first (( /quitjob )).", 255, 0, 0) 
        else 
            local job = 0 
            local jobtext = guiGridListGetItemText(jobList, guiGridListGetSelectedItem(jobList), 1) 
             
            if ( jobtext=="Delivery Driver" or jobtext=="Taxi Driver" or jobtext=="Bus Driver" ) then  -- Driving job, requires the license 
                local carlicense = getElementData(getLocalPlayer(), "license.car") 
                if (carlicense~=1) then 
                    outputChatBox("You require a drivers license to do this job.", 255, 0, 0) 
                    return 
                end 
            end 
             
            if (jobtext=="Delivery Driver") then 
                displayTruckerJob() 
                job = 1 
            elseif (jobtext=="Taxi Driver") then 
                job = 2 
                displayTaxiJob() 
            elseif  (jobtext=="Bus Driver") then 
                job = 3 
                displayBusJob() 
            elseif (jobtext=="City Maintenance") then 
                job = 4 
            elseif (jobtext=="Mechanic") then 
                displayMechanicJob() 
                triggerServerEvent("giveMechanicJob", getLocalPlayer()) 
                job = 5 
            elseif (jobtext=="Locksmith") then 
                displayLocksmithJob() 
                job = 6 
            end 
             
            triggerServerEvent("acceptJob", getLocalPlayer(), job) 
             
            destroyElement(jobList) 
            destroyElement(bAcceptJob) 
            destroyElement(bCancel) 
            destroyElement(wEmployment) 
            wEmployment, jobList, bAcceptJob, bCancel = nil, nil, nil, nil 
            showCursor(false) 
        end 
    end 
end 
  
function cancelJob(button, state) 
    if (source==bCancel) and (button=="left") then 
        destroyElement(jobList) 
        destroyElement(bAcceptJob) 
        destroyElement(bCancel) 
        destroyElement(wEmployment) 
        wEmployment, jobList, bAcceptJob, bCancel = nil, nil, nil, nil 
        showCursor(false) 
    end 
end 

Server:

mysql = exports.mysql 
  
chDimension = 125 
chInterior = 3 
  
-- CALL BACKS FROM CLIENT 
  
function onEmploymentServer() 
    exports.global:sendLocalText(source, "Jessie Smith says: Hello, are you looking for a new job?", nil, nil, nil, 10) 
    exports.global:sendLocalText(source, " *Jessie Smith hands over a list with jobs to " .. getPlayerName(source):gsub("_", " ") .. ".", 255, 51, 102) 
end 
  
addEvent("onEmploymentServer", true) 
addEventHandler("onEmploymentServer", getRootElement(), onEmploymentServer) 
  
function givePlayerJob(jobID) 
    local charname = getPlayerName(source) 
     
    exports['anticheat-system']:changeProtectedElementDataEx(source, "job", jobID) 
    mysql:query_free("UPDATE characters SET job=" .. mysql:escape_string(jobID) .. ", jobcontract = 3 WHERE id = " .. mysql:escape_string(getElementData(source, "dbid")) ) 
     
    exports.global:givePlayerAchievement(source, 30) 
  
    if (jobID==4) then -- CITY MAINTENANCE 
        exports.global:giveWeapon(source, 41, 1500, true) 
        outputChatBox("Use this paint to paint over tags you find.", source, 255, 194, 14) 
        exports['anticheat-system']:changeProtectedElementDataEx(source, "tag", 9) 
        mysql:query_free("UPDATE characters SET tag=9 WHERE id = " .. mysql:escape_string(getElementData(source, "dbid")) ) 
    end 
end 
addEvent("acceptJob", true) 
addEventHandler("acceptJob", getRootElement(), givePlayerJob) 
  
function quitJob(source) 
    local logged = getElementData(source, "loggedin") 
    if logged == 1 then 
        local job = getElementData(source, "job") 
        if job == 0 then 
            outputChatBox("You are currently unemployed.", source, 255, 0, 0) 
        else 
            local result = mysql:query_fetch_assoc("SELECT jobcontract FROM characters WHERE id = " .. mysql:escape_string(getElementData(source, "dbid")) ) 
            if result then 
                local contracttime = tonumber( result["jobcontract"] ) or 0 
                if contracttime > 1 then 
                    outputChatBox( "You need to wait " .. contracttime .. " payday(s) before you can leave your job.", source, 255, 0, 0) 
                else 
                    exports['anticheat-system']:changeProtectedElementDataEx(source, "job", 0) 
                    mysql:query_free("UPDATE characters SET job=0 WHERE id = " .. mysql:escape_string(getElementData(source, "dbid")) ) 
                    if job == 4 then 
                        exports['anticheat-system']:changeProtectedElementDataEx(source, "tag", 1) 
                        mysql:query_free("UPDATE characters SET tag=1 WHERE id = " .. mysql:escape_string(getElementData(source, "dbid")) ) 
                    end 
                     
                    triggerClientEvent(source, "quitJob", source, job) 
                end 
            else 
                outputDebugString( "QuitJob: SQL error" ) 
            end 
        end 
    end 
end 
  
addCommandHandler("endjob", quitJob, false, false) 
addCommandHandler("quitjob", quitJob, false, false) 
  
function resetContract( thePlayer, commandName, targetPlayerName ) 
    if exports.global:isPlayerAdmin( thePlayer ) then 
        if targetPlayerName then 
            local targetPlayer, targetPlayerName = exports.global:findPlayerByPartialNick( thePlayer, targetPlayerName ) 
            if targetPlayer then 
                if getElementData( targetPlayer, "loggedin" ) == 1 then 
                    local result = mysql:query_free("UPDATE characters SET jobcontract = 0 WHERE id = " .. mysql:escape_string(getElementData( targetPlayer, "dbid" )) .. " AND jobcontract > 0" ) 
                    if result then 
                        outputChatBox( "Reset Job Contract for " .. targetPlayerName, thePlayer, 0, 255, 0 ) 
                    else 
                        outputChatBox( "Failed to reset Job Contract Time.", thePlayer, 255, 0, 0 ) 
                    end 
                else 
                    outputChatBox( "Player is not logged in.", thePlayer, 255, 0, 0 ) 
                end 
            end 
        else 
            outputChatBox( "SYNTAX: /" .. commandName .. " [player]", thePlayer, 255, 194, 14 ) 
        end 
    end 
end 
addCommandHandler("resetcontract", resetContract, false, false) 
  
function setMechanicData( ) 
    exports['anticheat-system']:changeProtectedElementDataEx(source, "job", 5, true) 
end 
addEvent("giveMechanicJob", true) 
addEventHandler("giveMechanicJob", getRootElement(), setMechanicData) 
  
function checkJob(thePlayer, commandName) 
    if (exports.global:isPlayerHeadAdmin(thePlayer)) then 
        jobdata = getElementData(thePlayer, "job") 
        outputChatBox("Job: "..jobdata, thePlayer, 255, 194, 14) 
    end  
end 
addCommandHandler("checkjob", checkJob)  

To simplify it, I'm trying to make the /job command give you Job ID 7.

Link to comment
local jobmarker = createMarker ( 1192.25390625, -1324.5009765625, 13.3984375, "cylinder", 1.0, 0, 255, 255, 50 ) 
local x,y = guiGetScreenSize()  -- Get players resolution. 
  
function renderRectangle() 
    dxDrawRectangle(226.0,97.0,387.0,402.0,tocolor(255,255,255,255),false) 
end 
  
function jobmarkerHit () 
    addEventHandler("onClientRender",root,renderRectangle) 
    outputChatBox("This is a test message", 255, 153, 0) 
    outputChatBox("This is a second test message", 255, 153, 0) 
end 
addEventHandler( "onClientMarkerHit", jobmarker, jobmarkerHit ) 
  
function jobmarkerLeave () 
    removeEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker, jobmarkerLeave ) 
  
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker) then 
        if exports.global:hasMoney(localPlayer, 50) then 
            exports.global:giveMoney(localPlayer, 50) 
            outputChatBox("You have been given 50$ due to testing purposes.", 0, 255, 0) 
            triggerServerEvent("acceptJob", localPlayer, 7) 
        else 
            outputChatBox("You are not at the right place!", 255, 0, 0) 
        end 
    end 
end 
addCommandHandler("job", useJob) 

Link to comment
local jobmarker = createMarker ( 1192.25390625, -1324.5009765625, 13.3984375, "cylinder", 1.0, 0, 255, 255, 50 ) 
local x,y = guiGetScreenSize()  -- Get players resolution. 
  
function renderRectangle() 
    dxDrawRectangle(226.0,97.0,387.0,402.0,tocolor(255,255,255,255),false) 
end 
  
function jobmarkerHit () 
    addEventHandler("onClientRender",root,renderRectangle) 
    outputChatBox("This is a test message", 255, 153, 0) 
    outputChatBox("This is a second test message", 255, 153, 0) 
end 
addEventHandler( "onClientMarkerHit", jobmarker, jobmarkerHit ) 
  
function jobmarkerLeave () 
    removeEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker, jobmarkerLeave ) 
  
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker) then 
        if exports.global:hasMoney(localPlayer, 50) then 
            exports.global:giveMoney(localPlayer, 50) 
            outputChatBox("You have been given 50$ due to testing purposes.", 0, 255, 0) 
            triggerServerEvent("acceptJob", localPlayer, 7) 
        else 
            outputChatBox("You are not at the right place!", 255, 0, 0) 
        end 
    end 
end 
addCommandHandler("job", useJob) 

You make me feel like a complete noob ._., well can't deny facts!

I just need help with one last thing,

function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker) then 
     
                        triggerServerEvent("acceptJob", localPlayer, 7) 
        end 
        end 
addCommandHandler("job", useJob) 

If you successfuly got the job with /job a text appears in outputChatBox, like "You're now working for Jim's Rings"

And if you're employed aldready: "You are already employed, please quit your other job first (( /quitjob ))"

function acceptJob(button, state) 
    if (button=="left") then 
        local row, col = guiGridListGetSelectedItem(jobList) 
        local job = getElementData(getLocalPlayer(), "job") 
         
        if (row==-1) or (col==-1) then 
            outputChatBox("Please select a job first!", 255, 0, 0) 
        elseif (job>0) then 
            outputChatBox("You are already employed, please quit your other job first (( /quitjob )).", 255, 0, 0) 
        else 
            local job = 0 
            local jobtext = guiGridListGetItemText(jobList, guiGridListGetSelectedItem(jobList), 1) 
             
            if ( jobtext=="Delivery Driver" or jobtext=="Taxi Driver" or jobtext=="Bus Driver" ) then  -- Driving job, requires the license 
                local carlicense = getElementData(getLocalPlayer(), "license.car") 
                if (carlicense~=1) then 
                    outputChatBox("You require a drivers license to do this job.", 255, 0, 0) 
                    return 
                end 
            end 

Link to comment
local jobmarker = createMarker ( 1192.25390625, -1324.5009765625, 13.3984375, "cylinder", 1.0, 0, 255, 255, 50 ) 
local x,y = guiGetScreenSize()  -- Get players resolution. 
  
function renderRectangle() 
    dxDrawRectangle(226.0,97.0,387.0,402.0,tocolor(255,255,255,255),false) 
end 
  
function jobmarkerHit () 
    addEventHandler("onClientRender",root,renderRectangle) 
    outputChatBox("This is a test message", 255, 153, 0) 
    outputChatBox("This is a second test message", 255, 153, 0) 
end 
addEventHandler( "onClientMarkerHit", jobmarker, jobmarkerHit ) 
  
function jobmarkerLeave () 
    removeEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker, jobmarkerLeave ) 
  
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker) then 
        local job = getElementData(localPlayer, "job") 
        if ( job > 0 ) then 
            outputChatBox("You are already employed, please quit your other job first (( /quitjob )).", 255, 0, 0) 
        else 
            triggerServerEvent("acceptJob", localPlayer, 7) 
        end 
    end 
end 
addCommandHandler("job", useJob) 

Link to comment

Thank you :), almost everything is figured out now, there's only one thing remaining and that is a Ped standing next to it.

I tried with this:

local jobmarker = createMarker ( 1019.2646484375, -1348.587890625, 12.548809051514, "cylinder", 1.3, 255, 255, 153, 15 ) 
  
function renderRectangle() 
 local screenWidth, screenHeight = guiGetScreenSize() 
local nSw,nSh = guiGetScreenSize( ) 
local rootElement = getRootElement() 
local x,y = guiGetScreenSize()  -- Get players resolution. 
  
--Draw texts and background 
dxDrawRectangle ( x/3.4, y/1.6, x/2.13, y/4.2, tocolor ( 0, 0, 0, 150 ) ) 
dxDrawText("  Jim's Rings Donut Delivery Job",nSw/3, nSh/1.57, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
dxDrawText("Use /acceptjob to accept this job",nSw/3, nSh/1.47, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
dxDrawText("/quitjob if this job do not suit  you",nSw/3, nSh/1.27, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
end 
  
 --Add text on markerHit 
function jobmarkerHit () 
    addEventHandler("onClientRender",root,renderRectangle) 
    outputChatBox("(( Jim's Rings Donut Delivery Job ))", thePlayer, 255, 153, 0) 
end 
addEventHandler( "onClientMarkerHit", jobmarker, jobmarkerHit ) 
  
 --Hide dxDrawings upon markerLeave 
function jobmarkerLeave () 
    removeEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker, jobmarkerLeave ) 
  
 --acceptjob command while inside marker 
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker) then 
        local job = getElementData(localPlayer, "job") 
        if ( job > 0 ) then 
            outputChatBox("You are already employed, please quit your other job first (( /quitjob )).", thePlayer, 0, 255, 0, 0) 
        else 
            triggerServerEvent("acceptJob", localPlayer, 7) 
outputChatBox("You are now employed at Jim's Rings Donut Delivery's.", thePlayer, 0, 190, 0, 0) 
        end 
    end 
end 
addCommandHandler("acceptjob", useJob) 
  
  
  
local jim = createPed( 1019.2646484375, -1348.587890625, 13.548809051514 ) 
setPedRotation( jim, 89 ) 
setElementDimension( jim, 0 ) 
setElementInterior( jim , 0 ) 
setElementData( jim, "talk", 1 ) 
setElementData( jim, "name", "Jim Clark" ) 
setPedAnimation ( jim, "INT_OFFICE", "OFF_Sit_Idle_Loop", -1, true, false, false ) 
setElementFrozen(jim, true) 

But it bombed me with errors (the Ped thingies)

Link to comment

You forgot to set the skin model argument in createPed.

local jobmarker = createMarker ( 1019.2646484375, -1348.587890625, 12.548809051514, "cylinder", 1.3, 255, 255, 153, 15 ) 
  
local jim = createPed( 0, 1019.2646484375, -1348.587890625, 13.548809051514, 89 ) -- 0 = CJ skin. 
setElementDimension( jim, 0 ) 
setElementData( jim, "talk", 1 ) 
setElementData( jim, "name", "Jim Clark" ) 
setPedAnimation ( jim, "INT_OFFICE", "OFF_Sit_Idle_Loop", -1, true, false, false ) 
setElementFrozen(jim, true) 
  
function renderRectangle() 
 local screenWidth, screenHeight = guiGetScreenSize() 
local nSw,nSh = guiGetScreenSize( ) 
local rootElement = getRootElement() 
local x,y = guiGetScreenSize()  -- Get players resolution. 
  
--Draw texts and background 
dxDrawRectangle ( x/3.4, y/1.6, x/2.13, y/4.2, tocolor ( 0, 0, 0, 150 ) ) 
dxDrawText("  Jim's Rings Donut Delivery Job",nSw/3, nSh/1.57, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
dxDrawText("Use /acceptjob to accept this job",nSw/3, nSh/1.47, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
dxDrawText("/quitjob if this job do not suit  you",nSw/3, nSh/1.27, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
end 
  
 --Add text on markerHit 
function jobmarkerHit () 
    addEventHandler("onClientRender",root,renderRectangle) 
    outputChatBox("(( Jim's Rings Donut Delivery Job ))", thePlayer, 255, 153, 0) 
end 
addEventHandler( "onClientMarkerHit", jobmarker, jobmarkerHit ) 
  
 --Hide dxDrawings upon markerLeave 
function jobmarkerLeave () 
    removeEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker, jobmarkerLeave ) 
  
 --acceptjob command while inside marker 
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker) then 
        local job = getElementData(localPlayer, "job") 
        if ( job > 0 ) then 
            outputChatBox("You are already employed, please quit your other job first (( /quitjob )).", thePlayer, 0, 255, 0, 0) 
        else 
            triggerServerEvent("acceptJob", localPlayer, 7) 
outputChatBox("You are now employed at Jim's Rings Donut Delivery's.", thePlayer, 0, 190, 0, 0) 
        end 
    end 
end 
addCommandHandler("acceptjob", useJob) 

Link to comment

Ah, thank you for all your help, but I somehow bumped into another problem on the way which I just spotted.

There's 5 different jobs and every job has a different .lua file, for some reason, they mix together (dxDrawings only)

This is what I have....

  
  
local jobmarker5 = createMarker ( -70.373046875, -1136.9384765625, 0.078125, "cylinder", 1.3, 255, 255, 153, 15 ) 
  
function renderRectangle() 
 local screenWidth, screenHeight = guiGetScreenSize() 
local nSw,nSh = guiGetScreenSize( ) 
local rootElement = getRootElement() 
local x,y = guiGetScreenSize()  -- Get players resolution. 
  
--Draw texts and background 
dxDrawRectangle ( x/3.4, y/1.6, x/2.13, y/4.2, tocolor ( 0, 0, 0, 150 ) ) 
dxDrawText("       Los Santos Delivery Job",nSw/3, nSh/1.57, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
dxDrawText("Use /acceptjob to accept this job",nSw/3, nSh/1.47, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
dxDrawText("/quitjob if this job do not suit  you",nSw/3, nSh/1.2, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
end 
  
 --Add text on markerHit 
function jobmarkerHit () 
    addEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerHit", jobmarker5, jobmarkerHit ) 
  
 --Hide dxDrawings upon markerLeave 
function jobmarkerLeave () 
    removeEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker5, jobmarkerLeave ) 
  
 --acceptjob command while inside marker 
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker5) then 
        local job = getElementData(localPlayer, "job") 
        if ( job > 0 ) then 
            outputChatBox("You are already employed, please quit your other job first (( /quitjob )).", thePlayer, 0, 255, 0, 0) 
        else 
            triggerServerEvent("acceptJob", localPlayer, 7) 
outputChatBox("You are now an employee at Jim's Rings Donut Delivery's.", thePlayer, 0, 190, 0, 0) 
        end 
    end 
end 
addCommandHandler("acceptjob", useJob) 

Here's a second job marker (Might help):

local jobmarker4 = createMarker ( 1783.376953125, -1885.7841796875, 12.391790390015, "cylinder", 1.3, 255, 255, 153, 15 ) 
  
function renderRectangle() 
 local screenWidth, screenHeight = guiGetScreenSize() 
local nSw,nSh = guiGetScreenSize( ) 
local rootElement = getRootElement() 
local x,y = guiGetScreenSize()  -- Get players resolution. 
  
--Draw texts and background 
dxDrawRectangle ( x/3.4, y/1.6, x/2.13, y/4.2, tocolor ( 0, 0, 0, 150 ) ) 
dxDrawText("     Los Santos Taxi Driver Job",nSw/3, nSh/1.57, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
dxDrawText("Use /acceptjob to accept this job",nSw/3, nSh/1.47, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
dxDrawText("/quitjob if this job do not suit  you",nSw/3, nSh/1.2, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
end 
  
 --Add text on markerHit 
function jobmarker4Hit () 
    addEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerHit", jobmarker4, jobmarkerHit ) 
  
 --Hide dxDrawings upon markerLeave 
function jobmarkerLeave () 
    removeEventHandler("onClientRender",root,renderRectangle) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker4, jobmarkerLeave ) 
  
 --acceptjob command while inside marker 
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker4) then 
        local job = getElementData(localPlayer, "job") 
        if ( job > 0 ) then 
            outputChatBox("You are already employed, please quit your other job first (( /quitjob )).", thePlayer, 0, 255, 0, 0) 
        else 
            triggerServerEvent("acceptJob", localPlayer, 2) 
outputChatBox("You are now a licensed taxi driver.", thePlayer, 0, 190, 0, 0) 
        end 
    end 
end 
addCommandHandler("acceptjob", useJob) 

And one question,

is it possible to add an image or text above this guy's head (that is attached to him).

local jim = createPed( 0, 1019.2646484375, -1348.587890625, 13.548809051514, 89 ) -- 0 = CJ skin. 
setElementDimension( jim, 0 ) 
setElementData( jim, "talk", 1 ) 
setElementData( jim, "name", "Jim Clark" ) 
setPedAnimation ( jim, "INT_OFFICE", "OFF_Sit_Idle_Loop", -1, true, false, false ) 
setElementFrozen(jim, true) 

Link to comment
You can't attach a text to a element, but you can draw a 3D text with dxDrawText function.

Also, your problem is that you call the render function the same name in every script.

P.S: You could make this just in one script using a table, but it would be hard for you.

Alright, I'll give it a try and yeh, I just noticed :P aldready fixed, thanks anyways ^.^

EDIT: how am I supposed to add a 3D text above a specific area/NPC's head?, I only want it to show on one spot.

EDIT: How do I do this with the marker :), it seems easier.

Like this: 4838.png

Also, how can I restrict the marker from letting people see it while being in the air? It's visible from any range, as long as you're over it. :S

local jobmarker2 = createMarker ( 1917.20703125, -1863.583984375, 12.561410903931, "cylinder", 1.3, 255, 255, 153, 15 ) 
  
function renderRectangleMechanic() 
 local screenWidth, screenHeight = guiGetScreenSize() 
local nSw,nSh = guiGetScreenSize( ) 
local rootElement = getRootElement() 
local x,y = guiGetScreenSize()  -- Get players resolution. 
  
--Draw texts and background 
  
guiCreateStaticImage(581,625,105,78,"images/key.png",false) 
dxDrawRectangle ( x/3.4, y/1.6, x/2.13, y/4.2, tocolor ( 0, 0, 0, 150 ) ) 
dxDrawText("     Los Santos Mechanic Job",nSw/3, nSh/1.57, nSw, nSh,tocolor(255,255,255,185),0.7,"bankgothic","left","top",false,false,false) 
dxDrawText("    Use /acceptjob to accept this job",nSw/3, nSh/1.47, nSw, nSh,tocolor(255,255,255,185),0.6,"bankgothic","left","top",false,false,false) 
dxDrawText("This job pays: N/A$ per person (( Player )) ",nSw/3, nSh/1.25, nSw, nSh,tocolor(255,255,255,185),0.5,"bankgothic","left","top",false,false,false) 
dxDrawText("/quitjob if this job does not suit you",nSw/3, nSh/1.2, nSw, nSh,tocolor(255,255,255,185),0.55,"bankgothic","left","top",false,false,false) 
end 
  
 --Add text on markerHit 
function jobmarker2Hit () 
    if isElementWithinMarker(localPlayer, jobmarker2) then 
    addEventHandler("onClientRender",root,renderRectangleMechanic) 
end 
end 
addEventHandler( "onClientMarkerHit", jobmarker2, jobmarker2Hit ) 
  
 --Hide dxDrawings upon markerLeave 
function jobmarker2Leave () 
    removeEventHandler("onClientRender",root,renderRectangleMechanic) 
end 
addEventHandler( "onClientMarkerLeave", jobmarker2, jobmarker2Leave ) 
  
 --acceptjob command while inside marker 
function useJob() 
    if isElementWithinMarker(localPlayer, jobmarker2) then 
        local job = getElementData(localPlayer, "job") 
        if ( job > 0 ) then 
            outputChatBox("You are already employed, please quit your other job first (( /quitjob )).", thePlayer, 0, 255, 0, 0) 
        else 
            triggerServerEvent("acceptJob", localPlayer, 5) 
outputChatBox("You are now a licensed mechanic.", thePlayer, 0, 190, 0, 0) 
        end 
    end 
end 
addCommandHandler("acceptjob", useJob) 

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