Jump to content

[HELP]Destroy object attached to player


KaMi

Recommended Posts

Hello ! I recently made a weapon that shoots explosives. I thought about adding an object in the form of decoration using the bone attach resource. Everything go well until I realized that , when the player dies, the object stayed stuck and was not destroyed. Here you have the code

 

function activArmas( player )
	if (getElementData (player, "Armactivada") == false) then
		setElementData (player, "Armactivada", true)
		outputChatBox( "Activaste el arma", player, 100, 0, 0 )
	else
		setElementData (player, "Armactivada", false)
		outputChatBox( "Desactivaste el arma", player, 100, 0, 0 )
	end
end
addCommandHandler("activar", activArmas)


local frascote = {}

function setObjectInWeapon( previousWeaponID, currentWeaponID )
	if (getElementData (source, "Armactivada") == true) then
		if ( currentWeaponID == 31 ) then
			exports.bone_attach:attachElementToBone(frascote[source],source,12,-0.09,0,-0.03,0,2,40)
		elseif ( previousWeaponID == 31 ) then
			exports.bone_attach:detachElementFromBone( frascote[source] )
			destroyElement( frascote[source] )
		end
	end
end
addEventHandler("onPlayerWeaponSwitch", root, setObjectInWeapon)


function wast()
	if (getElementData (source, "Armactivada") == true) then
		destroyElement( frascote[source] ) --Here i have my problem.
	end
end
addEventHandler("onPlayerWasted", root, wast)

 

Sorry for repost the topic but the spanish community is not than active .

Thanks a lot !  

 

 

Edited by CodyJ(L)
Fixed lua format
Link to comment

 

10 minutes ago, CodyJ(L) said:

Where is frascote being created?

i forget specify this

frascote[source] = frasco

answering your question... i think in the line 13. I don't usually use tables

Edited by <~KaMiKaZe~>
Link to comment

if not objectTable then

objectTable = {};

end

objectTable[playerSource] = createObject(id, x,y ,z)

-- write there the attach

-- and detach

if isElement(objectTable[playerSource]) then

detachElements(objectTable[playerSource])

destroyElement(objectTable[playerSource])

end

Link to comment
7 hours ago, Sanyika666 said:

if not objectTable then

objectTable = {};

end

objectTable[playerSource] = createObject(id, x,y ,z)

-- write there the attach

-- and detach

if isElement(objectTable[playerSource]) then

detachElements(objectTable[playerSource])

destroyElement(objectTable[playerSource])

end

I put the code in this form, but nothing :/

 

if not objectTable then

objectTable = {};

end

objectTable[playerSource] = createObject(2976,0,0,0)


function setObjectInWeapon( previousWeaponID, currentWeaponID )
	if (getElementData (source, "Armactivada") == true) then
		if ( currentWeaponID == 31 ) then
			exports.bone_attach:attachElementToBone(objectTable[playerSource],source,12,-0.09,0,-0.03,0,2,40)
		elseif ( previousWeaponID == 31 ) then
			exports.bone_attach:detachElementFromBone( objectTable[playerSource] )
			destroyElement( objectTable[playerSource] )
		end
	end
end
addEventHandler("onPlayerWeaponSwitch", root, setObjectInWeapon)

function wast()
	if (getElementData (source, "Armactivada") == true) then
		destroyElement( objectTable[playerSource] ) 
	end
end
addEventHandler("onPlayerWasted", root, wast)

if isElement(objectTable[playerSource]) then

detachElements(objectTable[playerSource])

destroyElement(objectTable[playerSource])

end

 

the console give me this error :

ERROR: Weap\server.lua:24 table index is nil

7 hours ago, CodyJ(L) said:

Post the code where it's created. Not just the line

SERVER-SIDE

if not objectTable then

objectTable = {};

end

objectTable[playerSource] = createObject(2976,0,0,0)


function setObjectInWeapon( previousWeaponID, currentWeaponID )
	if (getElementData (source, "Armactivada") == true) then
		if ( currentWeaponID == 31 ) then
			exports.bone_attach:attachElementToBone(objectTable[playerSource],source,12,-0.09,0,-0.03,0,2,40)
		elseif ( previousWeaponID == 31 ) then
			exports.bone_attach:detachElementFromBone( objectTable[playerSource] )
			destroyElement( objectTable[playerSource] )
		end
	end
end
addEventHandler("onPlayerWeaponSwitch", root, setObjectInWeapon)

function wast()
	if (getElementData (source, "Armactivada") == true) then
		destroyElement( objectTable[playerSource] ) 
	end
end
addEventHandler("onPlayerWasted", root, wast)

if isElement(objectTable[playerSource]) then

detachElements(objectTable[playerSource])

destroyElement(objectTable[playerSource])

end

CLIENT-SIDE


function fireGG_135( weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement, startX, startY, startZ )
           if (getElementData (source, "Armactivada") == true) then
           if ( weapon == 31 ) then
           local genergy = createMarker( 0, 0, 0, "corona", 1, 0, 165, 57, 255  )
           local genergyo = createObject( 2976, startX, startY, startZ )
           setElementAlpha( genergyo, 0 )
           attachElements( genergy, genergyo, 0, 0, 0 )
           moveObject( genergyo, 1000, hitX, hitY, hitZ )
           setElementCollisionsEnabled( genergyo, false )


           setTimer( function()

           destroyElement( genergyo )
           destroyElement( genergy )
           createExplosion( hitX, hitY, hitZ, 2 )

           end, 1500, 1 )
        end
    end
end
addEventHandler("onClientPlayerWeaponFire", root, fireGG_135)

 

Edited by <~KaMiKaZe~>
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...