Jump to content

Problem with duty


Simi23

Recommended Posts

Hello! I have make a duty script, and its doesn't working. Can anyone solve it? 

Server: 

addEvent("addArmor", true)

function addArmor()
    setPedArmor(source, 100)
end

addEventHandler("addArmor", getRootElement(), addArmor)

function pdduty(player)
    local x, y, z = getElementPosition(player)
    local pickup = createPickup(x + 3, y, z, 3, 1242)
    colshape = getElementColShape(pickup)
    addEventHandler("onColShapeHit", colshape, openwindow)
    addEventHandler("onColShapeLeave", colshape, closewindow)
    addEventHandler("onPickupUse", pickup, 
    function()
        cancelEvent()
    end)
end
addCommandHandler("pdduty", pdduty)

function openwindow(hitElement, matchingDimension)
    if matchingDimension and getElementType(hitElement) == "player" then
        triggerClientEvent("openwindow", hitElement)
        
    end
end



function closewindow(hitElement, matchingDimension)
    if matchingDimension and getElementType(hitElement) == "player" then
        triggerClientEvent("closewindow", hitElement)
    end
end

Client: 

sx, sy = guiGetScreenSize()

addEvent("openwindow", true)

function changeDuty()
    if getElementData(lPlayer, "duty", "0") then
        lPlayer = getLocalPlayer()    
        givePedWeapon(lPlayer, 24)
        givePedWeapon(lPlayer, 31, 180)
        triggerServerEvent("addArmor", getRootElement())
        setElementData(lPlayer, "duty", "1")
    end
end

function draw()
    dxDrawRectangle(sx * 0.4, sy * 0.65, sx * 0.2, sy * 1.0, tocolor(0,0,0,150))
    dxDrawText("Duty: [E]", sx * 0.45, sy * 0.7)
end

function openwindow()
    addEventHandler("onClientRender", getRootElement(), draw)
    bindKey("e", "down", changeDuty)
end

addEventHandler("openwindow", getRootElement(), openwindow)

addEvent("closewindow", true)

function closewindow()
    removeEventHandler("onClientRender", getRootElement(), draw)
    unbindKey("e", "down", changeDuty)
end

addEventHandler("closewindow", getRootElement(), closewindow)

The meta doesn't have any problems, for sure.

Edited by Simi23
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...