Bean666 Posted May 4, 2015 Share Posted May 4, 2015 hello i downloaded a sniperNPC resource is it possible that there will be a teamname called "Military" that they won't attack? client.lua: function isMyPingTheLowest() local players = getElementsByType("player") local yes = true for i, player in ipairs(players) do if getPlayerPing(getLocalPlayer()) > getPlayerPing(player) then yes = false end end if yes == true then return true else return false end end 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 addEventHandler("onClientPedDamage", getRootElement(), function(attacker) if getElementData(source, "type") == "ped.sniper.npc" and getElementData(attacker, "type") == "ped.sniper.npc" then cancelEvent() end end ) setTimer( function() if isMyPingTheLowest() then for i, peds in ipairs(getElementsByType("ped")) do if getElementData(peds, "type") == "ped.sniper.npc" and getElementHealth(peds) > 0 then local x, y, z = getElementPosition(peds) local lowest = nil local player = nil for i, players in ipairs(getElementsByType("player")) do local px, py, pz = getElementPosition(players) if getDistanceBetweenPoints3D(x, y, z, px, py, pz) < 100 then if lowest == nil then lowest = getDistanceBetweenPoints3D(x, y, z, px, py, pz) player = players else if getDistanceBetweenPoints3D(x, y, z, px, py, pz) < lowest then lowest = getDistanceBetweenPoints3D(x, y, z, px, py, pz) player = players end end end end if isElement(player) then triggerServerEvent("sniperTakeDecision", getRootElement(), peds, player) end end end end end , 1500, 0) addEvent("sniperTakeDecisionClient", true) addEventHandler("sniperTakeDecisionClient", getRootElement(), function(sniperPedID, aimPlayer) local x, y, z = getElementPosition(sniperPedID) local px, py, pz = getElementPosition(aimPlayer) setPedAimTarget(sniperPedID, px, py, pz) local rotZ = findRotation(x, y, px, py) setPedRotation(sniperPedID, rotZ) setPedControlState(sniperPedID, "aim_weapon", true) setPedControlState(sniperPedID, "fire", true) setTimer( function() if isElement(sniperPedID) then setPedControlState(sniperPedID, "fire", false) setPedControlState(sniperPedID, "aim_weapon", false) end end , 500, 1) end ) server.lua: addEvent("sniperTakeDecision", true) addCommandHandler("sniper", function(thePlayer, command) local x, y, z = getElementPosition(thePlayer) local int = getElementInterior(thePlayer) local ped = createSniperPed(x, y, z) setElementInterior(ped, int) end ) setTimer( function() for i, peds in ipairs(getElementsByType("ped")) do if getElementData(peds, "type") == "ped.sniper.npc" and getElementHealth(peds) > 0 then setPedWeaponSlot(peds, 6) giveWeapon(peds, 34, 10000, true) end end end , 50, 0) function createSniperPed(x, y, z) local ped = createPed(285, x, y, z) setTimer( function() if isElement(ped) then giveWeapon(ped, 34, 10000, true) setPedWeaponSlot(ped, 6) setElementData(ped, "type", "ped.sniper.npc") setElementFrozen(ped, true) end end , 5000, 1) return ped end addEventHandler("sniperTakeDecision", getRootElement(), function(sniperPedID, aimPlayer) setElementData(sniperPedID, "target", aimPlayer) triggerClientEvent("sniperTakeDecisionClient", getRootElement(), sniperPedID, aimPlayer) end ) Link to comment
WhoAmI Posted May 4, 2015 Share Posted May 4, 2015 onClientPlayerDamage Check if attacker was sniper and damaged player team was military. If so, cancel event. Link to comment
WhoAmI Posted May 4, 2015 Share Posted May 4, 2015 addEventHandler("onClientPlayerDamage", localPlayer, function(attacker) if ( getElementData(attacker, "type") == "ped.sniper.npc" and getTeamFromName("Military") == getPlayerTeam(source) ) then cancelEvent() end ) Link to comment
Bean666 Posted May 6, 2015 Author Share Posted May 6, 2015 since i put that code in client.lua , they won't attack any players anymore , even tho i'm in the otherteam. Link to comment
ma2med Posted May 6, 2015 Share Posted May 6, 2015 Client: function isMyPingTheLowest() local players = getElementsByType("player") local yes = true for i, player in ipairs(players) do if getPlayerPing(getLocalPlayer()) > getPlayerPing(player) then yes = false end end if yes == true then return true else return false end end 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 addEventHandler("onClientPedDamage", getRootElement(), function(attacker) if getElementData(source, "type") == "ped.sniper.npc" and getElementData(attacker, "type") == "ped.sniper.npc" then cancelEvent() end end ) setTimer( function() if isMyPingTheLowest() then for i, peds in ipairs(getElementsByType("ped")) do if getElementData(peds, "type") == "ped.sniper.npc" and getElementHealth(peds) > 0 then local x, y, z = getElementPosition(peds) local lowest = nil local player = nil for i, players in ipairs(getElementsByType("player")) do local px, py, pz = getElementPosition(players) if getDistanceBetweenPoints3D(x, y, z, px, py, pz) < 100 then if lowest == nil then lowest = getDistanceBetweenPoints3D(x, y, z, px, py, pz) player = players else if getDistanceBetweenPoints3D(x, y, z, px, py, pz) < lowest then lowest = getDistanceBetweenPoints3D(x, y, z, px, py, pz) player = players end end end end if isElement(player) and getTeamName(getPlayerTeam(player)) ~= "Military" then triggerServerEvent("sniperTakeDecision", getRootElement(), peds, player) end end end end end , 1500, 0) addEvent("sniperTakeDecisionClient", true) addEventHandler("sniperTakeDecisionClient", getRootElement(), function(sniperPedID, aimPlayer) local x, y, z = getElementPosition(sniperPedID) local px, py, pz = getElementPosition(aimPlayer) setPedAimTarget(sniperPedID, px, py, pz) local rotZ = findRotation(x, y, px, py) setPedRotation(sniperPedID, rotZ) setPedControlState(sniperPedID, "aim_weapon", true) setPedControlState(sniperPedID, "fire", true) setTimer( function() if isElement(sniperPedID) then setPedControlState(sniperPedID, "fire", false) setPedControlState(sniperPedID, "aim_weapon", false) end end , 500, 1) end ) Link to comment
Bean666 Posted May 6, 2015 Author Share Posted May 6, 2015 doesn't work. edit: works now thank you. 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