JR10 Posted March 19, 2014 Share Posted March 19, 2014 Here, tested and worked: local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'player' and #guards > 0) then -- He's a player target = attacker removeEventHandler('onClientPreRender', root, followPlayer) addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local x, y, z = getElementPosition(target) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end local tx, ty, tz = getElementPosition(guard) setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) end end Link to comment
LiOneLMeSsIShoT Posted March 19, 2014 Author Share Posted March 19, 2014 Here, tested and worked: local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'player' and #guards > 0) then -- He's a player target = attacker removeEventHandler('onClientPreRender', root, followPlayer) addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local x, y, z = getElementPosition(target) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end local tx, ty, tz = getElementPosition(guard) setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) end end Hmm?? Are you sure that it worked? because when zombies hit my guard or even hit me the guard do nothing. and whatever i think this script made to attack "Player" who attacks me only.. because it's onClientPlayerDamage..and whatever there's exported functions that called "isPedZombie" I think it should help in the script ... --check if a ped is a zombie or not function isPedZombie(ped) if (isElement(ped)) then if (getElementData (ped, "zombie") == true) then return true else return false end else return false end end addEvent( "onZombieLostPlayer", true ) That's the Check.. Link to comment
JR10 Posted March 19, 2014 Share Posted March 19, 2014 I've changed it to onClientPedDamage, I missed the fact that you need it for zombies. I also added the exported isPedZombie in the check. Try this: local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'ped' and exports.zombies:isPedZombie(attacker) and #guards > 0) then -- He's a zombie target = attacker removeEventHandler('onClientPreRender', root, followPlayer) addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local x, y, z = getElementPosition(target) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end local tx, ty, tz = getElementPosition(guard) setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) end end Link to comment
LiOneLMeSsIShoT Posted March 19, 2014 Author Share Posted March 19, 2014 I've changed it to onClientPedDamage, I missed the fact that you need it for zombies. I also added the exported isPedZombie in the check.Try this: local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'ped' and exports.zombies:isPedZombie(attacker) and #guards > 0) then -- He's a zombie target = attacker removeEventHandler('onClientPreRender', root, followPlayer) addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local x, y, z = getElementPosition(target) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end local tx, ty, tz = getElementPosition(guard) setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) end end Yeah man i want it to check if zombies are the attackers or even player, not only zombies or only players...whatever there's error: :46: call failed to call "zombies:isPedZombie" Link to comment
LiOneLMeSsIShoT Posted March 19, 2014 Author Share Posted March 19, 2014 zombies resource running ? Yep Running. and other script exported that isPedZombie and works fine. but this script not. Link to comment
JR10 Posted March 19, 2014 Share Posted March 19, 2014 The export is only server-side. You can still use the synchronized element data to check if the ped is a zombie. local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'ped' and getElementData(attacker, 'zombie') and #guards > 0) then -- He's a zombie target = attacker removeEventHandler('onClientPreRender', root, followPlayer) addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local x, y, z = getElementPosition(target) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end local tx, ty, tz = getElementPosition(guard) setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) end end Link to comment
LiOneLMeSsIShoT Posted March 19, 2014 Author Share Posted March 19, 2014 The export is only server-side. You can still use the synchronized element data to check if the ped is a zombie. local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'ped' and getElementData(attacker, 'zombie') and #guards > 0) then -- He's a zombie target = attacker removeEventHandler('onClientPreRender', root, followPlayer) addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local x, y, z = getElementPosition(target) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end local tx, ty, tz = getElementPosition(guard) setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) end end alright man, actually it have a lot of really strange things: 1-When Zombie hit the guard he do nothing 2-when i block from zombie attacks the guard do nothing, so he's waiting for the guard to success with hitting me 3-when the guard is already Shoting in zombie after zombie hits me.. the shots don't even effect on the zombie...like nothing happen to him 4- when i spawn another guard and the guard that already spawned shot some zombie "the guard that i spawned for now hits the other guard" so the guards hit each other of i spawn one and the other already shoting 5- When the zombie move away the guard Don't want to follow me or even try to chase the zombie and actually i want the guard trys to hit the zombie if he see him in about 5 or 6 distance I'm """"Sorry"""" for making it long but this Bugged things will make the script Fail and give no sense Link to comment
JR10 Posted March 19, 2014 Share Posted March 19, 2014 The script will only work when a zombie damages you, so blocking the zombie will not trigger the event. You easily describe your issues, but you don't put any effort in trying to fix them. You need the guard to stop hitting the zombie if he moves too far, don't you know about getDistanceBetweenPoints3D? You don't try to solve your issues, why should we? Link to comment
LiOneLMeSsIShoT Posted March 19, 2014 Author Share Posted March 19, 2014 The script will only work when a zombie damages you, so blocking the zombie will not trigger the event. You easily describe your issues, but you don't put any effort in trying to fix them. You need the guard to stop hitting the zombie if he moves too far, don't you know about getDistanceBetweenPoints3D? You don't try to solve your issues, why should we? Because this script is "Complex" you made it by complex way because the function is made in the 3 argument of the addEventHandler so it's hard for a begginer like me anyway i have tried it : local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'ped' and getElementData(attacker, 'zombie') and #guards > 0) then -- He's a zombie target = attacker removeEventHandler('onClientPreRender', root, followPlayer) addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local ax, ay, az = getElementPosition(target) local tx, ty, tz = getElementPosition(guard) local x, y, z = getElementPosition(localPlayer) local bx, by, bz = getPedBonePosition(target, 1) local weapon = getPedWeaponSlot (guard) local targetDis = getDistanceBetweenPoints3D (tx, ty, tz, ax, ay, az) for index, guard in pairs(guards) do if (targetDis > 20) and (weapon == 30) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(ax, ay, az)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end if (targetDis > 15) and (weapon == 22) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(ax, ay, az)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end end end i did what i can with this script but i got errors now: 72: attempt to compare number with boolean 70:bad argument @ "getDistanceBetweenPoints3D Expected number at argument 1, got boolean 69: bad argument @ "getPedWeaponSlot" 66: bad argument @ "getElementPosition" Link to comment
LiOneLMeSsIShoT Posted March 19, 2014 Author Share Posted March 19, 2014 The script will only work when a zombie damages you, so blocking the zombie will not trigger the event. You easily describe your issues, but you don't put any effort in trying to fix them. You need the guard to stop hitting the zombie if he moves too far, don't you know about getDistanceBetweenPoints3D? You don't try to solve your issues, why should we? ? ;/ so? Link to comment
LiOneLMeSsIShoT Posted March 19, 2014 Author Share Posted March 19, 2014 HElp Please guys????? Link to comment
LiOneLMeSsIShoT Posted March 20, 2014 Author Share Posted March 20, 2014 HElp Please guys????? help please Link to comment
JR10 Posted March 20, 2014 Share Posted March 20, 2014 Stop posting multiple times asking for help, it will get you banned. Try this: local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'ped' and getElementData(attacker, 'zombie') and #guards > 0) then -- He's a zombie target = attacker removeEventHandler('onClientPreRender', root, followPlayer) addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local ax, ay, az = getElementPosition(target) local x, y, z = getElementPosition(localPlayer) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do local tx, ty, tz = getElementPosition(guard) local targetDis = getDistanceBetweenPoints3D (tx, ty, tz, ax, ay, az) local weapon = getPedWeaponSlot (guard) if (targetDis > 20) and (weapon == 30) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(ax, ay, az)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end if (targetDis > 15) and (weapon == 22) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(ax, ay, az)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end end end Link to comment
LiOneLMeSsIShoT Posted March 21, 2014 Author Share Posted March 21, 2014 Stop posting multiple times asking for help, it will get you banned.Try this: local guards = {} function moveGuard() table.insert(guards, source) addEventHandler('onClientPedDamage', source, function(attacker) if attacker == localPlayer then cancelEvent() end end) end addEvent("moveGuard",true) addEventHandler ("moveGuard", getRootElement(), moveGuard) function followPlayer() for index, guard in pairs(guards) do if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, index) else local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) local tint, tdim = getElementInterior(guard), getElementDimension(guard) if (int ~= tint) then setElementInterior(guard, int) end if (dim ~= tdim) then setElementDimension(guard, dim) end local x, y, z = getElementPosition(localPlayer) local tx, ty, tz = getElementPosition(guard) local dis = getDistanceBetweenPoints2D (x, y, tx, ty) setPedRotation(guard, findRotation(tx, ty, x, y)) if (dis > 2) then setPedControlState(guard, 'forwards', true) else setPedControlState(guard, 'forwards', false) end if (dis > 4) then setPedControlState(guard, 'sprint', true) else setPedControlState(guard, 'sprint', false) end end end end addEventHandler('onClientPreRender', root, followPlayer) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end return t end local target addEventHandler ("onClientPlayerDamage", localPlayer, function(attacker) if (isElement(attacker) and getElementType(attacker) == 'ped' and getElementData(attacker, 'zombie') and #guards > 0) then -- He's a zombie target = attacker removeEventHandler('onClientPreRender', root, followPlayer) addEventHandler('onClientRender', root, aimForTarget) end end) function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local ax, ay, az = getElementPosition(target) local x, y, z = getElementPosition(localPlayer) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do local tx, ty, tz = getElementPosition(guard) local targetDis = getDistanceBetweenPoints3D (tx, ty, tz, ax, ay, az) local weapon = getPedWeaponSlot (guard) if (targetDis > 20) and (weapon == 30) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(ax, ay, az)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end if (targetDis > 15) and (weapon == 22) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(ax, ay, az)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end end end Errors: :38: attempt to perform arithmetic on local 'y2' (a nil value) Link to comment
Moderators Citizen Posted March 21, 2014 Moderators Share Posted March 21, 2014 Ok, I understood the code even if it's pretty dirty, replace the aimForTarget function: function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local ax, ay, az = getElementPosition(target) local x, y, z = getElementPosition(localPlayer) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do local tx, ty, tz = getElementPosition(guard) local targetDis = getDistanceBetweenPoints3D (tx, ty, tz, ax, ay, az) local weapon = getPedWeaponSlot (guard) if (targetDis > 20) and (weapon == 30) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(tx, ty, ax, ay)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end if (targetDis > 15) and (weapon == 22) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(tx, ty, ax, ay)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end end end (edited line 26 and 36) Link to comment
LiOneLMeSsIShoT Posted March 22, 2014 Author Share Posted March 22, 2014 Ok, I understood the code even if it's pretty dirty, replace the aimForTarget function: function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local ax, ay, az = getElementPosition(target) local x, y, z = getElementPosition(localPlayer) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do local tx, ty, tz = getElementPosition(guard) local targetDis = getDistanceBetweenPoints3D (tx, ty, tz, ax, ay, az) local weapon = getPedWeaponSlot (guard) if (targetDis > 20) and (weapon == 30) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(tx, ty, ax, ay)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end if (targetDis > 15) and (weapon == 22) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(tx, ty, ax, ay)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end end end (edited line 26 and 36) Actually now when zombie hit me ...the guard do nothing and when 2 zombies attacks me i get error: :49: 'addEventHandler': 'onClientRender' with function is already handled Link to comment
LiOneLMeSsIShoT Posted March 23, 2014 Author Share Posted March 23, 2014 Ok, I understood the code even if it's pretty dirty, replace the aimForTarget function: function aimForTarget() if (#guards == 0) then removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end if (not isElement(target) or isPedDead(target)) then for index, guard in pairs(guards) do if (isElement(guard)) then setPedControlState(guard, 'fire', false) end end removeEventHandler('onClientRender', root, aimForTarget) addEventHandler('onClientPreRender', root, followPlayer) return end local ax, ay, az = getElementPosition(target) local x, y, z = getElementPosition(localPlayer) local bx, by, bz = getPedBonePosition(target, 1) for index, guard in pairs(guards) do local tx, ty, tz = getElementPosition(guard) local targetDis = getDistanceBetweenPoints3D (tx, ty, tz, ax, ay, az) local weapon = getPedWeaponSlot (guard) if (targetDis > 20) and (weapon == 30) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(tx, ty, ax, ay)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end if (targetDis > 15) and (weapon == 22) then if (not isElement(guard) or isPedDead(guard)) then table.remove(guards, guard) return end setPedRotation(guard, findRotation(tx, ty, x, y)) setPedAimTarget(guard, bx, by, bz) setPedControlState(guard, 'fire', true) else setPedRotation (guard, findRotation(tx, ty, ax, ay)) setPedAimTarget(guard, bx, by, bz, false) setPedControlState(guard, 'fire', false) end end end (edited line 26 and 36) Actually now when zombie hit me ...the guard do nothing and when 2 zombies attacks me i get error: :49: 'addEventHandler': 'onClientRender' with function is already handled I think this error comes because the guard can't handle more than one attacker? Link to comment
Moderators Citizen Posted March 23, 2014 Moderators Share Posted March 23, 2014 It's just a warning because you want them to start follow or aim a bot (idk since you didn't say which line it was) but you never told them to stop doing that action where you should. By the way they are doing the action you want already, so I guess there is no problem. Just read your script again step by step and you will maybe find where/when you should use removeEventHandler. Link to comment
LiOneLMeSsIShoT Posted March 24, 2014 Author Share Posted March 24, 2014 It's just a warning because you want them to start follow or aim a bot (idk since you didn't say which line it was) but you never told them to stop doing that action where you should.By the way they are doing the action you want already, so I guess there is no problem. Just read your script again step by step and you will maybe find where/when you should use removeEventHandler. They're not doing the action i want man i'm just trying to say in the script "when the zombie which the ped is attacking is away from him then the ped will follows him to make the distance about 10 and then starts to shot him" and actually the most of the script i can't understand because That guy helped me that he made the script more Complex and i'm actually need help to understand it too. 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