Jump to content

Poderia Me ajudar


Recommended Posts

Desculpe por postar outro tropico, mas consegui usar as funções, porem agora tenho outro problema, eu criei a tabela com os PED porem não se as funções aplicam-se apenas no primeiro PED e não em todos

 

client-side

--client-side

local ped = {} 
local peds = { 
{-2374.55151, -595.38910, 132.11719}, 
{-2376.55908, -596.57813, 132.11719}, 
{-2376.33325, -591.77344, 132.11171}, 
} 
for i=1,#peds do 
    thePed = createPed(math.random(26,41),peds[i][1],peds[i][2],peds[i][3] +0.5, 269) 
end 

function findRotation( x1, y1, x2, y2 ) 
    local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
    return t < 0 and t + 360 or t
end

function ped ()
	local x1 ,y1, z = getElementPosition(thePed) 
	local x2, y2, sz = getElementPosition(localPlayer)
	
	setPedAimTarget(thePed, x2, y2, sz)
	setPedRotation(thePed, findRotation( x1, y1, x2, y2 ))
end
addEventHandler("onClientRender", root, ped) 

function atirar ()
	givePedWeapon(thePed, 31, 500, true) 
	setPedControlState(thePed, "fire", true)
end
addEventHandler("onClientPedDamage", root, atirar)
addEvent ("pedAtira", true)
addEventHandler ("pedAtira", getRootElement(), atirar)

function stopatirar ()
	givePedWeapon(thePed, 31, 500, false) 
	setPedControlState(thePed, "fire", false)
end
addEvent ("stopPedatira", true)
addEventHandler ("stopPedatira", getRootElement(), stopatirar)

server-side

local zonaShot = createColRectangle ( -2400.04248, -620.97205, 25, 25 )
local radarShot = createRadarArea ( -2400.04248, -620.97205, 25, 25, 0, 255, 0, 175 )
--server-side

function enterZone ( thePlayer, matchingDimension )
        if getElementType ( thePlayer ) == "player" then 
			triggerClientEvent (thePlayer, "pedAtira", thePlayer)
        end
end
addEventHandler ( "onColShapeHit", zonaShot, enterZone )

function sairZone ( thePlayer, matchingDimension )
        if getElementType ( thePlayer ) == "player" then 
			triggerClientEvent (thePlayer, "stopPedatira", thePlayer)
        end
end
addEventHandler ( "onColShapeLeave", zonaShot, sairZone )

 

Link to comment
  • Other Languages Moderators

Naquele seu loop da parte client-side entre a linha 9 e 11, você está usando a mesma variável para todos os Peds (thePed), dai só vai funcionar 1 vez. Os demais Peds são perdidos. Sugiro que use ped[ i ] no lugar.

Edited by Lord Henry
Link to comment
16 hours ago, Lord Henry said:

Naquele seu loop da parte client-side entre a linha 9 e 11, você está usando a mesma variável para todos os Peds (thePed), dai só vai funcionar 1 vez. Os demais Peds são perdidos. Sugiro que use ped[ i ] no lugar.

function findRotation( x1, y1, x2, y2 ) 
    local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
    return t < 0 and t + 360 or t
end

function peds ()
    local x1 ,y1, z = getElementPosition(ped[ i ]) 
    local x2, y2, sz = getElementPosition(localPlayer)
    
    setPedAimTarget(ped[ i ], x2, y2, sz)
    setPedRotation(ped[ i ], findRotation( x1, y1, x2, y2 ))
end
addEventHandler("onClientRender", root, peds) 

Nesta função esta tendo um erro " local x1 ,y1, z = getElementPosition(ped[ i ])  " attlemp to index local 'data'( a nill value) "

Edited by kevincouto6
Link to comment

N esta funcionando, devido a não checagem da posição do ped, acredito que o erro seja na checagem de varios peds juntas se fosse apenas um funciona mas como tem mais de um ñ esta funcionando

22 minutes ago, Lord Henry said:

Como está o resto do código?

 

Link to comment
  • 2 weeks later...

Alguem pode me ajudar a função de detectar quando o player entra na zona, não esta fazendo os peds atirar ?

local ped_ = {} 
local peds = { 
{-2374.55151, -595.38910, 132.11719}, 
{-2376.55908, -596.57813, 132.11719}, 
{-2376.33325, -591.77344, 132.11171}, 
} 
function findRotation( x1, y1, x2, y2 ) 
    local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
    return t < 0 and t + 360 or t
end
function spawnPed(i)
	ped_[i] = createPed(math.random(26,41),peds[i][1],peds[i][2],peds[i][3])
	setElementData(ped_[i],"ped:custom_ped",true)
  	setElementData(ped_[i],"ped:index",i)
end
addEventHandler("onClientResourceStart",resourceRoot,function()
	for i=1,#peds do 
		spawnPed(i)
	end
end)
function atirar ()
	if source then
		if getElementData(source,"ped:custom_ped") then
			ped = source
			givePedWeapon(ped, 31, 500, true) 
			setPedControlState(ped, "fire", true)
		end
	end
end
addEvent ("pedAtira", true)
addEventHandler("onClientPedDamage", root, atirar)
addEventHandler ("pedAtira", getRootElement(), atirar)

function stopatirar ()
	for _, ped in ipairs(getElementsByType("ped")) do
		if getElementData(ped,"ped:custom_ped") then
			if isElementStreamedIn (ped) then
				givePedWeapon(ped, 31, 500, false) 
				setPedControlState(ped, "fire", false)
			end
		end
	end
end
addEvent ("stopPedatira", true)
addEventHandler ("stopPedatira", getRootElement(), stopatirar)
function handleRespawn()
	if getElementData(source,"ped:custom_ped") then
		index = getElementData(source,"ped:index")
		setTimer(destroyElement, 1000, 1, source) 
		setTimer(spawnPed, 1500, 1, index)
	end
end
addEventHandler("onClientPedWasted", getRootElement(), handleRespawn)
function rota ()
	for _, ped in pairs(getElementsByType("ped")) do
		if getElementData(ped,"ped:custom_ped") then
			if isElementStreamedIn (ped) then
				local x1 ,y1, z1 = getElementPosition(ped) 
				local x2, y2, z2 = getElementPosition(localPlayer)
				setPedAimTarget(ped, x2, y2, z2)
				setElementRotation(ped, 0,0,180+findRotation( x2, y2, x1, y1 ))
			end
		end
	end
end
addEventHandler("onClientRender", root, rota)

 

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