5150 Posted November 28, 2015 Share Posted November 28, 2015 dont ask why i need this, but does anyone know how to set a ped to godmode, and to make him attack only one certain team? i already have the script for attacking a ped, but it attacks everyone, and i dont want that. i want him attacking the Americans team. heres the client and serverside. thanks for the help 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) < 300 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 , 3000, 1) end ) server 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, 7) giveWeapon(peds, 38, 99999, true) end end end , 50, 0) function createSniperPed(x, y, z) local ped = createPed(286, x, y, z) setTimer( function() if isElement(ped) then giveWeapon(ped, 38, 99999, true) setPedWeaponSlot(ped, 7) 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
Olle Risk Posted November 28, 2015 Share Posted November 28, 2015 Not sure what you're using to control your peds but if it is slothbot you might wanna take a look at it's documentation. As far as I understand it should be possible to prevent attacking team mates in that resource. https://wiki.multitheftauto.com/wiki/Slothman/Slothbot Link to comment
5150 Posted November 29, 2015 Author Share Posted November 29, 2015 not slothbot. what you see is all there is Link to comment
Anubhav Posted November 29, 2015 Share Posted November 29, 2015 I made it to shoot Americans team only and godmode. 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, 7) giveWeapon(peds, 38, 99999, true) end end end , 50, 0) function createSniperPed(x, y, z) local ped = createPed(286, x, y, z) setTimer( function() if isElement(ped) then giveWeapon(ped, 38, 99999, true) setPedWeaponSlot(ped, 7) setElementData(ped, "type", "ped.sniper.npc") setElementFrozen(ped, true) setElementHealth(ped, 100) end end , 5000, 1) return ped end addEventHandler("sniperTakeDecision", getRootElement(), function(sniperPedID, aimPlayer) if getPlayerTeam(aimPlayer) and getTeamName(getPlayerTeam(aimPlayer)) == "Americans" then setElementData(sniperPedID, "target", aimPlayer) triggerClientEvent("sniperTakeDecisionClient", getRootElement(), sniperPedID, aimPlayer) end end ) *SERVER SIDE* Link to comment
5150 Posted November 30, 2015 Author Share Posted November 30, 2015 thanks! im glad you understood what i meant Link to comment
5150 Posted November 30, 2015 Author Share Posted November 30, 2015 hey while i have you here, is there a way to spawn several of these peds automatically on resource start? like where all i would have to do is add the coordinates into the script? Link to comment
5150 Posted November 30, 2015 Author Share Posted November 30, 2015 hey while i have you here, is there a way to spawn several of these peds automatically on resource start? like where all i would have to do is add the coordinates into the script? Link to comment
Anubhav Posted December 1, 2015 Share Posted December 1, 2015 You should not ask for scripts but I can help you out with functions and then you can make scripts and ask for help in it. you will need: Tables and Table Loops onResourceStart createPed and some more things according to your need Link to comment
5150 Posted December 1, 2015 Author Share Posted December 1, 2015 i never asked for one, only help with them but thanks 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