I want to make a script, that if a player is aiming at a Ped than it will do something, like an animation. Here I triend to instantly kill the Ped if I aim at it, but I am a starter at this, and can't make it

local retval true, entity entity =

GetEntityPlayerIsFreeAimingAt(

    player player

)

if retval = true then

ApplyDamageToPed(

ped ped, 

damageAmount 500, 

armorFirst false

)

What the actual F is that code? Did you just copy and paste what’s in the Natives reference without understanding the absolute basics of code?
Do yourself a favor and take some classes on programming first, please - will save you a lot of nerves!

I just want that to work.

It never will with the way you wrote it, that’s for sure :smiley:
Let me give you an example of what should work, however I dont have a test environment ready that I can use to verify if it does or not. At least it’s a step in the right direction:

Citizen.CreateThread(function()
    local player = PlayerPedId()

    if IsPlayerFreeAiming(player) then
        if GetEntityPlayerIsFreeAimingAt(player) then
            local GetEntityPlayerIsFreeAimingAt(player) = entity
            if IsEntityAPed(entity) then
                -- Do whatever with "entity" as it's confirmed 
                -- to be a ped being aimed at by the player
            end
        end
    else
        Citizen.Wait(100)
    end
end)

Stuff like this definitely requires at least some basic knowledge about scripting, so like I said please don’t try and hack things together so they work before learning the very basics.

1 Like

the above code is missing a while true and also the local is the wrong way round, fixed it below.

Citizen.CreateThread(function()
    while true do 
        Citizen.Wait(5)

        local player = PlayerPedId()

        if IsPlayerFreeAiming(player) then
            if GetEntityPlayerIsFreeAimingAt(player) then
                local entity = GetEntityPlayerIsFreeAimingAt(player)
                if IsEntityAPed(entity) then
                    -- Do whatever with "entity" as it's confirmed 
                    -- to be a ped being aimed at by the player
                end
            end
        else
            Citizen.Wait(100)
        end
    end
end)
2 Likes

Thank you very much.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.