Jump to content

mass action


Recommended Posts

I want to make setpedaimtarget etc for all peds i've got it

--416.40151977539,1677.1229248047,36.129425048828 
  
peds = {} 
  
addEventHandler("onClientResourceStart",root, 
function() 
    --spawn_point_1 = createColRectangle(416.40151977539,1677.1229248047,100,50) -- spawn poinT 
    spawn_point_1 = createColSphere(416.40151977539,1677.1229248047,36.129425048828,40) -- spawn point 
    x,y,z = getElementPosition( spawn_point_1 ) 
    for i=0, 10 do -- 20 mobs 
    peds[1] = createPed(0,x+math.random(-15,15),y+math.random(-15,15),z) 
    end 
end 
) 
  
  
function findRotation(x1,y1,x2,y2) 
  
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + 360 end; 
  return t; 
  
end 
  
addCommandHandler("warpme", 
function() 
    setElementPosition(localPlayer,416.40151977539,1677.1229248047,36.129425048828) 
end 
) 
  
  
addCommandHandler("tests", 
function() 
    local dx,dy,dz = getElementPosition( localPlayer ) 
    ss = createPed(0,dx,dy,dz) 
end 
) 
  
addEventHandler("onClientElementColShapeHit",root, 
function(theShape, matchingDimension) 
    if theShape == spawn_point_1 then 
        if ( getElementType( source ) == "player" ) and ( source == getLocalPlayer( ) ) then 
            for k,v in ipairs(peds) do 
            local ax,ay,az = getElementPosition( localPlayer ) 
            setPedAimTarget(v,ax,ay,az) 
            setPedControlState(v,"fire",true ) 
            local zx,zy,zz = getElementPosition(localPlayer) 
            local tx,ty,tz = getElementPosition(v) 
            setPedRotation(v, findRotation(tx,ty,zx,zy) ); 
            end 
        end 
    end 
end 
) 

what should I do to make action for peds with this variable?

addEventHandler("onClientElementColShapeHit",root, 
function(theShape, matchingDimension) 
    if theShape == spawn_point_1 then 
        if ( getElementType( source ) == "player" ) and ( source == getLocalPlayer( ) ) then 
            for k,v in ipairs(peds) do 
            local ax,ay,az = getElementPosition( localPlayer ) 
            setPedAimTarget(v,ax,ay,az) 
            setPedControlState(v,"fire",true ) 
            local zx,zy,zz = getElementPosition(localPlayer) 
            local tx,ty,tz = getElementPosition(v) 
            setPedRotation(v, findRotation(tx,ty,zx,zy) ); 
            end 
        end 
    end 
end 

Link to comment

try this:

--416.40151977539,1677.1229248047,36.129425048828 
  
peds = {} 
  
addEventHandler("onClientResourceStart",resourceRoot,function() 
    --spawn_point_1 = createColRectangle(416.40151977539,1677.1229248047,100,50) -- spawn poinT 
    spawn_point_1 = createColSphere(416.40151977539,1677.1229248047,36.129425048828,40) -- spawn point 
    x,y,z = getElementPosition( spawn_point_1 ) 
    count = 0 
    for i=0, 10 do -- 20 mobs 
        peds[count+1] = createPed(0,x+math.random(-15,15),y+math.random(-15,15),z) 
    end 
end) 
  
  
function findRotation(x1,y1,x2,y2) 
    local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
    if t < 0 then 
        t = t + 360 
    end 
    return t; 
end 
  
addCommandHandler("warpme",function() 
    setElementPosition(localPlayer,416.40151977539,1677.1229248047,36.129425048828) 
end) 
  
  
addCommandHandler("tests",function() 
    local dx,dy,dz = getElementPosition( localPlayer ) 
    ss = createPed(0,dx,dy,dz) 
end) 
  
addEventHandler("onClientElementColShapeHit",root,function(theShape, matchingDimension) 
    if theShape == spawn_point_1 then 
        if ( getElementType(source) == "player") and (source == localPlayer) then 
            for k,v in ipairs(peds) do 
                local ax,ay,az = getElementPosition( source ) 
                setPedAimTarget(v,ax,ay,az) 
                setPedControlState(v,"fire",true ) 
                local zx,zy,zz = getElementPosition(source) 
                local tx,ty,tz = getElementPosition(v) 
                setPedRotation(v, findRotation(tx,ty,zx,zy) ); 
            end 
        end 
    end 
end) 

You were creating over the first ped over and over again, so I used a count system as you could see on line 9-11

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