kevincouto6 Posted July 7, 2018 Share Posted July 7, 2018 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 ) Link to comment
Galactix Posted July 7, 2018 Share Posted July 7, 2018 (edited) Just change this: getElementPosition(peds[i]) to this: Quote getElementPosition(ped[i]) Edited July 7, 2018 by Galactix Link to comment
kevincouto6 Posted July 7, 2018 Author Share Posted July 7, 2018 20 minutes ago, Galactix said: Just change this: getElementPosition(peds[i]) to this: The error keeps happening Link to comment
JeViCo Posted July 7, 2018 Share Posted July 7, 2018 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 Link to comment
kevincouto6 Posted July 7, 2018 Author Share Posted July 7, 2018 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 Link to comment
JeViCo Posted July 7, 2018 Share Posted July 7, 2018 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 Link to comment
kevincouto6 Posted July 7, 2018 Author Share Posted July 7, 2018 (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 July 7, 2018 by kevincouto6 Link to comment
JeViCo Posted July 7, 2018 Share Posted July 7, 2018 (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 July 7, 2018 by Juuve Link to comment
kevincouto6 Posted July 8, 2018 Author Share Posted July 8, 2018 (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 July 8, 2018 by kevincouto6 Link to comment
kevincouto6 Posted July 8, 2018 Author Share Posted July 8, 2018 25 minutes ago, Juuve said: what do you mean? has some error when the player enters the zone the peds are not shooting Link to comment
JeViCo Posted July 8, 2018 Share Posted July 8, 2018 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 Link to comment
kevincouto6 Posted July 8, 2018 Author Share Posted July 8, 2018 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? Link to comment
JeViCo Posted July 9, 2018 Share Posted July 9, 2018 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 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now