Jump to content

Need help with this bot for the guard


jingzhi

Recommended Posts

Server side

function createguard() 
    local guardped = createPed(281,1544.16125,-1631.99683,13.38281,0,true) 
    triggerClientEvent("giveguardm4",guardped) 
end 
  
addEventHandler("onResourceStart",getRootElement(),createguard) 

Client side

addEvent("giveguardm4",true) 
function sendguardm4() 
   outputChatBox("client event triggered")  
   guard = source 
    if guard then 
        givePedWeapon(guard,m4,5000,true) 
    end 
end 
addEventHandler("giveguardm4",getRootElement(),sendguardm4) 
  
function invadeguard(attacker) 
    if attacker and getElementType(attacker) == "player" then 
        local pedhp = getElementHealth (guard) 
        local tarhp = getElementHealth (attacker) 
        if pedhp > 0 and tarhp > 0 then 
        local x,y,z = getElementPosition(guard) 
            local ax,ay,az = getElementPosition(attacker) 
            local isclear = isLineOfSightClear (x,y,z+.6,ax,ay,az+.6, true, false, false, true, false, false, false) 
            if isclear == true then 
                local angle = ( 360 - math.deg ( math.atan2 ( ( ax - x ), ( ay - y ) ) ) ) % 360  
                if isPedDucked() 
                    setPedAimTarget(guard,ax,ay,az-.5) 
                    setPedControlState (guard,"fire",true) 
                else 
                    setPedAimTarget(guard,ax,ay,az) 
                    setPedControlState (guard,"fire",true) 
                end 
                setTimer(invadeguard,50,1,attacker) 
            end 
        end 
    end 
end 
addEventHandler("onClientPedDamage",guard,invadeguard) 

So I want to make this bot for the guard, which if someone attack the guard, guard will shoot him with the m4, but when i try to run this script the guard was not even given a m4, so I put a chatbox and findout the event of giving m4 was not even triggered, please tell me where have I done wrong, and if there is other error please also tell me, thank you very much :)

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