Jump to content

Respawn Destroyed Object not Working


DarkLink

Recommended Posts

Hi there guys, I could make this with event on client shoots the weapon. but the object can be destroyed by others things..

I need to use the "onClientRender" to always check if is destroyed and to respawn, but I have something bad on my code, cant find it :S

Can someone help me?

Here is the code:

  
function createWood() 
    local xW,yW,zW = getElementPosition(wood) 
    local xWR, yWR, zWR = getElementRotation(wood) 
    destroyElement (wood) 
    wood = createObject ( 1418, xW, yW, zW, xWR,yWR,zWR, false ) 
end 
  
  
  
function createLine() 
    dxDrawLine3D (xW, yW, zW+1, xW, yW, zW-1, tocolor ( 0, 255, 0, 255 ), 10)   -- this is only to help me, to know which line would isLineOfSightClear would use  
    local result = isLineOfSightClear ( xW, yW,  zW+1,  xW,  yW, zW-1) 
    outputChatBox("o resultado e: " .. tostring(result)) 
     
    if(result) then 
        outputChatBox("no obstacle visible") 
        removeEventHandler("onClientRender", getRootElement(), createLine) 
         
        setTimer(function() createWood() outputChatBox("vai activar")  addEventHandler("onClientRender", getRootElement(), createLine)    end, 1000, 1) 
         
         
    else 
    
        outputChatBox("obstacle visible") 
    end 
    
end 
  
 function place() 
    local x,y,z = getElementPosition(source) 
    wood = createObject ( 1418, x + 3, y, z+3, 150.23657226563, 50.000610351563, 150.47875976563, false ) 
    xW,yW,zW = getElementPosition(wood) 
    xWR, yWR, zWR = getElementRotation(wood) 
    outputChatBox("a wood vale:" .. tostring(wood)) 
    addEventHandler("onClientRender", wood, createLine) 
 end 
addEventHandler ( "onClientPlayerSpawn", getRootElement(), place ) 
  

Thanks alot in advance :/

Link to comment

I not understand what you want create.

Maybe you mean this? or i not understand.

local state,wood 
  
function createLine( ) 
    if state and isElement( wood ) then 
        local x,y,z = getElementPosition( localPlayer ) 
        local xW,yW,zW = getElementPosition( wood ) 
        if isLineOfSightClear( x, y, z, xW, yW, zW, true, false, false, true, false, false, localPlayer ) then 
            dxDrawLine3D ( xW, yW, zW+1, xW, yW, zW-1, tocolor ( 0, 255, 0, 255 ), 10 )  
            setElementPosition( wood,x + 3, y, z+3 ) 
            outputChatBox( "no obstacle visible" ) 
        else 
            outputChatBox( "obstacle visible" ) 
        end 
    end 
end 
  
function place( ) 
    local x,y,z = getElementPosition( source ) 
    if isElement( wood ) then destroyElement( wood ) end 
    wood = createObject ( 1418, x + 3, y, z+3, 150.23657226563, 50.000610351563, 150.47875976563, false ) 
    outputChatBox("a wood vale:" .. tostring( wood ) ) 
    state = true 
    addEventHandler( "onClientRender", wood, createLine ) 
end 
addEventHandler ( "onClientPlayerSpawn", root, place )  

Updated

Edited by Guest
Link to comment

1º What I want is a event that will be executed always so : "onClientRender"

why this event?

because:

I wanna check a piece of wood if is on destroyed state or not (destroyed state is checked by isLineOfSightClear, if it returns true, its destroyed)

2º when its on destroyed state, just destroy wood and create it again.

Do u guys understand? thanks alot in advance ;)

Link to comment

I notice that although the createObject call is before the call of isLineOfSightClear, the objects gets created after the check of the line.. and it says that there is no object, when acctually there should be, because I created before than the check of the line..

but seems that createObject is not instantly it takes some time.. I guess there is no workaround to this ?

Someone more experienced maybe know how to..

thanks in advance ;)

Link to comment
createObject works fine. It creates the object instantly. It only takes time for the object to be streamed in. So you may want to try respawning object only when isElementStreamedIn returns true.

Ahhhh!! Didnt know about this!! Thanks alot Crystal! It will solve my problem!

Thank you very much !

Problem solved :)

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