Jump to content

bone attach sync help!


Xwad

Recommended Posts

in my script i create an object, and i attach the object to the player with bone attach. my Problem is that other players cant see the object.. only the local player can see it:/ Does the root not contains the sync??

client

function custom_mp40() 
       local id = getElementModel ( source )  
       if id == 21 then 
       local PedWeapon = getPedWeapon(localPlayer) 
       if (PedWeapon == 29) then 
       mp40 = createObject(1855,0,0,0) 
       exports.bone_attach:attachElementToBone(mp40,localPlayer,12,0,0,0,-3,-90,0) 
       outputChatBox("create", 255, 255, 0) 
       end 
       end 
       if id == 21 then 
       local PedWeapon = getPedWeapon(localPlayer) 
       if not (PedWeapon == 29) then 
       destroyElement(mp40) 
       outputChatBox("destroyed", 255, 0, 0) 
    end 
  end 
end 
addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), custom_mp40 ) 

Link to comment
in my script i create an object, and i attach the object to the player with bone attach. my Problem is that other players cant see the object.. only the local player can see it:/ Does the root not contains the sync??

attach it server side.

Link to comment
That's what I said originally but I was questioning whether or not it would work (Have never used bone attach)

try this.

local attach = {} 
  
function attchweapon(prev,cur) 
    local id = getElementModel(source) 
    if id == 21 then 
        if cur == 29 then  
            if isElement(attach[source]) then 
                destroyElement(attach[source]) 
                attach[source] = nil 
            end 
            attach[source] = createObject(1855,0,0,0) 
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,-3,-90,0) 
            outputChatBox("created",source, 255, 255, 0) 
        else 
            if isElement(attach[source]) then  
                destroyElement(attach[source])  
                attach[source] = nil 
                outputChatBox("destroyed",source, 0,255,0) 
            end  
        end      
    end  
end  
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),attchweapon) 

Link to comment

now i have a new problem:/ i want to destroy the object when the player dies. my code is not working, please help

function onWasted() 
       destroyElement(attach[source]) 
       outputChatBox("wasted", 255, 0, 0) 
    end 
addEventHandler ( "onPlayerWasted", getRootElement(), onWasted ) 
  
  
  
local attach = {} 
  
function custom_mp40(prev,cur) 
    local id = getElementModel(source) 
    if id == 21 then 
        if cur == 29 then 
            if isElement(attach[source]) then 
                destroyElement(attach[source]) 
                attach[source] = nil 
            end 
            attach[source] = createObject(1855,0,0,0) 
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,-3,-90,0) 
            outputChatBox("created",source, 255, 255, 0) 
        else 
            if isElement(attach[source]) then 
                destroyElement(attach[source]) 
                attach[source] = nil 
                outputChatBox("destroyed",source, 0,255,0) 
            end 
        end     
    end 
end 
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_mp40) 
  

Link to comment
ERROR: attempt to index global 'attach' (a nil value)

are you sure you didn't change the table name .

working fine for me

local attach = {} 
  
function custom_mp40(prev,cur) 
    local id = getElementModel(source) 
    if id == 21 then 
        if cur == 29 then 
            if isElement(attach[source]) then 
                destroyElement(attach[source]) 
                attach[source] = nil 
            end 
            attach[source] = createObject(1855,0,0,0) 
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,-3,-90,0) 
            outputChatBox("created",source, 255, 255, 0) 
        else 
            if isElement(attach[source]) then 
                destroyElement(attach[source]) 
                attach[source] = nil 
                outputChatBox("destroyed",source, 0,255,0) 
            end 
        end     
    end 
end 
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_mp40) 
  
function onWasted() 
    if isElement(attach[source]) then 
        destroyElement(attach[source]) 
        attach[source] = nil 
        outputChatBox("destroyed",source) 
    end 
end 
addEventHandler("onPlayerWasted",root,onWasted) 

Link to comment

i dont undesratnd this... I added more custom weapons and it gives the same debugscript!! pls help

is the problem becaouse of the table name? It must be "table"?

function onWasted() 
    if isElement(attach_mp40[source]) then
        destroyElement(attach_mp40[source])
        attach_mp40[source] = nil
    end
   
    if isElement(attach_thompson[source]) then
        destroyElement(attach_thompson[source])
        attach_thompson[source] = nil
    end
   
    if isElement(attach_mp44[source]) then
        destroyElement(attach_mp44[source])
        attach_mp44[source] = nil
    end
   
    if isElement(attach_bar[source]) then
        destroyElement(attach_bar[source])
        attach_bar[source] = nil
    end
   
    if isElement(attach_g43[source]) then
        destroyElement(attach_g43[source])
        attach_g43[source] = nil
    end
   
    if isElement(attach_garand[source]) then
        destroyElement(attach_garand[source])
        attach_garand[source] = nil
    end
   
    if isElement(attach_luger[source]) then
        destroyElement(attach_luger[source])
        attach_luger[source] = nil
    end
       
    if isElement(attach_colt45[source]) then
        destroyElement(attach_colt45[source])
        attach_colt45[source] = nil
    end
       
    if isElement(attach_panzershrek[source]) then
        destroyElement(attach_panzershrek[source])
        attach_panzershrek[source] = nil
    end
       
    if isElement(attach_bazooka[source]) then
        destroyElement(attach_bazooka[source])
        attach_bazooka[source] = nil
    end
       
    if isElement(attach_kar98[source]) then
        destroyElement(attach_kar98[source])
        attach_kar98[source] = nil
    end
       
    if isElement(attach_springfield[source]) then
        destroyElement(attach_springfield[source])
        attach_springfield[source] = nil
    end
end
addEventHandler("onPlayerWasted",root,onWasted)
 
 
 
 
local attach_mp40 = {}
function custom_mp40(prev,cur)
    local id = getElementModel(source)
    if id == 21 then
        if cur == 29 then
            if isElement(attach_mp40[source]) then
                destroyElement(attach_mp40[source])
                attach_mp40[source] = nil
            end
            attach_mp40[source] = createObject(1855,0,0,0)
            exports.bone_attach:attachElementToBone(attach_mp40[source],source,12,0,0,0,-3,-90,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach_mp40[source]) then
                destroyElement(attach_mp40[source])
                attach_mp40[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_mp40)
 
 
local attach_thompson = {}
function custom_thompson(prev,cur)
    local id = getElementModel(source)
    if id == 101 then
        if cur == 29 then
            if isElement(attach_thompson[source]) then
                destroyElement(attach_thompson[source])
                attach_thompson[source] = nil
            end
            attach_thompson[source] = createObject(1856,0,0,0)
            exports.bone_attach:attachElementToBone(attach_thompson[source],source,12,0,0,0,-1.5,-90,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach_thompson[source]) then
                destroyElement(attach_thompson[source])
                attach_thompson[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_thompson)
 
 
 
 
local attach_mp44 = {}
function custom_mp44(prev,cur)
    local id = getElementModel(source)
    if id == 20 then
        if cur == 30 then
            if isElement(attach_mp44[source]) then
                destroyElement(attach_mp44[source])
                attach_mp44[source] = nil
            end
            attach_mp44[source] = createObject(1857,0,0,0)
            exports.bone_attach:attachElementToBone(attach_mp44[source],source,12,0,0,0,-2,-97,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach_mp44[source]) then
                destroyElement(attach_mp44[source])
                attach_mp44[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_mp44)
 
 
local attach_bar = {}
function custom_bar(prev,cur)
    local id = getElementModel(source)
    if id == 100 then
        if cur == 30 then
            if isElement(attach_bar[source]) then
                destroyElement(attach_bar[source])
                attach_bar[source] = nil
            end
            attach_bar[source] = createObject(1858,0,0,0)
            exports.bone_attach:attachElementToBone(attach_bar[source],source,12,0,0,0,-2,-98,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach_bar[source]) then
                destroyElement(attach_bar[source])
                attach_bar[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_bar)
 
 
 
 
local attach_g43 = {}
function custom_g43(prev,cur)
    local id = getElementModel(source)
    if id == 22 then
        if cur == 33 then
            if isElement(attach_g43[source]) then
                destroyElement(attach_g43[source])
                attach_g43[source] = nil
            end
            attach_g43[source] = createObject(1859,0,0,0)
            exports.bone_attach:attachElementToBone(attach_g43[source],source,12,0,0,0,-3,-92,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach_g43[source]) then
                destroyElement(attach_g43[source])
                attach_g43[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_g43)
 
 
local attach_garand = {}
function custom_garand(prev,cur)
    local id = getElementModel(source)
    if id == 102 then
        if cur == 33 then
            if isElement(attach_garand[source]) then
                destroyElement(attach_garand[source])
                attach_garand[source] = nil
            end
            attach_garand[source] = createObject(1860,0,0,0)
            exports.bone_attach:attachElementToBone(attach_garand[source],source,12,0,0,0,-1.2,-92,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach_garand[source]) then
                destroyElement(attach_garand[source])
                attach_garand[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_garand)
 
 
 
 
local attach_luger = {}
function custom_luger(prev,cur)
    local id = getElementModel(source)
    if id == 20 or id == 21 or id == 22 then
        if cur == 23 then
            if isElement(attach_luger[source]) then
                destroyElement(attach_luger[source])
                attach_luger[source] = nil
            end
            attach_luger[source] = createObject(1861,0,0,0)
            exports.bone_attach:attachElementToBone(attach_luger[source],source,12,0,0,0,0,-90,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach_luger[source]) then
                destroyElement(attach_luger[source])
                attach_luger[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_luger)
 
 
local attach_colt45 = {}
function custom_colt45(prev,cur)
    local id = getElementModel(source)
    if id == 100 or id == 101 or id == 102 then
        if cur == 23 then
            if isElement(attach_colt45[source]) then
                destroyElement(attach_colt45[source])
                attach_colt45[source] = nil
            end
            attach_colt45[source] = createObject(1862,0,0,0)
            exports.bone_attach:attachElementToBone(attach_colt45[source],source,12,0,0,0,0,-90,0)
           
Link to comment

Why your are using many tables , put all of them inside one table. your code will be definitely tidier and easier to read.

Example:

local attach = { 
    -- skin Id, Weapon Id, Object Id, bone, x,y,z,rx,ry,rz 
    {21,29,1855,12,0,0,0,-3,-90,0} 
     
 } 

Link to comment

now its fully not wroking. all the skins are on a different weapon ids. I dont use it only on one weapon

function onWasted() 
    if isElement(attach[source]) then
        destroyElement(attach[source])
        attach[source] = nil
        outputChatBox("destroyed",source)
    end
end
addEventHandler("onPlayerWasted",root,onWasted)
 
 
 
 
local attach = {}
 
 
 
function custom_mp40(prev,cur)
    local id = getElementModel(source)
    if id == 21 then
        if cur == 29 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1855,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,-3,-90,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_mp40)
 
 
function custom_thompson(prev,cur)
    local id = getElementModel(source)
    if id == 101 then
        if cur == 29 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1856,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,-1.5,-90,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_thompson)
 
 
 
 
function custom_mp44(prev,cur)
    local id = getElementModel(source)
    if id == 20 then
        if cur == 30 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1857,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,-2,-97,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_mp44)
 
 
function custom_bar(prev,cur)
    local id = getElementModel(source)
    if id == 100 then
        if cur == 30 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1858,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,-2,-98,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_bar)
 
 
 
 
function custom_g43(prev,cur)
    local id = getElementModel(source)
    if id == 22 then
        if cur == 33 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1859,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,-3,-92,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_g43)
 
 
function custom_garand(prev,cur)
    local id = getElementModel(source)
    if id == 102 then
        if cur == 33 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1860,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,-1.2,-92,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_garand)
 
 
 
 
function custom_luger(prev,cur)
    local id = getElementModel(source)
    if id == 20 or id == 21 or id == 22 then
        if cur == 23 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1861,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,0,-90,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_luger)
 
 
function custom_colt45(prev,cur)
    local id = getElementModel(source)
    if id == 100 or id == 101 or id == 102 then
        if cur == 23 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1862,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,0,-90,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_colt45)
 
 
 
 
function custom_panzershrek(prev,cur)
    local id = getElementModel(source)
    if id == 20 then
        if cur == 29 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1863,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,0,-90,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
addEventHandler ("onPlayerWeaponSwitch", getRootElement(),custom_panzershrek)
 
 
function custom_bazooka(prev,cur)
    local id = getElementModel(source)
    if id == 100 then
        if cur == 29 then
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
            end
            attach[source] = createObject(1864,0,0,0)
            exports.bone_attach:attachElementToBone(attach[source],source,12,0,0,0,0,-90,0)
            outputChatBox("created",source, 255, 255, 0)
        else
            if isElement(attach[source]) then
                destroyElement(attach[source])
                attach[source] = nil
                outputChatBox("destroyed",source, 0,255,0)
            end
        end    
    end
end
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...