Jump to content

Need one code (PEDS DEL)


Try

Recommended Posts

Hellloo Guys

I want one code for del all peds (all the peds dead or live)

My code for peds is this if it help

addCommandHandler ("createped", 
function (player) 
        local x,y,z = getElementPosition (player) 
        ped = createPed (165,x,y,z) 
end) 

Can you help me?

Thanks

Link to comment
  • Moderators

Hi Try,

Try ( :lol: ) this:

  
function delAllPeds(thePlayer, comandName) 
    local peds = 0 
    for k,i in ipairs ( getElementsByType( "ped" ) )do 
        destroyElement( i ) 
        peds = peds+1 
    end 
    outputChatBox( peds.." were destroyed !", thePlayer ) 
end 
addCommandHandler( "delpeds", delAllPeds, false, false ) 
  

It should work

Link to comment

You forgot something, proracer.

addCommandHandler ("createped", 
function (player) 
        local x,y,z = getElementPosition (player) 
        ped = createPed (165,x,y,z) 
        giveWeapon(ped, 31, 100, true) -- it will give ped an M4 with 100 ammo[b] AND WILL SET THE SLOT TO THAT WEAPON[/b] 
end) 

Otherwise it shouldn't work as well as Try wants.

Link to comment

Try this:

function onGivePedWeapon ( ped, weaponid, amount ) 
    if ped and weaponid then 
        if amount then 
            giveWeapon ( ped, weaponid, amount ) 
        else 
            outputChatBox ( "Wrong syntax.", source, 255, 0, 0 ) 
        end 
    else 
        outputChatBox ( "Wrong Syntax.", source, 255, 0, 0 ) 
    end 
end 
  
addCommandHandler ( "givepedwp", onGivePedWeapon ) 

Link to comment

There's no need to use 2 if's, and if I'm right that won't work.

This is the fixed code and with less lines and less weight

function onGivePedWeapon ( pl, _,  pedID, weap, ammo ) 
    if pedID and weapon and amount then 
        if getElementByID ( pedID ) then 
            giveWeapon ( getElementByID ( pedID ), weap, ammo, true ) 
        else 
            outputChatBox ( "No ped has this ID", pl, 255, 0, 0 ) 
        end 
    else 
        outputChatBox ( "Wrong Syntax!", pl, 255, 0, 0 ) 
    end 
end 
  
addCommandHandler ( "givepedwp", onGivePedWeapon ) 

And use this new code for to create peds, otherwise the other one won't work.

addCommandHandler ("createped", 
function ( pl, _, id) 
        if not id then outputChatBox ( "The ped needs an ID to be spawned!", pl, 255, 0, 0 ) return end 
        local x, y, z = getElementPosition (player) 
        ped = createPed ( 165,x, y, z ) 
        setElementID ( ped, id ) 
        giveWeapon(ped, 31, 100, true) 
end) 

Link to comment
  • Moderators

hum if you want to give weapon for only one ped, you have to use /givepedwp thePed theWeapon theAmmos

and if you want to give a weapon to all peds, try this:

  
function giveWeaponPeds( thePlayer, commandName, weapon, ammo ) 
    if (weapon and munitions) then 
        for k,i in ipairs ( getElementsByType( "ped" ) )do 
            giveWeapon ( i, weapon, ammo, true ) 
        end 
    else 
        outputChatBox("/wpeds [weaponID] [ammos]", thePlayer ) 
    end 
end 
addCommandHandler( "wpeds", giveWeaponPeds, false, false ) 
  

Link to comment
function giveWeaponPeds( thePlayer, commandName, weapon, ammo ) 
    if (weapon and ammo) then 
        for k,i in ipairs ( getElementsByType( "ped" ) )do 
            giveWeapon ( i, weapon, ammo, true ) 
        end 
    else 
        outputChatBox("/wpeds [weaponID] [ammos]", thePlayer ) 
    end 
end 
addCommandHandler( "wpeds", giveWeaponPeds, false, false ) 

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