Jump to content

HELP - show health bot dx


WASSIm.

Recommended Posts

this script show health bot in DX and not working

CLIENT

   function onshowhealthnemesis ( nemesi) 
    dxDrawText("Health Nemesis: ".. getElementHealth(tostring(nemesi)), 10, (screenH - 16) / 2, (10) + 154, ( (screenH - 16) / 2) + 16, tocolor(255, 0, 0, 255), 1, "default-bold", "left", "top", false, false, true, false, false) 
    end 
    addEvent("onshowhealthnemesis", true) 
    addEventHandler( "onshowhealthnemesis", getRootElement(), onshowhealthnemesis ) 

SERVER

showBox ("info","Just some information") 
local spawnTable = { 
[1] = {-1935.5, 665.4, 47}, 
[2] = {2561.4,2779,11}, 
[3] = {-1008,-651,33}, 
[4] = {2203,-2250,14}, 
} 
  
local weaponTable = { 
[1] = {38}, 
[2] = {37}, 
} 
  
  
function Nemesisbymanawydan (player )   
       local x,y,z = unpack(spawnTable[math.random(1,4)]) 
       local weapons = unpack(weaponTable[math.random(1,2)]) 
       nemesi = exports [ "slothBot" ]:spawnBot (x,y,z, 90, 271, 0, 0, Nemesis, weapons, 
"hunting", true ) 
      triggerClientEvent ("onshowhealthnemesis", getRootElement(), nemesi) 
      outputChatBox ("Nemesis: STARS", getRootElement(), 255, 0, 0, true ) 
      myBlip = (createBlipAttachedTo ( nemesi, 23 )) 
 end 
addEventHandler("onResourceStart", resourceRoot, Nemesisbymanawydan)   
  
  
  
addEvent("onBotWasted",true) 
addEventHandler("onBotWasted",getRootElement(), 
function (killer) 
if (source == nemesi) then 
givePlayerMoney(killer,math.random(4000,6000)) 
killerName = getPlayerName(killer) 
weapon = getPedWeapon(killer) 
wr, wg, wb = getPlayerNametagColor(killer) 
exports.killmessages:outputMessage ( {killerName,{"padding",width=3},{"icon",id=weapon or 0},{"padding",width=3},{"color",r=255,g=0,b=0},"Nemesis"},getRootElement(),wr,wg,wb ) 
destroyElement(myBlip) 
setTimer(Nemesisbymanawydan, 1000, 1) 
end 
end)  

if restart script

mtascreen20130202164923.png

if i killing bot

sanstitrebl.png

Link to comment
When the resource starts ( server side ), and triggers the client side event, it outputs that error because the client side is not yet loaded.

Also, you need onClientRender to draw the the text, also, you would need to check if the "nemsi" element exists.

how fix ?

Link to comment

Simply use onClientResourceStart and triggerEvent or triggerServerEvent and tell the server you are ready. I usually pick the first option when I don't need any server data to be sent to client when he joins.

Link to comment
Simply use onClientResourceStart and triggerEvent or triggerServerEvent and tell the server you are ready. I usually pick the first option when I don't need any server data to be sent to client when he joins.

i don't understand

you can give me script fix plis

Link to comment

What you're trying to do is not as simple as what you think and has many errors. I'm rushing now and will not fix them for you. What does :spawnBot return? What does getElementHealth( tostring( ) ) is for? getElementHealth requires element (player/vehicle/ped) not a string.. You need to get back to basics. Check my peds example resource and see how I made health bar. https://community.multitheftauto.com/index.php?p= ... ils&id=234

Link to comment

i change new dx bar health and make show health in marker bot

SERVER

local spawnTable = { 
[1] = {-1935.5, 665.4, 47}, 
[2] = {2561.4,2779,11}, 
[3] = {-1008,-651,33}, 
[4] = {2203,-2250,14}, 
} 
  
local weaponTable = { 
[1] = {38}, 
[2] = {37}, 
} 
  
       local x,y,z = unpack(spawnTable[math.random(1,4)]) 
       local weapons = unpack(weaponTable[math.random(1,2)]) 
       local Marker1 = createMarker ( x, y, z, "cylinder", 5, 200, 200, 200, 200 ) 
  
function Nemesisbymanawydan (player )   
       nemesi = exports [ "slothBot" ]:spawnBot (x,y,z, 90, 271, 0, 0, Nemesis, weapons, 
"hunting", true ) 
      outputChatBox ("Nemesis: STARS", getRootElement(), 255, 0, 0, true ) 
      exports [ "extrahealth" ]:setElementExtraHealth ( nemesi, 2000 ) 
      myBlip = (createBlipAttachedTo ( nemesi, 23 )) 
      myMarker = (attachElements (Marker1, nemesi, 0, 0, 0 )) 
 end 
addEventHandler("onResourceStart", resourceRoot, Nemesisbymanawydan)   
  
function markerplayer( ) 
     triggerClientEvent ("PGHPVis", root, nemesi) 
end 
  addEventHandler ( "onMarkerHit", Marker1, markerplayer ) 
  
addEvent("onBotWasted",true) 
addEventHandler("onBotWasted",getRootElement(), 
function (killer) 
if (source == nemesi) then 
givePlayerMoney(killer,math.random(4000,6000)) 
killerName = getPlayerName(killer) 
weapon = getPedWeapon(killer) 
wr, wg, wb = getPlayerNametagColor(killer) 
exports.killmessages:outputMessage ( {killerName,{"padding",width=3},{"icon",id=weapon or 0},{"padding",width=3},{"color",r=255,g=0,b=0},"Nemesis"},getRootElement(),wr,wg,wb ) 
destroyElement(myBlip) 
setTimer(Nemesisbymanawydan, 1000, 1) 
end 
end) 
  
  

CLIENT

setDevelopmentMode(true) 
  
local MsgDisplayed 
local MsgTimer 
  
local screenWidth,screenHeight = guiGetScreenSize() 
  
  
  
local ProgressHPSettings = { 
    nemesi = nil; 
    x = screenWidth-450; 
    y = screenHeight*0.23; 
    w = 350; 
    h = 45; 
    colorBg = tocolor(0,0,0,180); 
    colorUg = tocolor(255,28,28,180); 
    colorText = tocolor(255,255,255,255); 
} 
  
function drawProgressHPBar() 
    dxDrawRectangle ( ProgressHPSettings.x, ProgressHPSettings.y, ProgressHPSettings.w, ProgressHPSettings.h, ProgressHPSettings.colorBg, false ) 
    dxDrawRectangle ( ProgressHPSettings.x+10, ProgressHPSettings.y+5, ((ProgressHPSettings.w-20)*(exports[ "extrahealth" ]:getElementExtraHealth ( ProgressHPSettings.nemesi )/getElementData(ProgressHPSettings.nemesi,'startHP')) > 0 and (ProgressHPSettings.w-20)*(exports[ "extrahealth" ]:getElementExtraHealth ( ProgressHPSettings.nemesi )/getElementData(ProgressHPSettings.nemesi,'startHP')) or 0), ProgressHPSettings.h-10, ProgressHPSettings.colorUg, false ) 
    dxDrawText ( tostring(math.floor(exports[ "extrahealth" ]:getElementExtraHealth ( ProgressHPSettings.nemesi ) > 0 and exports[ "extrahealth" ]:getElementExtraHealth ( ProgressHPSettings.nemesi ) or 0)).."hp/"..tostring(math.floor(getElementData(ProgressHPSettings.nemesi,'startHP') > 0 and getElementData(ProgressHPSettings.nemesi,'startHP') or 0)).."hp", ProgressHPSettings.x+10, ProgressHPSettings.y+5, (ProgressHPSettings.x+10) + (ProgressHPSettings.w-20), (ProgressHPSettings.y+5)+(ProgressHPSettings.h-10), ProgressHPSettings.colorText, 1.5, "default", "center", "center", true, true, false, false, true) 
end 
  
addEvent ( "showMsg", true ) 
addEventHandler ( "showMsg", root, 
    function (t, clr) 
        if ( not MsgDisplayed ) then 
            MsgDisplayed = dxMsgWindow:create( t, 0.35, 0.01, 0.3, 0.05, true, "default", 1, "center","center" ) 
            MsgDisplayed:colorText(unpack(clr)) 
            MsgDisplayed:colorRect(0,0,0,180) 
            MsgTimer = setTimer(function()MsgDisplayed:destroy();MsgTimer=nil;MsgDisplayed=nil;end,8000,1) 
            return 
        end 
        MsgDisplayed:text(t) 
        MsgDisplayed:colorText(unpack(clr)) 
        resetTimer ( MsgTimer ) 
    end 
) 
  
addEvent ( "PGHPVis", true ) 
addEventHandler ( "PGHPVis", root, 
    function (el) 
        if ( el ) then 
            ProgressHPSettings.nemesi = el 
            addEventHandler("onClientRender", root, drawProgressHPBar) 
        else 
            ProgressHPSettings.nemesi = nil; 
            removeEventHandler("onClientRender", root, drawProgressHPBar) 
        end 
    end 
) 

debugscript 3

sanstitreiw.png

Link to comment

Your line 23 has way too many calls. Split it into a few line because currently it's difficult to say which function fails. Also, make variable names shorter because it's difficult to read.

local extraHP = exports[ "extrahealth" ]:getElementExtraHealth ( ProgressHPSettings.nemesi ); -- output this value to see what getElementExtraHealth returns 
local startHP = getElementData(ProgressHPSettings.nemesi,'startHP'); -- output this value as well, use dxDrawText if you're debugging values in onClient(Pre/HUD)Render event 
dxDrawRectangle ( ProgressHPSettings.x+10, ProgressHPSettings.y+5, ((ProgressHPSettings.w-20)*(extraHP/startHP) > 0 and (ProgressHPSettings.w-20)*(extraHP/startHP) or 0), ProgressHPSettings.h-10, ProgressHPSettings.colorUg, false ) 

Link to comment
Your line 23 has way too many calls. Split it into a few line because currently it's difficult to say which function fails. Also, make variable names shorter because it's difficult to read.
local extraHP = exports[ "extrahealth" ]:getElementExtraHealth ( ProgressHPSettings.nemesi ); -- output this value to see what getElementExtraHealth returns 
local startHP = getElementData(ProgressHPSettings.nemesi,'startHP'); -- output this value as well, use dxDrawText if you're debugging values in onClient(Pre/HUD)Render event 
dxDrawRectangle ( ProgressHPSettings.x+10, ProgressHPSettings.y+5, ((ProgressHPSettings.w-20)*(extraHP/startHP) > 0 and (ProgressHPSettings.w-20)*(extraHP/startHP) or 0), ProgressHPSettings.h-10, ProgressHPSettings.colorUg, false ) 

nothing

add triggerClientEvent ("PGHPVis", root) ????

Link to comment

Check if markerplayer function is called. If it is, then check the client's script if you get the nemesis value sent from the server. Why don't you learn debugging? You MUST debug scripts yourself. You will get all the information you need to fix your script. Besides you don't give much information by saying:

nothing

add triggerClientEvent ("PGHPVis", root) ????

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