Jump to content

Help with Peds


5150

Recommended Posts

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

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

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