Jump to content

Scripting NEED HELP


CsaliHUN

Recommended Posts

Hi Everyone!
Can someone help me, how can I make that, if a fire is created it outputs the chatbox the fire's position (example: "The LSPD is on fire" or "The Hospital is on fire" .


 

The Script Files:

FireC.lua

local fireElement = {}

addEvent("FireServer.rootFireCreate",true)
addEventHandler("FireServer.rootFireCreate",getRootElement(),function(rand)
	local fire = createFire(FirePositions[rand][1], FirePositions[rand][2], FirePositions[rand][3], FirePositions[rand][4], FirePositions[rand][5], FirePositions[rand][6])
	fireElement[#fireElement + 1] = fire
end)

addEventHandler ("onClientResourceStart", getRootElement(), 
function (res)
	if res ~= getThisResource() then return end
	triggerServerEvent("FireServer.loadMe", localPlayer, localPlayer)
end)

function draw()
	for k,v in ipairs(getElementsByType("object")) do
		if getElementData(v, "Fire->object") then
			local x, y ,z = getElementPosition(v)
			local wx, wy, wz = getScreenFromWorldPosition(x , y, z+1)
			if wx and wy then
				local playerx, playery, playerz = getElementPosition(getLocalPlayer())
				if getDistanceBetweenPoints3D(playerx, playery, playerz, wx, wy, wz) <= 5 then 
					dxDrawRectangle(wx-200/2,wy,200,30,tocolor(0,0,0,255/2))
					dxDrawRectangle(wx-200/2+5,wy+5,190,20,tocolor(124, 197, 118,255/2))
				end
			end
		end
	end
end
addEventHandler("onClientRender", root, draw)

FireG.lua

FirePositions = { -- X, Y, Z, Range(FireSize)
[1] = {2114.1240234375, -1756.2508544922, 13.3984375, 800},
}

FireS.lua

local loadedPlayers = {}
local fireBar = {}
FireServer = {}

function FireServer.start(player)
	loadedPlayers[#loadedPlayers + 1] = player
end
addEvent("FireServer.loadMe", true)
addEventHandler("FireServer.loadMe", root, FireServer.start)

function FireServer.FireCreate()
	if math.random(1, 3) == 2 then
		local rand = math.random(#FirePositions)
		if fireBar[rand] then return end
		for k,v in pairs(loadedPlayers) do
			triggerClientEvent(v, "FireServer.rootFireCreate", v, rand)
			fireBar[rand] = createObject(1337, FirePositions[rand][1], FirePositions[rand][2], FirePositions[rand][3] - 1)
			setElementAlpha(fireBar[rand], 0)
			setElementCollisionsEnabled(fireBar[rand], false)
			setElementData(fireBar[rand], "Fire->object", true)
		end
	end
end
setTimer(FireServer.FireCreate, 1000, 0)

 

Link to comment
  • Administrators

FireC.lua

addEvent("FireServer.rootFireCreate",true)
addEventHandler("FireServer.rootFireCreate",getRootElement(),function(rand)
    local fire = createFire(FirePositions[rand][1], FirePositions[rand][2], FirePositions[rand][3], FirePositions[rand][4])
    fireElement[#fireElement + 1] = fire
    outputChatBox(FirePositions[rand].name.." is on fire!") --output to chatbox the name of location
end)

 

FireG.lua

FirePositions = { -- X, Y, Z, Range(FireSize)
[1] = {2114.1240234375, -1756.2508544922, 13.3984375, 800, name = "Location Name"}, --include name of location
}

 

Edited by LopSided_
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...