Jump to content

Shooting with ped


arezu

Recommended Posts

When i create a ped and give it a weapon, and then i fire it, then it only fires for like 1 second and then it only shows the animation(doesn't give the effects of shooting).

  
--server side 
addCommandHandler("dude", 
function(thePlayer) 
    local gunner = createPed(0, 0, 0, 0) 
    giveWeapon(gunner, 31, 999999999, true) 
    local posX, posY, posZ = getElementPosition(thePlayer) 
    setElementPosition(gunner, posX + 2, posY, posZ) 
    triggerClientEvent("onRequestStartBlabla", thePlayer, gunner) 
    outputChatBox("gunner!") 
end) 
  
--client side 
local theDude = nil 
  
function shooter() 
    if(theDude == nil)then return end 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if(vehicle == false)then return end 
    local isShooting = getControlState("vehicle_secondary_fire") 
    if(isShooting)then 
        setPedControlState(theDude, "fire", true) 
        outputChatBox("is shooting!") 
    else 
        setPedControlState(theDude, "fire", false) 
    end 
end 
  
  
addEvent("onRequestStartBlabla", true) 
addEventHandler("onRequestStartBlabla", getRootElement(),  
function(gunner) 
    theDude = gunner 
    addEventHandler("onClientRender", getRootElement(), shooter) 
end) 
  
  

i dont get any errors and i see the debug text i write in chatbox..

Link to comment

ok, thanks.. i hope it works well :)

edit: it works perfectly :)

edit2: i attached the ped to the vehicle before triggering the client event, and then also changing rotation of ped onClientRender and setAimTarget(theDude, getPositionOffset(vehicle, 0, 5000, 0))

and getPositionOffset(vehicle, 0, 5000, 0) is a function i made and i get the position 5000 units in front of the vehicle.. it works and it shoots forward.. but when accelerate forwards, then the ped suddenly shoots in the opposite direction.. if i drive backwards then nothing like that happens..

I tried to change the aim target to the opposite direction, and tried driving backwards, but there was no change. (only happens when accelerating forwards..).

is there any way around this? i tried in mta 1.05 and 1.1

Link to comment
are you just setting ped rotation, or are you setting their aim?

also, it seems like peds are shooting the wrong direction somethimes because they twist at the waist, but the bullets still go the right way, is that what your seeing?

Im setting both ped rotation and their aim, and yes, they twist the waist, but that doesn't change the direction the bullets go in.. because if i stay still, then their waist has the same rotation and the mullet has the same position as when accelerating.

so the only thing that changes is the direction the bullets goes in when accelerating. (aiming direction is not controllable when i am accelerating)

Link to comment
hard to say what it might be without seeing the script. if you keep checking the position of the ped, does it update? attached objects used to have issues with updating position.

I tried removing attachElements and instead set the ped position over the vehicle so the ped stands on the roof.. but the same problem remains.

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