Jump to content

Admin logo


Zsoltisz

Recommended Posts

Hello guys. Whats the problem with my script? :(

prob:

lua: source_file.lua:30: attempt to call global 'addEventHandler' (a nil value)
imgW = 64
imgH = 64
function adminLogo()
	adminszolis = getElementData(targetPlayer, "adminduty")
    if (exports.StarMTA_core:Fejleszto(targetPlayer) == true and adminszolis == true or exports.StarMTA_core:Fejleszto(thePlayer) == true) then
    for i,player in ipairs() do
        if player ~= localPlayer then
            local cX, cY, cZ = getCameraMatrix()
            local hX, hY, hZ = getPedBonePosition(player)
            hZ = hZ + 1.0
            local pX,pY,pZ = getPedBonePosition(localPlayer)
            pZ = pZ + 1.0
            if getScreenFromWorldPosition(hX, hY, hZ) and isLineOfSightClear(cX,cY,cZ, pX,pY,pZ) then
                local sX, sY, sD = getScreenFromWorldPosition(hX, hY, hZ)
                local relative = (50 - sD) / 50
                if relative > 0 then
                    local iW = imgW * relative
                    local iH = imgH * relative
 
                    local iX = sX - (iW / 2)
                    local iY = sY - (iH / 2)
 
                    dxDrawImage(iX, iY, iW, iH, "admin.png")
                end
            end
        end
    end
end
end
addEventHandler("onClientRender", root, adminLogo)

 

Link to comment
13 minutes ago, Zsoltisz said:

I need to add this picture for upper my head. So i can do it with BONE_HEAD2? Can you show me how, please? :/

follow click on the function @aka Blue "getPedBonePosition" just said to go to the wiki where it explains how to get the bone position so that u can use that position to place the picture at that bone location.

you have to use the ID not the name of the bone so "BONE_HEAD2" ID is 6 so

local hX, hY, hZ = getPedBonePosition(player, 6)

 

Link to comment
9 hours ago, Walid said:

All what you need : dxDrawImageOnElement

Thats OK. But how can i put image upper my head?

 

Player = getPedBonePosition(player, 6)
tag = dxCreateTexture("Duty/Fejleszto_Duty.png")

function Fejleszto_Duty()
	adminszolis = getElementData(targetPlayer, "adminduty")
    if (exports.StarMTA_core:Fejleszto(targetPlayer) == true and adminszolis == true or exports.StarMTA_core:Fejleszto(thePlayer) == true) then
	dxDrawImageOnElement(Player,tag)
		end
	end
addEventHandler("onClientPreRender", root, Fejleszto_Duty)

 

Link to comment

@Zsoltisz

getPedBonePosition returns 3 values (x,y,z) it does not return the player.

Your code specifies a "targetPlayer" which I'm  guessing is the player so i think that you should use that.

local tag = dxCreateTexture("Duty/Fejleszto_Duty.png")

function Fejleszto_Duty()
    adminszolis = getElementData(targetPlayer, "adminduty")
    if (exports.StarMTA_core:Fejleszto(targetPlayer) == true and adminszolis == true or exports.StarMTA_core:Fejleszto(thePlayer) == true) then
		dxDrawImageOnElement(targetPlayer,tag)
  	end
end
addEventHandler("onClientPreRender", root, Fejleszto_Duty)

try this.

Link to comment

Are you sure that you define this function : dxDrawImageOnElement ?

If you didn't put this useful function in your script add it :

 

function dxDrawImageOnElement(TheElement,Image,distance,height,width,R,G,B,alpha)
				local x, y, z = getElementPosition(TheElement)
				local x2, y2, z2 = getElementPosition(localPlayer)
				local distance = distance or 20
				local height = height or 1
				local width = width or 1
                                local checkBuildings = checkBuildings or true
                                local checkVehicles = checkVehicles or false
                                local checkPeds = checkPeds or false
                                local checkObjects = checkObjects or true
                                local checkDummies = checkDummies or true
                                local seeThroughStuff = seeThroughStuff or false
                                local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false
                                local ignoredElement = ignoredElement or nil
				if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then
					local sx, sy = getScreenFromWorldPosition(x, y, z+height)
					if(sx) and (sy) then
						local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
						if(distanceBetweenPoints < distance) then
							dxDrawMaterialLine3D(x, y, z+1+height-(distanceBetweenPoints/distance), x, y, z+height, Image, width-(distanceBetweenPoints/distance), tocolor(R or 255, G or 255, B or 255, alpha or 255))
						end
					end
			end
	end

 

Link to comment

oh god...

  1. local tag = dxCreateTexture("Duty/Fejleszto_Duty.png")
    
    function Fejleszto_Duty()
      for _,player in pairs(getElementsByType'player')do
      	if getElementData(player, "adminduty") then
      		dxDrawImageOnElement(player,tag,20,2.3) -- adjust 2.3 to how high you want the image ofer the player
    	end
    end
    addEventHandler("onClientPreRender", root, Fejleszto_Duty)
      
      -- this is a custom function and must be declared in your code
    function dxDrawImageOnElement(TheElement,Image,distance,height,width,R,G,B,alpha) 
        local x, y, z = getElementPosition(TheElement)
        local x2, y2, z2 = getElementPosition(localPlayer)
        local distance = distance or 20
        local height = height or 1
        local width = width or 1
        local checkBuildings = checkBuildings or true
        local checkVehicles = checkVehicles or false
        local checkPeds = checkPeds or false
        local checkObjects = checkObjects or true
        local checkDummies = checkDummies or true
        local seeThroughStuff = seeThroughStuff or false
        local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false
        local ignoredElement = ignoredElement or nil
    	if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then
    		local sx, sy = getScreenFromWorldPosition(x, y, z+height)
    		if(sx) and (sy) then
    			local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
    			if(distanceBetweenPoints < distance) then
    							dxDrawMaterialLine3D(x, y, z+1+height-(distanceBetweenPoints/distance), x, y, z+height, Image, width-(distanceBetweenPoints/distance), tocolor(R or 255, G or 255, B or 255, alpha or 255))
    			end
    		end
    	end
    end

     

Link to comment
1 hour ago, Zsoltisz said:

ahh. It's don't working for me :((

Try this 

local tag = dxCreateTexture("Duty/Fejleszto_Duty.png")

function Fejleszto_Duty()
    local players = getElementsByType("player")
    for i = 1 , #players do
        if getElementData(players[i], "adminduty") then
           dxDrawImageOnElement(players[i],tag)
        end 
    end
end
addEventHandler("onClientPreRender", root, Fejleszto_Duty)
  

function dxDrawImageOnElement(TheElement,Image,distance,height,width,R,G,B,alpha) 
    local x, y, z = getElementPosition(TheElement)
    local x2, y2, z2 = getElementPosition(localPlayer)
    local distance = distance or 20
    local height = height or 1
    local width = width or 1
    local checkBuildings = checkBuildings or true
    local checkVehicles = checkVehicles or false
    local checkPeds = checkPeds or false
    local checkObjects = checkObjects or true
    local checkDummies = checkDummies or true
    local seeThroughStuff = seeThroughStuff or false
    local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false
    local ignoredElement = ignoredElement or nil
    if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then
        local sx, sy = getScreenFromWorldPosition(x, y, z+height)
        if(sx) and (sy) then
            local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
            if(distanceBetweenPoints < distance) then
               dxDrawMaterialLine3D(x, y, z+1+height-(distanceBetweenPoints/distance), x, y, z+height, Image, width-(distanceBetweenPoints/distance), tocolor(R or 255, G or 255, B or 255, alpha or 255))
            end
        end
    end
end

 

Link to comment

Sorry for i type again :D But i see my logo too again but i added this code. Here is the full code:

function Fejleszto_Duty()
local tag = dxCreateTexture("Duty/Fejleszto_Duty.png")
		local players = getElementsByType("player")
		for _,player in pairs(getElementsByType'player')do
			local adminduty = getElementData (player, "adminduty" )
			if (exports.StarMTA_core:Fejleszto(player) and adminduty == 1 and getElementAlpha(player) == 255 ) then
				dxDrawImageOnElement(player,tag,20,1) -- adjust 2.3 to how high you want the image ofer the player
			if players[_] ~= localPlayer then
   
			end
			end
	end
end
addEventHandler("onClientPreRender", root, Fejleszto_Duty)

function Tulajdonos_Duty()
	local tag2 = dxCreateTexture("Duty/Tulajdonos_Duty.png")
	local players = getElementsByType("player")
		for _,player in pairs(getElementsByType'player')do
			local adminduty = getElementData ( player, "adminduty" )
			if (exports.StarMTA_core:Tulajdonos(player) and adminduty == 1 and getElementAlpha(player) == 255 ) then
				dxDrawImageOnElement(player,tag2,20,1) -- adjust 2.3 to how high you want the image ofer the player
			if players[_] ~= localPlayer then
   
			end
			end
		end
end
addEventHandler("onClientPreRender", root, Tulajdonos_Duty)


    function dxDrawImageOnElement(TheElement,Image,distance,height,width,R,G,B,alpha)
    				local x, y, z = getElementPosition(TheElement)
    				local x2, y2, z2 = getElementPosition(localPlayer)
    				local distance = distance or 20
    				local height = height or 1
    				local width = width or 1
                                    local checkBuildings = checkBuildings or true
                                    local checkVehicles = checkVehicles or false
                                    local checkPeds = checkPeds or false
                                    local checkObjects = checkObjects or true
                                    local checkDummies = checkDummies or true
                                    local seeThroughStuff = seeThroughStuff or false
                                    local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false
                                    local ignoredElement = ignoredElement or nil
    				if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then
    					local sx, sy = getScreenFromWorldPosition(x, y, z+height)
    					if(sx) and (sy) then
    						local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
    						if(distanceBetweenPoints < distance) then
    							dxDrawMaterialLine3D(x, y, z+1+height-(distanceBetweenPoints/distance), x, y, z+height, Image, width-(distanceBetweenPoints/distance), tocolor(R or 255, G or 255, B or 255, alpha or 255))
    						end
    					end
    			end
    	end

 

Link to comment
local tag = dxCreateTexture("Duty/Fejleszto_Duty.png")
local tag2 = dxCreateTexture("Duty/Tulajdonos_Duty.png")

function Fejleszto_Duty()
    local players = getElementsByType("player")
    for i = 1 , #players do
        local adminduty = getElementData(players[i], "adminduty") or 0
        local alpha = getElementAlpha(players[i]) or 0
        if tonumber(adminduty) == 1 and alpha == 255 then 
            if players[i] ~= localPlayer then
                if exports.StarMTA_core:Fejleszto(players[i]) then 
                    dxDrawImageOnElement(players[i],tag)
                elseif exports.StarMTA_core:Tulajdonos(players[i]) then 
                    dxDrawImageOnElement(players[i],tag2)
                end 
            end 
        end 
    end
end
addEventHandler("onClientRender", root, Fejleszto_Duty)
  

function dxDrawImageOnElement(TheElement,Image,distance,height,width,R,G,B,alpha) 
    local x, y, z = getElementPosition(TheElement)
    local x2, y2, z2 = getElementPosition(localPlayer)
    local distance = distance or 20
    local height = height or 1
    local width = width or 1
    local checkBuildings = checkBuildings or true
    local checkVehicles = checkVehicles or false
    local checkPeds = checkPeds or false
    local checkObjects = checkObjects or true
    local checkDummies = checkDummies or true
    local seeThroughStuff = seeThroughStuff or false
    local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false
    local ignoredElement = ignoredElement or nil
    if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then
        local sx, sy = getScreenFromWorldPosition(x, y, z+height)
        if(sx) and (sy) then
            local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
            if(distanceBetweenPoints < distance) then
               dxDrawMaterialLine3D(x, y, z+1+height-(distanceBetweenPoints/distance), x, y, z+height, Image, width-(distanceBetweenPoints/distance), tocolor(R or 255, G or 255, B or 255, alpha or 255))
            end
        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...