Jump to content

Help MY!!!


kevincouto6

Recommended Posts

Posted

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 )

 

Posted (edited)

It would be nice it you actually told us what problem you're having. And the topic's title is very unhelpful.

 

 

Edited by MrTasty
Posted
3 hours ago, MrTasty said:

It would be nice it you actually told us what problem you're having. And the topic's title is very unhelpful.

 

 

Good my problem and that when the PEDs will respawn they are duplicating, Please could you correct the errors, and sorry for the inconvenience

Posted

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.

Posted (edited)

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

Posted
13 minutes ago, idan1432 said:

where do you put this script on server-side or client-side?

this script have to be on server-side

these Scripts are for a map I'm creating

  • Moderators
Posted (edited)

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

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