GerardWay Posted April 2, 2015 Share Posted April 2, 2015 Hey guys! I was wondering if anyone could help me out here. I have a bot that spawns and attacks players, but I'd like to have 2 things changed about it: - The ProgressBar needs to only appear on a Players screen when he is near the bot - More spawnpoints for this bot need to be added I'd be grateful if anyone could help:) client local screenX, screenY = guiGetScreenSize() -- Settings local nemesisMaxHP = 2500 local progressWidth, progressHeight = 400, 20 local progressX, progressY = (screenX - progressWidth) / 2, 100 local dxTextTitle = "Nemesis HP:" local dxTextScale = 1.5 local dxTextFont = "Bluenote" local dxTextColor = tocolor(255, 255, 255, 255) -- Initiate Skins addEventHandler("onClientResourceStart", resourceRoot, function() local txd = engineLoadTXD("nemesis.txd", 312 ) local dff = engineLoadDFF("nemesis.dff", 312 ) engineImportTXD(txd, 312) engineReplaceModel(dff, 312) end ) -- Calculated variables ( no need to touch ) local dxTextWidth = dxGetTextWidth(dxTextTitle, dxTextScale, dxTextFont) local dxTextHeight = dxGetFontHeight(dxTextScale, dxTextFont) local dxPosX, dxPosY = (screenX - dxTextWidth) / 2, progressY - 7 - dxTextHeight -- Don't touch these local cProgress, theNemesis, nemesisMaxHP addEvent("onReceiveNemesis", true) addEventHandler("onReceiveNemesis", resourceRoot, function (nemesis, maxHealth) if ( nemesis ) then cProgress = 100 theNemesis = nemesis nemesisMaxHP = maxHealth + 100 addEventHandler("onClientRender", getRootElement(), renderDX) end end ) function renderDX() if ( theNemesis and isElement(theNemesis) and cProgress ) then local nemesisCurrentHP = exports.extra_health:getElementExtraHealth(theNemesis) + getElementHealth(theNemesis) cProgress = nemesisCurrentHP < 0 and 0 or (nemesisCurrentHP / nemesisMaxHP) -- Draw the Title Text dxDrawText(dxTextTitle, dxPosX - 2, dxPosY - 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX - 2, dxPosY, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX + 2, dxPosY - 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX, dxPosY - 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX, dxPosY + 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX + 2, dxPosY + 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX + 2, dxPosY, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX - 2, dxPosY + 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX, dxPosY, dxTextWidth, dxTextHeight, dxTextColor, dxTextScale, dxTextFont) -- Draw the BG DX Rectangle dxDrawImage(progressX-5, progressY-5, progressWidth+10, progressHeight+10, "files/bar_bg.png") -- Draw the progress dxDrawImageSection(progressX, progressY, progressWidth * cProgress, progressHeight, progressX, progressY, progressWidth, progressHeight, "files/bar_progress.png") -- Draw the dead text if ( cProgress == 0 and isPedDead(theNemesis) ) then dxDrawText("The Nemesis has been defeated - Please wait for the next one to Spawn.", progressX, progressY, progressWidth, progressHeight, dxTextColor, dxTextScale, dxTextFont) end else removeEventHandler("onClientRender", getRootElement(), renderDX) end end Server -- Settings local nemesisSpawnMSG = "The nemesis has spawned!" local nemesisKillMoney = 15000 local nemesisKillLocalMSG = "You have assisted killing the Nemesis ( " .. tostring(nemesisKillMoney) .. ")" -- Special Variables addEventHandler("onResourceStart", resourceRoot, function () createNemesis(-1935.5480957031, 665.44055175781, 47.0, 90, 2500, 312, 0, 0, nil, 38, "attacking", true) setTimer(createNemesis, 300000, 0, -1935.5480957031, 665.44055175781, 47.0, 90, 2500, 312, 0, 0, nil, 0, "chasing", true) end ) addEventHandler("onResourceStop", resourceRoot, function() if theNemesis then destroyElement(theNemesis) end end ) function createNemesis(botX, botY, botZ, botR, maxHP, skinID, interior, dimension, theTeam, weapon, theMode, theModesubject) if ( exports["slothBot"] and exports["extra_health"] and not theNemesis ) then theNemesis = exports["slothBot"]:spawnBot(botX, botY, botZ, botR, skinID, interior, dimension, theTeam, weapon, theMode, theModesubject) maxHealth = maxHP exports["extra_health"]:setElementExtraHealth(theNemesis, maxHealth) local theBlip = createBlipAttachedTo(theNemesis, 23) outputChatBox(nemesisSpawnMSG, getRootElement(), 255, 0, 0) addEventHandler("onBotWasted", theNemesis, function() -- Destroy the blip once the bot dies destroyElement(theBlip) theNemesis = nil -- Award money to all players nearby local bX, bY, bZ = getElementPosition(source) local pCount = 0 for index, player in ipairs(getElementsByType("player")) do local pX, pY, pZ = getElementPosition(player) if ( getDistanceBetweenPoints3D(bX, bY, bZ, pX, pY, pZ) <= 100 ) then outputChatBox(nemesisKillLocalMSG, player, 255, 0, 0) givePlayerMoney(player, nemesisKillMoney) end end outputChatBox("The nemesis has been defeated by " .. tostring(pCount) .. " players!", getRootElement(), 255, 0, 0) end ) for player, _ in pairs ( isReady ) do triggerClientEvent(player, "onReceiveNemesis", resourceRoot, theNemesis, maxHealth) end end end addEvent("onBotWasted", true) Link to comment
Enargy, Posted April 2, 2015 Share Posted April 2, 2015 - The ProgressBar needs to only appear on a Players screen when he is near the bot You could use getDistanceBetweenPoints3D - More spawnpoints for this bot need to be added You can insert into a table different spawnpoints Link to comment
GerardWay Posted April 2, 2015 Author Share Posted April 2, 2015 Could you possibly help me out with the bar visible distance please? I managed to make him spawn at different locations, so now it's just the bar left:3 Link to comment
Enargy, Posted April 3, 2015 Share Posted April 3, 2015 try this function renderDX() if ( theNemesis and isElement(theNemesis) and cProgress ) then local nemesisCurrentHP = exports.extra_health:getElementExtraHealth(theNemesis) + getElementHealth(theNemesis) cProgress = nemesisCurrentHP < 0 and 0 or (nemesisCurrentHP / nemesisMaxHP) -- Draw the Title Text dxDrawText(dxTextTitle, dxPosX - 2, dxPosY - 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX - 2, dxPosY, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX + 2, dxPosY - 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX, dxPosY - 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX, dxPosY + 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX + 2, dxPosY + 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX + 2, dxPosY, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX - 2, dxPosY + 2, dxTextWidth, dxTextHeight, tocolor(0, 0, 0, 255), dxTextScale, dxTextFont) dxDrawText(dxTextTitle, dxPosX, dxPosY, dxTextWidth, dxTextHeight, dxTextColor, dxTextScale, dxTextFont) local x1, y1, z1 = getElementPosition(theNemesis) local x2, y2, z2 = getElementPosition(getLocalPlayer()) if getDistanceBetweenPoints3D(x1, y1, z1,x2, y2, z2) < 10 then -- the minimum distance that must be the player to make the text visible. -- Draw the BG DX Rectangle dxDrawImage(progressX-5, progressY-5, progressWidth+10, progressHeight+10, "files/bar_bg.png") -- Draw the progress dxDrawImageSection(progressX, progressY, progressWidth * cProgress, progressHeight, progressX, progressY, progressWidth, progressHeight, "files/bar_progress.png") end -- Draw the dead text if ( cProgress == 0 and isPedDead(theNemesis) ) then dxDrawText("The Nemesis has been defeated - Please wait for the next one to Spawn.", progressX, progressY, progressWidth, progressHeight, dxTextColor, dxTextScale, dxTextFont) end else removeEventHandler("onClientRender", getRootElement(), renderDX) end end Link to comment
GerardWay Posted April 3, 2015 Author Share Posted April 3, 2015 Thank you! [ADMIN PLEASE DELETE TOPIC] Link to comment
Castillo Posted April 3, 2015 Share Posted April 3, 2015 There's no reason to remove the topic, if you didn't want people to be able to copy the code, then you shouldn't have posted it in a public forum. Link to comment
Recommended Posts