Jump to content

I need moving body guards with weapons


Minotaur

Recommended Posts

So i need moving body guards around me follow me wherewer i go even in to the car shoot him near me in players but i know them to be switched :D . I hope someone can help me thanks in advence! Sorry for the really bad english :o:o:cry:

and only use this script admins and moderators. :)

Link to comment
    local ablauf = {} 
    local ped = {} 
    local stat = {} 
    local firetimer = {} 
    local timer = {} 
    local jx, jy, jz = {}, {}, {} 
    local pedSayTimer = {} 
      
     end 
  
local function toggleFollower() 
    for index, p in next, ped do 
        if(isElement(p)) then 
            local player = getPlayerFromName(getElementData(p, "besitzer")) 
            if(player) and (ped[player]) then 
                if(isElement(p)) and (ablauf[player] == true) then 
                    if not(stat[p]) then 
                        stat[p] = {} 
                        timer[p] = {} 
                    end 
                    local owner = player 
                    if(owner) then 
                        local x, y, z = getElementPosition(owner) 
                        local x2, y2, z2 = getElementPosition(p) 
                        if(getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) > 3) then 
                            -- SPRINT CHECK -- 
                            stat[p]["running"] = true 
                            if(getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) > 10) then 
                                if(stat[p]["jumping"] ~= true) and (stat[p]["inveh"] ~= true) then 
                                    setPedAnimation(p, "ped" , "sprint_civi", -1, true, true, false) -- Sprintet 
                                end 
                            else 
                                if(stat[p]["jumping"] ~= true) and (stat[p]["inveh"] ~= true) then 
                                    setPedAnimation(p, "ped" , "JOG_maleA", -1, true, true, false) -- Joggt 
                                end 
                            end 
                            -- ROTATION -- 
                            local x1, y1 = getElementPosition(p) 
                            local x2, y2 = getElementPosition(owner) 
                            local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi 
                            rot = rot-90 
                            setPedRotation(p, rot) 
                            -- CAR -- 
                            local inveh = false 
                            if(isPedInVehicle(player)) then 
                                inveh = true 
                            end 
                            if(inveh == true) and (getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) < 4) then  
                                if(stat[p]["inveh"] ~= true) and (stat[p]["enterveh"] ~= true) then 
                                    stat[p]["enterveh"] = true 
                                    setPedAnimation(p) 
                                    triggerClientEvent(getRootElement(), "doPedEnter", player, p, true) 
                                    setTimer(function() 
                                        local occupants = getVehicleOccupants(getPedOccupiedVehicle(player)) 
                                        for i = 1, getVehicleMaxPassengers(getPedOccupiedVehicle(player)), 1 do 
                                            if not(occupants[i]) then 
                                                warpPedIntoVehicle(p, getPedOccupiedVehicle(player), i) 
                                                stat[p]["inveh"] = true 
                                                break; 
                                            end 
                                        end 
                                        stat[p]["enterveh"] = false 
                                    end, 2000, 1) 
                                end 
                            else 
                                if(stat[p]["inveh"] == true) and (stat[p]["enterveh"] == false) and(isPedInVehicle(player) == false) then -- er ist nicht im auto aber ich bin es 
                                    stat[p]["enterveh"] = true 
                                    triggerClientEvent(getRootElement(), "doPedExitVeh", player, p, true) 
                                    setTimer(function() 
                                        removePedFromVehicle(p) 
                                        stat[p]["enterveh"] = false 
                                        stat[p]["inveh"] = false 
                                    end, 1000, 1) 
                                end 
                            end 
                            -- JUMP CHECK  -- 
                            if(inveh == false) then 
                                if((z-z2) > 0.-- s8) --> and (getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) < 4) and (stat[p]["jumping"] ~= true) then -- er ist oben 
                                    stat[p]["jumping"] = true 
                                    setPedAnimation(p) 
                                    triggerClientEvent(getRootElement(), "doPedJump", player, p, true) 
                                    if(isTimer(timer[p]["jump"])) then killTimer(timer[p]["jump"]) end 
                                    timer[p]["jump"] = setTimer(function() 
                                        stat[p]["jumping"] = false 
                                        triggerClientEvent(getRootElement(), "doPedJump", player, p, false) 
                                    end, 800, 1) 
                                end 
                            end 
                        else 
                            if (stat[p]["running"] == true)then 
                                stat[p]["running"] = false 
                                setPedAnimation(p) 
                            end 
                        end 
                    else 
                        destroyElement(p) 
                    end 
                end 
            end 
        else 
            if(isElement(p)) then 
                destroyElement(p) 
            end 
            p = nil 
        end 
    end 
end 
  
    setTimer(functionscheck, 200, -1) 
    end 
addCommandHandler("follower", toggleFollower) 
    if(ablauf[p] == true) then return end 
    ablauf[p] = true 
    local x, y, z = getElementPosition(p) 
    ped[p] = createPed(164, x, y+1, z) 
    setElementData(ped[p], "besitzer", getPlayerName(p)) 
    setElementData(ped[p], "bodyguard", true) 
    setTimer(giveWeapon, 1000, 1, ped[p], 36, 99999, true) 
    setPedStat (ped[p], 72, 999) 
    setPedStat (ped[p], 76, 999) 
    setPedStat (ped[p], 74, 999) 
    --addEventHandler("onClientPedDamage", ped, on_damage_check) 
    pedSayTimer[ped[p]] = setTimer(doPedSaySomething, 5000, 1, ped[p]) 
    addEventHandler("onPedWasted", ped[p], function() 
        local ped = source 
        setTimer(destroyElement, 1000, 1, ped) 
        ablauf[p] = false 
         
    end) 
end) 
  

Please anybody help me in this script this is not good i want to toggle follower and only for admins but this is not good :(

Link to comment

And this is the client

local gMe = getLocalPlayer() 
  
addEvent("doPedJump", true) 
addEvent("doPedEnter", true) 
addEvent("doPedExitVeh", true) 
  
addEventHandler("doPedJump", getLocalPlayer(), function(p, boolean) 
    setPedControlState(p, "jump", boolean) 
end) 
  
addEventHandler("doPedEnter", getLocalPlayer(), function(p, boolean) 
    setPedControlState(p, "enter_passenger", boolean) 
end) 
  
addEventHandler("doPedExitVeh", getLocalPlayer(), function(p, boolean) 
    setPedControlState(p, "enter_exit", boolean) 
end) 
  
  
-- DAMAGE ABFRAGE -- 
  
local pedTarget = {} 
local pedTimer = {} 
local pedShooting = {} 
  
local function doPedAttackOtherPlayer(ped) 
    if(isTimer(pedTimer[ped])) or (isPedInVehicle(ped)) then 
        killTimer(pedTimer[ped]) 
    end 
    if(isElement(ped)) then 
        pedTimer[ped] = setTimer(function() 
            if(isElement(ped)) then 
                local target = pedTarget[ped] 
                if(target) then 
                    local x, y, z = getElementPosition(ped) 
                    local x2, y2, z2 = getElementPosition(target) 
                    if(isLineOfSightClear(x, y, z, x2, y2, z2, true, false, false, false, false, false)) then 
                        if(getElementHealth(target) > 1) then 
                            if(pedShooting[ped] ~= true) then 
                                --[[ 
                                local x1, y1 = getElementPosition(ped) 
                                local x2, y2 = getElementPosition(target) 
                                    local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi 
                                    rot = rot-90 
                                    setPedRotation(ped, rot) 
                                    setPedAnimation(ped) 
                                    if(getPedControlState(ped, "fire") ~= true) then 
                                        setPedControlState(ped, "fire", true) 
                                    end 
                                    setPedAimTarget(ped, x2, y2, z2)]] 
                                setPedControlState(ped, "fire", true) 
                                pedShooting[ped] = true 
                            else 
                                local x1, y1, z1 = getElementPosition(ped) 
                                local x2, y2, z2 = getElementPosition(target) 
                                local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi 
                                rot = rot-90 
                                setPedRotation(ped, rot) 
                                setPedAimTarget(ped, x2, y2, z2) 
                            end 
                        else 
                            killTimer(pedTimer[ped]) 
                            pedShooting[ped] = false 
                            setPedControlState(ped, "fire", false) 
                        end 
                    else 
                        killTimer(pedTimer[ped]) 
                        pedShooting[ped] = false 
                        setPedControlState(ped, "fire", false) 
                    end 
                end 
            else 
                killTimer(pedTimer[ped]) 
            end 
        end, 500, -1) 
    else 
        killTimer(pedTimer[ped]) 
    end 
end 
  
addEventHandler("onClientPedDamage", getRootElement(), function(attacker) 
    if(getElementData(source, "bodyguard") == true) then 
        if(attacker) and (isElement(attacker)) then 
            if(getElementType(attacker) == "player") or (getElementType(attacker) == "vehicle") then 
                pedTarget[source] = attacker 
                doPedAttackOtherPlayer(source) 
            end 
        end 
    end 
end) 
  
-- onClientRender Func -- 
  
  
addEventHandler("onClientRender", getRootElement(), function() 
    for index, p in pairs(getElementsByType("ped", getRootElement(), true)) do 
        if(getElementData(p, "bodyguard") == true) then 
            local owner = getElementData(p, "besitzer") 
            if(owner) then 
                local x, y, z = getElementPosition(p) 
                local x2, y2, z2 = getElementPosition(gMe) 
                if(isLineOfSightClear(x, y, z, x2, y2, z2, true, true, false, true)) then 
                    local sx, sy = getScreenFromWorldPosition(x, y, z+1) 
                    if(sx) and (sy) then 
                        local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) 
                        if(distance < 30) then 
                            dxDrawText(owner.."'s Bodyguard", sx+2, sy+2, sx, sy, tocolor(0, 0, 0, 200), 2-(distance/20), "arial", "center", "center") 
                            dxDrawText(owner.."'s Bodyguard", sx, sy, sx, sy, tocolor(0, 255, 0, 200), 2-(distance/20), "arial", "center", "center") 
                        end 
                    end 
                end 
            end 
        end 
    end 
end) 

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