Zsoltisz Posted October 3, 2016 Share Posted October 3, 2016 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
koragg Posted October 3, 2016 Share Posted October 3, 2016 Is that script client side? Link to comment
Zsoltisz Posted October 3, 2016 Author Share Posted October 3, 2016 Yes. That's client side. Link to comment
aka Blue Posted October 3, 2016 Share Posted October 3, 2016 You need to add a the bone that you want to get the position from: float float float getPedBonePosition ( ped thePed, int bone ) Link to comment
Zsoltisz Posted October 3, 2016 Author Share Posted October 3, 2016 I need to add this picture for upper my head. So i can do it with BONE_HEAD2? Can you show me how, please? Link to comment
Mr.Loki Posted October 3, 2016 Share Posted October 3, 2016 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
Zsoltisz Posted October 3, 2016 Author Share Posted October 3, 2016 (edited) Ohh Thank you my friend. I understand. I type it for my script but i got error again... Edited October 3, 2016 by Zsoltisz Miss picture. Link to comment
Walid Posted October 3, 2016 Share Posted October 3, 2016 All what you need : dxDrawImageOnElement Link to comment
Zsoltisz Posted October 4, 2016 Author Share Posted October 4, 2016 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
Mr.Loki Posted October 4, 2016 Share Posted October 4, 2016 @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
Mr.Loki Posted October 4, 2016 Share Posted October 4, 2016 What errors are in the debug? Link to comment
Zsoltisz Posted October 4, 2016 Author Share Posted October 4, 2016 Nothing... I don't see nothing prob with this. Link to comment
Mr.Loki Posted October 4, 2016 Share Posted October 4, 2016 (edited) post your full code Edited October 4, 2016 by loki2143 Link to comment
Zsoltisz Posted October 4, 2016 Author Share Posted October 4, 2016 That's the full code :DDDD Maybe this is the problem? Link to comment
iPrestege Posted October 4, 2016 Share Posted October 4, 2016 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
Mr.Loki Posted October 4, 2016 Share Posted October 4, 2016 oh god... 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
Zsoltisz Posted October 4, 2016 Author Share Posted October 4, 2016 ahh. It's don't working for me :(( Link to comment
Walid Posted October 4, 2016 Share Posted October 4, 2016 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
Zsoltisz Posted October 5, 2016 Author Share Posted October 5, 2016 Yeah!! Working. But now i see my logo too. How can i disable it? Link to comment
Walid Posted October 5, 2016 Share Posted October 5, 2016 1 hour ago, Zsoltisz said: Yeah!! Working. But now i see my logo too. How can i disable it? if players[i] ~= localPlayer then end Link to comment
Zsoltisz Posted October 5, 2016 Author Share Posted October 5, 2016 Okay. Thank you my friend. Have a nice day Link to comment
Walid Posted October 6, 2016 Share Posted October 6, 2016 10 hours ago, Zsoltisz said: Okay. Thank you my friend. Have a nice day You are welcome Link to comment
Zsoltisz Posted October 6, 2016 Author Share Posted October 6, 2016 Sorry for i type again 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
Walid Posted October 6, 2016 Share Posted October 6, 2016 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now