KaMi

[HELP]Destroy object attached to player

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

Share this post


Link to post
5 minutes ago, CodyJ(L) said:

Moved to scripting, anywho; use tables.

thanks, can you pls give an example ? my mind is blank

Share this post


Link to post

 

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

Share this post


Link to post

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

Share this post


Link to post
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~>

Share this post


Link to post
2 minutes ago, CodyJ(L) said:

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

There's your problem.

Ho, what i have to do here ?

Share this post


Link to post
9 minutes ago, CodyJ(L) said:

That's just thrown in there, (PlayerSource) doesn't even exist.

 

I'm sorry for bothering but I'm very confused. What can I do?

Share this post


Link to post
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.