Jump to content

Help MY!!!


kevincouto6

Recommended Posts

I'm having a problem with this script, could anyone help me, please?

ped1 = createPed ( 287, 1877.8000488281, -2291.6000976563, 13.60000038147 )
ped2 = createPed ( 287, 1878.3000488281, -2288.5, 13.60000038147 )
ped3 = createPed ( 287, 1878.4000244141, -2294.6999511719, 13.60000038147 )
ped4 = createPed ( 61, 1883.359375, -2291.3227539063, 13.60781288147 )
    setTimer ( setPedAnimation, 1000, 1, ped1, "SHOP", "SHP_serve_loop",-1, false, false, false, true)
    setTimer ( setPedAnimation, 1000, 1, ped2, "SHOP", "SHP_serve_loop",-1, false, false, false, true)
    setTimer ( setPedAnimation, 1000, 1, ped3, "SHOP", "SHP_serve_loop",-1, false, false, false, true)
    setTimer ( setPedAnimation, 1000, 1, ped4, "COP_AMBIENT", "coplook_loop",-1, false, false, false, true)
setPedRotation ( ped1, 87.9990844 )
setPedRotation ( ped2, 58.0004577 )
setPedRotation ( ped3, 111.999084 )
setPedRotation ( ped4, 273.253387 )
    setElementFrozen(ped1, true)
    setElementFrozen(ped2, true)
    setElementFrozen(ped3, true)
    setElementFrozen(ped4, true)
    
function peddestroy1 ( thePlayer )
if ( isPedDead ( ped1 ) ) then
setTimer ( destroyElement, 7100, 1, ped1 )  
end
end
addEventHandler("onPedWasted", getRootElement(ped1), peddestroy1 )

function peddestroy2 ( thePlayer )
if ( isPedDead ( ped2 ) ) then
setTimer ( destroyElement, 7300, 1, ped2 )    
end
end
addEventHandler("onPedWasted", getRootElement(ped2), peddestroy2 )

function peddestroy3 ( thePlayer )
if ( isPedDead ( ped3 ) ) then
setTimer ( destroyElement, 7500, 1, ped3 )   
end
end
addEventHandler("onPedWasted", getRootElement(ped3), peddestroy3 )

function peddestroy4 ( thePlayer )
if ( isPedDead ( ped4 ) ) then
setTimer ( destroyElement, 7700, 1, ped4 )  
end
end
addEventHandler("onPedWasted", getRootElement(ped4), peddestroy4 )

function pedrespawnafterdeath1()
   ped1 = createPed ( 287, 1877.8000488281, -2291.6000976563, 13.60000038147 )
   pedanim = setTimer ( setPedAnimation, 1000, 1, ped1, "SHOP", "SHP_serve_loop", -1,  false, false, false, true) 
   setPedRotation ( ped1, 87.9990844 )
   setElementFrozen(ped1, true)
   end
 
function pedrespawnafterdeath2 ()
   ped2 = createPed ( 287, 1878.3000488281, -2288.5, 13.60000038147 )
   pedanim = setTimer ( setPedAnimation, 1000, 1, ped2, "SHOP", "SHP_serve_loop", -1,  false, false, false, true)
   setPedRotation ( ped2, 58.0004577 )
   setElementFrozen(ped2, true)

   end
function pedrespawnafterdeath3()
   ped3 = createPed ( 287, 1878.4000244141, -2294.6999511719, 13.60000038147 )
   pedanim = setTimer ( setPedAnimation, 1000, 1, ped3, "SHOP", "SHP_serve_loop", -1,  false, false, false, true)
   setPedRotation ( ped3, 111.999084 )
   setElementFrozen(ped3, true)
   end
   
function pedrespawnafterdeath4()
   ped4 = createPed ( 61, 1883.359375, -2291.3227539063, 13.60781288147 )   
   pedanim = setTimer ( setPedAnimation, 1000, 1, ped4, "COP_AMBIENT", "coplook_loop", -1,  false, false, false, true)
   setPedRotation ( ped4, 273.253387 )
   setElementFrozen(ped4, true)
   end
 
function pednewadeath1 ( thePlayer )
if ( isPedDead ( ped1 ) ) then
setTimer ( pedrespawnafterdeath1, 10000, 1 )
end
end
addEventHandler("onPedWasted", ped1, getRootElement(), pednewadeath1 )

 function pednewadeath2 ( thePlayer )
if ( isPedDead ( ped2 ) ) then 
setTimer ( pedrespawnafterdeath2, 10000, 1 )
end
end
addEventHandler("onPedWasted", ped2, getRootElement(), pednewadeath2 )

 function pednewadeath3 ( thePlayer )
if ( isPedDead ( ped3 ) ) then
setTimer ( pedrespawnafterdeath3, 10000, 1 )
end
end
addEventHandler("onPedWasted", ped3, getRootElement(), pednewadeath3 )

 function pednewadeath4 ( thePlayer )
if ( isPedDead ( ped4 ) ) then
setTimer ( pedrespawnafterdeath4, 10000, 1 )   
end
end
addEventHandler("onPedWasted", ped4, getRootElement(), pednewadeath4 )

 

Link to comment

That's probably because you've used the wrong syntax for addEventHandler.

The first 4 handlers should be as follows:

addEventHandler("onPedWasted", ped1, peddestroy1 )
addEventHandler("onPedWasted", ped2, peddestroy2 )
addEventHandler("onPedWasted", ped3, peddestroy3 )
addEventHandler("onPedWasted", ped4, peddestroy4 )

And the following handlers should be:

addEventHandler("onPedWasted", ped1, pednewadeath1 )
addEventHandler("onPedWasted", ped2, pednewadeath2 )
addEventHandler("onPedWasted", ped3, pednewadeath3 )
addEventHandler("onPedWasted", ped4, pednewadeath4 )

 

Anyway, I'd additionally advise you to use just one handler to handle all of that instead of having 8 different handlers.

Link to comment

As I've said, it would be a easier, cleaner and more efficient if you used just one handler. And because it's cleaner, it's easier to see and fix problems.

local peds = {
  -- {model, x, y, z, rotZ, animblock, animname}
  {287, 1877.8, -2291.6, 13.6, 88, "SHOP", "SHP_serve_loop"},
  {287, 1878.3, -2288.5, 13.6, 58, "SHOP", "SHP_serve_loop"},
  {287, 1878.4, -2294.7, 13.6, 112, "SHOP", "SHP_serve_loop"},
  {61, 1883.36, -2291.3, 13.6, 273.25, "COP_AMBIENT", "coplook_loop"},
}


local id = {} -- do not edit this table

local function spawnPed(data)
  local p = createPed(data[1], data[2], data[3], data[4], data[5]) -- spawn ped with model, x, y, z and rotZ
  setPedAnimation(p, data[6], data[7]) -- set the ped's animation (you might want to change this into a setTimer statement if the animation doesn't apply correctly)
  addEventHandler("onPedWasted", p, handleRespawn) -- attach handler for respawning
  id[p] = i -- save the ped's key of the table (so we can find his data)
end
local function handleRespawn()
  -- source: the ped that died
  -- id[source] = the key/id of the ped that died
  -- peds[id[source]] = data on the ped's key/id
  local data = peds[id[source]] -- find the ped's data
  setTimer(destroyElement, 1000, 1, source) -- destroy ped after 1s
  setTimer(createPed, 1500, 1, data) -- use our cusom function to spawn ped after 1.5s
end

-- initialize
for i, ped in ipairs(peds) do -- iterate through all ped data
  spawnPed(ped) -- use our custom function to spawn ped
end

 

Edited by MrTasty
Link to comment
On 30/09/2017 at 06:52, MrTasty said:

As I've said, it would be a easier, cleaner and more efficient if you used just one handler. And because it's cleaner, it's easier to see and fix problems.


local peds = {
  -- {model, x, y, z, rotZ, animblock, animname}
  {287, 1877.8, -2291.6, 13.6, 88, "SHOP", "SHP_serve_loop"},
  {287, 1878.3, -2288.5, 13.6, 58, "SHOP", "SHP_serve_loop"},
  {287, 1878.4, -2294.7, 13.6, 112, "SHOP", "SHP_serve_loop"},
  {61, 1883.36, -2291.3, 13.6, 273.25, "COP_AMBIENT", "coplook_loop"},
}


local id = {} -- do not edit this table

local function spawnPed(data)
  local p = createPed(data[1], data[2], data[3], data[4], data[5]) -- spawn ped with model, x, y, z and rotZ
  setPedAnimation(p, data[6], data[7]) -- set the ped's animation (you might want to change this into a setTimer statement if the animation doesn't apply correctly)
  addEventHandler("onPedWasted", p, handleRespawn) -- attach handler for respawning
  id[p] = i -- save the ped's key of the table (so we can find his data)
end
local function handleRespawn()
  -- source: the ped that died
  -- id[source] = the key/id of the ped that died
  -- peds[id[source]] = data on the ped's key/id
  local data = peds[id[source]] -- find the ped's data
  setTimer(destroyElement, 1000, 1, source) -- destroy ped after 1s
  setTimer(createPed, 1500, 1, data) -- use our cusom function to spawn ped after 1.5s
end

-- initialize
for i, ped in ipairs(peds) do -- iterate through all ped data
  spawnPed(ped) -- use our custom function to spawn ped
end

 

The Peds are not giving respawn after dead !!You could leave the script ready for me.

Link to comment
  • Moderators

I honestly do not understand why people add so many addEventHandlers, one on the parent is enough. :)

 

 

local peds = {
  -- {model, x, y, z, rotZ, animblock, animname}
  {287, 1877.8, -2291.6, 13.6, 88, "SHOP", "SHP_serve_loop"},
  {287, 1878.3, -2288.5, 13.6, 58, "SHOP", "SHP_serve_loop"},
  {287, 1878.4, -2294.7, 13.6, 112, "SHOP", "SHP_serve_loop"},
  {61, 1883.36, -2291.3, 13.6, 273.25, "COP_AMBIENT", "coplook_loop"},
}

local pedsParent = createElement("pedsParent")

local id = {} -- do not edit this table

local function spawnPed(data, index)
    local p = createPed(data[1], data[2], data[3], data[4], data[5]) -- spawn ped with model, x, y, z and rotZ
    setPedAnimation(p, data[6], data[7]) -- set the ped's animation (you might want to change this into a setTimer statement if the animation doesn't apply correctly)
    setElementParent(p, pedsParent)
    id[p] = index -- save the ped's key of the table (so we can find his data)
end


local function handleRespawn()
    -- source: the ped that died
    -- id[source] = the key/id of the ped that died
    -- peds[id[source]] = data on the ped's key/id
    local index = id[source]
    if index then
        id[source] = nil -- clean up! Important, else data leak!
        local data = peds[index] -- find the ped's data
        if data then
            setTimer(destroyElement, 1000, 1, source) -- destroy ped after 1s
            setTimer(spawnPed, 1500, 1, data, index) -- use our cusom function to spawn ped after 1.5s
        end
    end
end

addEventHandler("onPedWasted", pedsParent, handleRespawn) -- attach handler for respawning

-- initialize
for i, ped in ipairs(peds) do -- iterate through all ped data
    spawnPed(ped, i) -- use our custom function to spawn ped
end

(credits to MrTasty)

Edited by IIYAMA
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...