Jump to content

How do I solve this?


Recommended Posts

Posted

I wanted your help because the ped is not getting the getElementPosition of all ped, and the "setPedAimTarget" is not completely working because no errors appear

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 
    ped[i] = createPed(math.random(26,41),peds[i][1],peds[i][2],peds[i][3]) 
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 rotationpedd ()

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


function atirar ()
    givePedWeapon(ped[i], 31, 500, true) 
    setPedControlState(ped[i], "fire", true)
end
addEventHandler("onClientPedDamage", root, atirar)

addEvent ("pedAtira", true)
addEventHandler ("pedAtira", getRootElement(), atirar)

function stopatirar ()
    givePedWeapon(ped[i], 31, 500, false) 
    setPedControlState(ped[i], "fire", false)
end
addEvent ("stopPedatira", true)
addEventHandler ("stopPedatira", getRootElement(), stopatirar)

ERROR: pedAtack/client.lua:12: attempt to peform arithmetic on local 'x1' (a boolean value)

code server

local zonaShot = createColRectangle ( -2400.04248, -620.97205, 50, 50 )
local radarShot = createRadarArea ( -2400.04248, -620.97205, 50, 50, 0, 255, 0, 175 )

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 )

Posted (edited)

Just change this:

getElementPosition(peds[i]) 

to this:

Quote

getElementPosition(ped[i]) 

 

Edited by Galactix

If I helped you, make sure you click the reaction button on the right to support me!
It will grant me more visibility and will help me to help others!

If you have any kind of request or subject you would like to discuss about with me,
don't hesitate to send me a private message about it!

 

Posted

peds = nil

i = nil

you should iterate everything through peds table:

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

for i=1,#peds do 
    ped[i] = createPed(math.random(26,41),peds[i][1],peds[i][2],peds[i][3]) 

  function rotationpedd ()

      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, rotationpedd)


  function atirar ()
      givePedWeapon(ped[i], 31, 500, true) 
      setPedControlState(ped[i], "fire", true)
  end
  addEventHandler("onClientPedDamage", root, atirar)

  addEvent ("pedAtira", true)
  addEventHandler ("pedAtira", getRootElement(), atirar)

  function stopatirar ()
      givePedWeapon(ped[i], 31, 500, false) 
      setPedControlState(ped[i], "fire", false)
  end
  addEvent ("stopPedatira", true)
  addEventHandler ("stopPedatira", getRootElement(), stopatirar)
end

also i fixed some mistakes here

Posted
1 hour ago, Juuve said:

 

Could you help me with handlerRespawn? in debugscript no error appears, And the respawn function after death is not working ?Can you tell me what to do? 

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

local pedsParent = createElement("pedsParent")
local id = {} -- do not edit this table


for i=1,#peds do 
    ped[i] = createPed(math.random(26,41),peds[i][1],peds[i][2],peds[i][3])
    
  function spawnPed( peds,index)
        ped[i] = createPed(math.random(26,41),peds[i][1],peds[i][2],peds[i][3]) 
        setElementParent(ped[i], pedsParent)
        id[ped[i]] = index 
  end


  function handleRespawn()

        local index = id[source]
        if index then
            id[source] = nil 
            local peds = peds[index] 
            if peds then
                setTimer(destroyElement, 1000, 1, source) 
                setTimer(spawnPed, 1500, 1, peds, index)
            end
        end
  end
  addEventHandler("onPedWasted", pedsParent, handleRespawn)

  function rotationpedd ()

      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, rotationpedd)


  function atirar ()
      givePedWeapon(ped[i], 31, 500, true) 
      setPedControlState(ped[i], "fire", true)
  end
  addEventHandler("onClientPedDamage", root, atirar)

  addEvent ("pedAtira", true)
  addEventHandler ("pedAtira", getRootElement(), atirar)

  function stopatirar ()
      givePedWeapon(ped[i], 31, 500, false) 
      setPedControlState(ped[i], "fire", false)
  end
  addEvent ("stopPedatira", true)
  addEventHandler ("stopPedatira", getRootElement(), stopatirar)
end


 

Posted
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

local pedsParent = createElement("pedsParent")
local id = {} -- do not edit this table


for i=1,#peds do 
    ped[i] = createPed(math.random(26,41),peds[i][1],peds[i][2],peds[i][3])
  	setElementData(ped[i],"ped:index",i)
    
  function spawnPed(i)
        ped[i] = createPed(math.random(26,41),peds[i][1],peds[i][2],peds[i][3]) 
        setElementParent(ped[i], pedsParent)
  end


  function handleRespawn()

        if getElementData(source,"ped:index") then
            index = getElementData(source,"ped:index")
            setTimer(destroyElement, 1000, 1, source) 
            setTimer(spawnPed, 1500, 1, index)
        end
  end
  addEventHandler("onPedWasted", pedsParent, handleRespawn)

  function rotationpedd ()

      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, rotationpedd)


  function atirar ()
      givePedWeapon(ped[i], 31, 500, true) 
      setPedControlState(ped[i], "fire", true)
  end
  addEventHandler("onClientPedDamage", root, atirar)

  addEvent ("pedAtira", true)
  addEventHandler ("pedAtira", getRootElement(), atirar)

  function stopatirar ()
      givePedWeapon(ped[i], 31, 500, false) 
      setPedControlState(ped[i], "fire", false)
  end
  addEvent ("stopPedatira", true)
  addEventHandler ("stopPedatira", getRootElement(), stopatirar)
end

i guess i fixed handlerRespawn. Check it

Posted (edited)

Sorry for posting again, I could not edit, the scripts are not working and nothing debug appears

57 minutes ago, Juuve said:

i guess i fixed handlerRespawn. Check it

someone would know to tell me what happens setPedAimTarget for 20 seconds he hits and then to

Edited by kevincouto6
Posted (edited)
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 Juuve
Posted (edited)
8 hours ago, Juuve said:

 

Sorry trouble again "The functions of detecting the player entering the zone are not working the problems can be in my script server" ? ""no debug no error appears""

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
addEventHandler("onClientPedDamage", root, atirar)
addEvent ("pedAtira", true)
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)

 

Edited by kevincouto6
Posted
1 hour ago, kevincouto6 said:

 has some error when the player enters the zone the peds are not shooting

you should hit ped to make it attack you in your script

Posted
3 hours ago, Juuve said:

you should hit ped to make it attack you in your script

Are they to make the protection of a place there is the possibility, to make them shoot when they invade the zone?

Posted
9 hours ago, kevincouto6 said:

Are they to make the protection of a place there is the possibility, to make them shoot when they invade the zone?

i think you can. Use colshapes or colspheres attached to npcs

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