Jump to content

Need Help with a script to create peds


Recommended Posts

  
  
swatpeds = { 
[1] = {285, 1572.2216796875, -1626.880859375, 13.3828125} 
} 
  
    for k, v in ipairs(swatpeds) do 
            local k = createPed(285, v) 
            givePedWeapon(k, 31, 5000, true) -- Give ped 5000 rounds of M4 
    end 
  

I can't figure out why it is throwing errors...

The list swatpeds is the coordinates where the ped should spawn

Link to comment

Try this:

local swatpeds = { 
    -- Model, Pox, Posy, Posz 
    {285, 1572.2216796875, -1626.880859375, 13.3828125} 
     
} 
  
for k, data in ipairs ( swatpeds ) do 
    local ped = createPed ( v[1], v[2], v[3], v[4] ) 
    givePedWeapon ( ped, 31, 5000, true ) 
end 
  

Link to comment

  
swatpeds = { 
     [1] = {285, 1572.2216796875, -1626.880859375, 13.3828125},  
     [2] = {285, 1544.6943359375, -1621.15234375, 13.55456161499} 
} 
  
for k, v in ipairs(swatpeds) do 
    local ped = createPed(unpack(v)) 
     
    local x,y,z = getElementPosition(ped) 
    setPedRotation(ped, 90) 
     
    giveWeapon(ped, 31, 200, true) 
     
end 
  

how would i change local ped = createPed(unpack(v))

to be local ped + VALUE OF K = createPed(unpack(v))

so that each ped can have different weps and face different directions.

instead of the ped being called just ped I need the peds to be called ped1 and ped2

Link to comment
swatpeds = { 
     { 
          ped = nil, 
          arguements = {285, 1572.2216796875, -1626.880859375, 13.3828125, 90}, -- model,x,y,z,rotation 
          weapon = { 
               id = 31, 
               ammo = 5000, 
               setAsCurrent = true 
          }, 
          special_function = function(ped) 
              -- eg. setPedHeadless(ped, false)  
               -- TO DO 
          end 
     }, 
     { 
          ped = nil, 
          arguements = {285, 1544.6943359375, -1621.15234375, 13.55456161499, 90}, 
          weapon = { 
               id = 31, 
               ammo = 5000, 
               setAsCurrent = true 
          }, 
          special_function = function(ped) 
               -- eg. setPedHeadless(ped, true)  
               -- TO DO 
          end 
     } 
} 
  
for i, data in ipairs(swatpeds) do 
     local ped = createPed(unpack(data.arguements)) 
     giveWeapon(ped, data.weapon.id, data.weapon.ammo, data.weapon.setAsCurrent) 
  
     if type(data.special_function) == "function" then 
          data.special_function(ped) 
     end 
  
     data.ped = ped 
end 

You can reach peds with:

swatpeds[1].ped 
swatpeds[2].ped 
... 

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