Jump to content

justn

Members
  • Posts

    525
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by justn

  1. 9 minutes ago, mateplays said:

    Thanks for the code, but... somehow it still does not work... i tried putting this into a different resource but it still does not get rid of any blips, and it does not output any errors to debugscript

    Just tested it, works perfectly for me when I attached a blip to myself via command.
    Could you show your current code ?

  2. Correct me if I'm wrong but I'm assuming all you're wanting here is that when the player hits the hunter then he gets the hunter bonus ? If this is the case then the only issue with your code is that in your getHunter function, you need to change addWinnerBonus to addHunterBonus

  3. Your getBlipAttachedTo function only returns the first blip that it finds attached to the player.  (Also I wouldn't loop through every blip in the server as this can have an impact on performance depending on how many blips there are)

    What I would advise is looping through the attached elements of the player , adding all the blips to a table then returning the table(instead of only returning the first found attached blip).  Then in your onPlayerQuit event, you loop through that table destroying everything. Pretty much the code I have below, hope this helps you!


     

    addEventHandler("onPlayerQuit",getRootElement(),
        function()
            local blips = getBlipsAttachedTo(source) 
            if blips then 
                for i,theBlip in ipairs(blips) do
                    destroyElement(theBlip) 
                end
            end 
        end
    )
    
    function getBlipsAttachedTo( thePlayer ) 
        local attached = {}
        local blips = getAttachedElements(thePlayer)
        for k, theBlip in ipairs( blips ) do 
            if isElement(theBlip) and getElementType(theBlip) == 'blip' then 
                table.insert(attached,theBlip)
            end 
        end 
        return attached 
    end 


     

  4. The code provided by HiroShi isn't going to work. Cancelling onPlayerDamage has no effect. Also looping is unnecessary in that case.

    Try this:

    addEventHandler("onClientPlayerDamage",root,
        function(attacker,w,body)
            if attacker then
                if body ~= 9 then
                    cancelEvent()
                end
            end
        end
    )

     

  5.  

    local sx_, sy_ = 1920, 1080
    local sx__, sy__ = guiGetScreenSize()
    local xm, ym = sx__/sx_, sy__/sy_
    
    local hudElements = {}
    
    function _dxDrawImage(x,y,w,h,image,rot,rotOffsetX,rotOffsetY,color,postgui)
        local btn = guiCreateButton(x,y,w,h,"",false)
        if btn then
            setElementData(btn,"hudElement",true)
            guiSetAlpha(btn,0)
            
            table.insert(hudElements,{element=btn,type='image',dx={}})
            hudElements[#hudElements].dx[1] = x
            hudElements[#hudElements].dx[2] = y
            hudElements[#hudElements].dx[3] = w
            hudElements[#hudElements].dx[4] = h
            hudElements[#hudElements].dx[5] = image
            hudElements[#hudElements].dx[6] = tonumber(rot) or 0 
            hudElements[#hudElements].dx[7] = tonumber(rotOffsetX) or 0 
            hudElements[#hudElements].dx[8] = tonumber(rotOffsetY) or 0 
            hudElements[#hudElements].dx[9] = tonumber(color) or tocolor(255,255,255,255)
            hudElements[#hudElements].dx[10] = ( postgui == true ) or false
            return true
        end
    end
    
    function _dxDrawRectangle(x,y,w,h,color,postgui)
        local btn = guiCreateButton(x,y,w,h,"",false)
        if btn then
            setElementData(btn,"hudElement",true)
            guiSetAlpha(btn,0)
            
            table.insert(hudElements,{element=btn,type='rectangle',dx={}})
            hudElements[#hudElements].dx[1] = x
            hudElements[#hudElements].dx[2] = y
            hudElements[#hudElements].dx[3] = w
            hudElements[#hudElements].dx[4] = h
            hudElements[#hudElements].dx[5] = tonumber(color) or tocolor(255,255,255,255)
            hudElements[#hudElements].dx[6] = ( postgui == true ) or false
            return true
        end
    end
    
                    
    addEventHandler('onClientRender',root,
        function()
    
            for i,v in ipairs(hudElements) do
                if targetElement and targetElement == v.element then
                    if getKeyState("mouse1") ~= true then targetElement = nil end
                    if isCursorShowing() == true then
                        local positionX, positionY, worldX, worldY, worldZ = getCursorPosition()
                        local screenx, screeny = getScreenFromWorldPosition(worldX,worldY,worldZ)
                        if screenx  and screenx < sx__ and screeny < sy__ then
                            v.dx[1],v.dx[2] = screenx,screeny
                        end
                        guiSetPosition(v.element,v.dx[1],v.dx[2],false)
                    else
                        targetElement = false
                    end
                end
                if v.type == 'rectangle' then
                    dxDrawRectangle( v.dx[1],  v.dx[2], v.dx[3], v.dx[4],v.dx[5], v.dx[6])
                elseif v.type == 'image' then
                    dxDrawImage( v.dx[1],  v.dx[2], v.dx[3], v.dx[4],v.dx[5], v.dx[6], v.dx[7], v.dx[8], v.dx[9], v.dx[10] )
                end
            end
        end
    )
    
    
    addEventHandler("onClientGUIMouseDown",resourceRoot,
        function(btn)
            if btn == "left" then
                if getElementData(source,"hudElement") == true then
                    targetElement = source
                end
            end
        end
    )
    
    bindKey("m","down",function()
        if isCursorShowing() then
            showCursor(false)
        else
            showCursor(true)
        end
    end)
    
    _dxDrawRectangle( (sx_-245) * xm, (sy_/2-460) * ym, 220 * xm, 10 * ym,tocolor(0,0,0,120),true)

     

    Made you this real quick so you have an idea of what to do, it's not all perfect at the moment but it's something you could use as a start. It's much simpler than you attempting to calculate for every single thing you'd want to draw. You can use what you have there to help you with doing the texts, good luck.

    • Thanks 1
  6. To start off, something wrong with your code that you should be careful of doing, for instance:

    Error:

    -- Replacing this:
    local sx__, sy__ = guiGetScreenSize() -- keep this
    
    -- With this:
    sx__, sy__ = xs, ys 
    
    -- = no no

    To avoid positioning/scaling issues, I wouldn't recommend replacing the value of the variable which you're gonna be using for further calculations with the position of the cursor. 

    Now what you could do is use the onClientClick with a variable to enable/disable the dragging, using onClientRender and getCursorPosition when the cursor is showing , then using the screen position from the cursor to set the value for your hud. A little example below, something like this should work:
     

    local sx_, sy_ = 1920, 1080
    local sx__, sy__ = guiGetScreenSize()
    local xm, ym = sx__/sx_, sy__/sy_
    
    local hudX, hudY = (sx_-245) * xm, (sy_/2-460) * ym
    local isMovingHud = false
    
    addEventHandler('onClientClick',root,
        function(btn,state,posX,posY)
            if btn == 'left' then
                if state == 'down' then
                    isMovingHud = true
                else
                    isMovingHud = false
                end
            end
        end
    )
                    
    addEventHandler('onClientRender',root,
        function()
            
            if isMovingHud == true then
                if isCursorShowing() == true then
                    local positionX, positionY, worldX, worldY, worldZ = getCursorPosition()
                    hudX,hudY = getScreenFromWorldPosition(worldX,worldY,worldZ)
                else
                    isMovingHud = false
                end
            end
    
            dxDrawRectangle( hudX,  hudY, 220 * xm, 10 * ym,tocolor(0,0,0,120))
        end
    )
    
    
    bindKey("m","down",function()
        if isCursorShowing() then
            showCursor(false)
        else
            showCursor(true)
        end
    end)

     

  7. You put 'elseif' as in if the job wasn't  the 'RS Haul Delivery' then it would check if the hours played is below 50, which is why you were able to get the job regardless of how many hours played. Here you go though.
     

    local hoursplayed = tonumber(getElementData(localPlayer, "hoursplayed")) or 0
       
    if (jobtext=="RS Haul Delivery") then
        if hoursplayed < 50 then
            outputChatBox("You must play at least 50 hours to work as a RS haul delivery driver", 255, 0,0)
            return true
        end
    end

     

    • Thanks 1
  8. 2 hours ago, redditing said:

    Ok thx. Do you know how you can send elementData from the server to the client?

    Once you've set the element data on the server you can use getElementData on the client to receive the set data.
    Or triggerClientEvent , whatever you decide

  9. I believe this is what you're trying to do.
     

    marker = createMarker(-662.33703613281,2365.9025878906,178.9553527832, "cylinder", 1.5, 0, 100, 100, 200)
    
    function Texto()
        local x,y,z = getElementPosition(localPlayer)
        local distance = getDistanceBetweenPoints3D(-662.33703613281,2365.9025878906,178.9553527832,x,y,z)
        if distance < 20 then
            local sx,sy =  getScreenFromWorldPosition(-662.33703613281,2365.9025878906,178.9553527832)
            if sx and sy then
                local coords = {sx,sy}
                if coords[1] and coords[2] then
                    dxDrawText("CJ", coords[1], coords[2], coords[1], coords[2], tocolor(255,0,0,255), 10, "sans", "center", "center", false, false, false, false)
                end
            end
        end
    end
    addEventHandler("onClientRender", root, Texto)

     

  10. Well first off you're trying to set the team color to a team that doesn't exist yet - (update colors after making sure the team exists)
    Secondly I would suggest checking if colour.r, colour.g & colour.b are numbers before trying to set anything(to prevent errors)

    Try this:

    team = {}
    colour = {}
    colour.r = 255
    colour.g = 85
    colour.b = 85
    
    local tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
    
    function updateTeamSettings(playerSource,cmd,R,G,B)
        local playerName = getPlayerName(playerSource)
        local account = getPlayerAccount (playerSource)
        local account_name = getAccountName(account)
        if isObjectInACLGroup ( "user." .. account_name, aclGetGroup ( "Admin" )) then
        if not tonumber(R) or not tonumber(G) or not tonumber(B) then outputChatBox("Syntex /color R G B",playerSource,255,255,255,true) return end
        if R <= 50 and G <= 50 and B <= 50 then
            colour.r = 255
            colour.g = 255
            colour.b = 255
        else
            colour.r = R
            colour.g = G
            colour.b = B
        end
            tagColor = rgbToHex(colour.r,colour.g,colour.b) or "#FFFFFF"
            triggerClientEvent(getRootElement(), "updateName", getRootElement(), homeName, homeTag, enemyName, enemyTag,colour.r,colour.g,colour.b)
            outputChatBox("Done Update",playerSource,255,255,255,true)
            local enemyTeam = getTeamFromName(enemyName)
            if enemyTeam then
                team[2] = enemyTeam
                updateTeamColour()
            else
                team[2] = createTeam ( enemyName, colour.r,colour.g,colour.b)
                if team[2] then
                    updateTeamColour()
                end
            end
        end
    end
    addCommandHandler("color",updateTeamSettings)
    
    
    function updateTeamColour()
        setTeamColor ( team[2], colour.r, colour.g, colour.b )
    end

     

×
×
  • Create New...