Jump to content

[HELP] Fire Ped Weapon


Imposter

Recommended Posts

Sorry I took so long, I have exams. >_> Anyways, I can't get the peds to move, even the forward control state doesnt work. I need some way for the ped to look at the player and shoot him. The shooting works, but the looking doesn't (The ped doesn't rotate). Help would be greatly appreciated.

Client.lua

  
function setPedMoveState(thePed, theMoveState) 
    local theLastPlayer = getElementData(thePed, "theLastPlayer"); 
    if (isElement(theLastPlayer) == true) then 
        local pedX, pedY, pedZ = getElementPosition(thePed); 
        local playerX, playerY, playerZ = getElementPosition(theLastPlayer); 
        local playerRot = getElementRotation(theLastPlayer); 
        if (playerX) and (playerY) and (playerZ) then 
            if(isLineOfSightClear(playerX, playerY, playerZ, pedX, pedY, pedZ, true, false, false, true, true, false, false)) then 
                if (theMoveState == true) then 
                    setPedLookAt(thePed, playerX, playerY, playerZ, 999999999, 200, theLastPlayer); 
                    setPedAimTarget(thePed, playerX, playerY, playerZ); 
                    setPedCameraRotation(thePed, (math.deg(math.atan2((playerX - pedX), (playerY - pedY)))) % 360); 
                    setPedControlState(thePed, "sprint", true); -- This doesn't work 
                    setPedControlState(thePed, "forward", true); -- This doesn't work 
                end 
            else 
                setPedControlState(thePed, "sprint", false); -- This doesn't work 
                setPedControlState(thePed, "forward", false); -- This doesn't work 
            end 
        end 
    end 
end 
addEvent("setPedMoveState", true); 
addEventHandler("setPedMoveState", getRootElement(), setPedMoveState); 
  
function setPedShootState(thePed, theShootState) 
    local theLastPlayer = getElementData(thePed, "theLastPlayer"); 
    if (isElement(theLastPlayer) == true) then 
        setPedControlState(thePed, "fire", theShootState); 
    end 
end 
addEvent("setPedShootState", true); 
addEventHandler("setPedShootState", getRootElement(), setPedShootState); 
  

Server.lua

thePeds = { 
    [0] = createPed(287, 152.85546875, 1929.802734375, 18.964239120483, 50.057220458984, true), 
    [1] = createPed(287, 160.578125, 1908.6025390625, 18.678409576416, 30.946228027344, true), 
    [2] = createPed(287, 185.9677734375, 1926.345703125, 17.759992599487, 181.6369934082, true), 
    [3] = createPed(287, 204.7578125, 1898.0029296875, 17.640625, 5.5619201660156, true), 
    [4] = createPed(287, 222.2822265625, 1897.9443359375, 17.640625, 18.388641357422, true) 
}; 
  
function givePedsWeapons() 
    table.foreach(thePeds, function(theIndex) 
        local thePed = thePeds[theIndex]; 
        if (thePed) then 
            giveWeapon(thePed, 31, 99999, true); 
        end 
    end); 
end 
addCommandHandler("gpw", givePedsWeapons); 
  
function givePedsBrains() 
    table.foreach(thePeds, function(theIndex) 
        setTimer(function() 
            local thePed = thePeds[theIndex]; 
            if (thePed) then 
                local theLastPlayer = getElementData(thePed, "theLastPlayer"); 
                if (theLastPlayer) and (getElementType(theLastPlayer) == "player") then 
                    if (isPedDead(theLastPlayer) == true) then 
                        local pedX, pedY, pedZ = getElementPosition(thePed); 
                        local playerX, playerY, playerZ = getElementPosition(theLastPlayer); 
                        local theDistance = getDistanceBetweenPoints3D(pedX, pedY, pedZ, playerX, playerY, playerZ); 
                        if (theDistance <= 15) then 
                            triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                            triggerClientEvent("setPedShootState", getRootElement(), thePed, true); 
                        elseif (theDistance > 15) and (theDistance <= 25) then 
                            triggerClientEvent("setPedMoveState", getRootElement(), thePed, true); 
                            triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                        elseif (theDistance <= 50) then 
                            triggerClientEvent("setPedMoveState", getRootElement(), thePed, true); 
                            triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                        else 
                            -- Get New Player! 
                            setElementData(thePed, "theLastPlayer", nil); 
                            triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                            triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                        end 
                    else 
                        -- Get New Player! 
                        setElementData(thePed, "theLastPlayer", nil); 
                        triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                        triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                    end 
                else 
                    for theIndex, thePlayer in ipairs(getElementsByType("player")) do 
                        if (isPedDead(thePlayer) == false) then 
                            local pedX, pedY, pedZ = getElementPosition(thePed); 
                            local playerX, playerY, playerZ = getElementPosition(thePlayer); 
                            local theDistance = getDistanceBetweenPoints3D(pedX, pedY, pedZ, playerX, playerY, playerZ); 
                            if (theDistance <= 15) then 
                                setElementData(thePed, "theLastPlayer", thePlayer); 
                                triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                                triggerClientEvent("setPedShootState", getRootElement(), thePed, true); 
                            elseif (theDistance > 15) and (theDistance <= 25) then 
                                setElementData(thePed, "theLastPlayer", thePlayer); 
                                triggerClientEvent("setPedMoveState", getRootElement(), thePed, true); 
                                triggerClientEvent("setPedShootState", getRootElement(), thePed, false);                                     
                            elseif (theDistance <= 50) then 
                                triggerClientEvent("setPedMoveState", getRootElement(), thePed, true); 
                                triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                                setElementData(thePed, "theLastPlayer", thePlayer); 
                            else 
                                -- Stop moving! 
                                setElementData(thePed, "theLastPlayer", nil); 
                                triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                                triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                            end 
                        else 
                            -- Get New Player! 
                            setElementData(thePed, "theLastPlayer", nil); 
                            triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                            triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                        end 
                    end 
                end 
            end 
        end, 50, 0); 
    end); 
end 
addCommandHandler("gpb", givePedsBrains); 

Link to comment

If you were at math hour's in class 7-8 then you know that in 3D world rotation between two 3D point's can be calculated with triangel methode and some atan2f. So in one word you don't need any function from MTA to get the angel between the two 3D point's.

Here is my first aimbot done in C++ in some FPS game. It used 3D world math to get the yaw/pitch for the camera (this can be very easy converted to get the rotation for the Ped)

I release this bk i don't need it anymore bk ATM i am using 2D world math angel (converting x,y,z to screen x,y and from there i can get the yaw/pitch for the camera) I done it in 2D math bk it's more precis like 3D math.

  
  
            D3DXVECTOR3 NewVector; 
            NewVector.x = pClientInfo->g_pLocal->Pos.x - g_pESP.pPlayers[AimAt].Aimcords.x; 
            NewVector.y = pClientInfo->g_pLocal->Pos.y - g_pESP.pPlayers[AimAt].Aimcords.y; 
            NewVector.z = pClientInfo->g_pLocal->Pos.z - g_pESP.pPlayers[AimAt].Aimcords.z; 
  
            float CamYaw = (float)atanf(NewVector.x/NewVector.z); 
            if(NewVector.z > 0.0f && NewVector.x < 0.0f && CamYaw < 0.0f) 
                CamYaw += D3DX_PI; 
            else if(NewVector.z > 0.0f && NewVector.x > 0.0f) 
                CamYaw += D3DX_PI; 
  
            DWORD tempKey = 0; 
            switch(AimbotKey) 
            { 
                default: 
                    tempKey = VK_LBUTTON; 
                break; 
             
                case 1: 
                    tempKey = VK_RBUTTON; 
                break; 
                 
                case 2: 
                    tempKey = VK_SHIFT; 
                break; 
            } 
            if((GetAsyncKeyState(tempKey) && !Aimbotkeyon) || (Aimbotkeyon)) 
            { 
                pClientInfo->g_pLocal->pitch    = (float)atan2f(NewVector.y,(float)sqrt(pow(NewVector.z,2) + pow(NewVector.x,2))); 
                pClientInfo->g_pLocal->yaw      = CamYaw; 
  
  

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