DarkLink Posted January 26, 2012 Share Posted January 26, 2012 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 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
Kenix Posted January 26, 2012 Share Posted January 26, 2012 (edited) 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 January 26, 2012 by Guest Link to comment
BriGhtx3 Posted January 26, 2012 Share Posted January 26, 2012 This script is totally confusing Why do you render the same event twice? Link to comment
Kenix Posted January 26, 2012 Share Posted January 26, 2012 This script is totally confusing I not understand too. DarkLink,Explain better what you need create. Link to comment
DarkLink Posted January 26, 2012 Author Share Posted January 26, 2012 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
Xeno Posted January 26, 2012 Share Posted January 26, 2012 I think he wants to create a gun range script where you shoot things? Link to comment
DarkLink Posted January 26, 2012 Author Share Posted January 26, 2012 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
DiSaMe Posted January 26, 2012 Share Posted January 26, 2012 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. Link to comment
DarkLink Posted January 26, 2012 Author Share Posted January 26, 2012 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now