Jump to content

whats wrong with this script?


hipolitalakaj

Recommended Posts

 

Hi!

Can someone help me whats wrong with this code?

Got these errors in debugscript:

https://imgur.com/a/sVJd7yw

function test() 
   local weapon = createWeapon("ak-47") 
   setWeaponAmmo(weapon, 120) 
   setWeaponClipAmmo(weapon, 32) 
   setWeaponState(weapon, "firing") 
   setElementAlpha(weapon, 0) 
   local newAK = createElement(object, 2965) 
   attachElements(weapon, newAK) 
end 
addCommandHandler("aktest", test)
Link to comment
You need to place the position of the weapon

 

50 minutes ago, hipolitalakaj said:

 

Hi!

Can someone help me whats wrong with this code?

Got these errors in debugscript:

https://imgur.com/a/sVJd7yw


function test() 
   local weapon = createWeapon("ak-47") 
   setWeaponAmmo(weapon, 120) 
   setWeaponClipAmmo(weapon, 32) 
   setWeaponState(weapon, "firing") 
   setElementAlpha(weapon, 0) 
   local newAK = createElement(object, 2965) 
   attachElements(weapon, newAK) 
end 
addCommandHandler("aktest", test)

local x,y,z = getElementPosition(localPlayer)

local weapon = createWeapon("AK-47",x,y,z)

  • Like 1
Link to comment
function test() 
  local x, y, z = getElementPosition(localPlayer) 
  local weapon = createWeapon("ak-47", x, y, z) 
   setWeaponAmmo(weapon, 120) 
   setWeaponClipAmmo(weapon, 32) 
   setWeaponState(weapon, "firing") 
   setElementAlpha(weapon, 0) 
   local newAK = createObject(2965, x, y, z) 
   attachElements(weapon, newAK) 
end 
addCommandHandler("aktest", test)

 

  • Like 1
Link to comment

bone_attach do the same as attachelements if I'm right, so it's still just be an object.

Can someone give me an example code of the weapon in the player hand and can aim+shoot? I can't figure out how to start.. I'm not a professional coder sorry. just need some skin on my server but I want to keep the original AK47 modell too.

Link to comment

Well you need use export functions resource name and use it on local player and bone of the right hand wich is id 25 and use it where you sees feet good at hand then see those function i give you and the even onClinetWeaponFire and you be good

getPedBonePosition

 

Link to comment

Still can't attach in my right hand (just creates the object where's my right hand but don't attach it in my hand) with bone_attach resource.

function test() 
  local x,y,z = getPedBonePosition(localPlayer, 25)
  local weapon = createWeapon("ak-47", x, y, z) 
   setWeaponAmmo(weapon, 120) 
   setWeaponClipAmmo(weapon, 32) 
   setWeaponState(weapon, "firing") 
   setElementAlpha(weapon, 0) 
   local newAK = createObject(2965, x, y, z) 
    exports['bone_attach']:attachElementToBone(weapon, newAK, 25, 0, 0, 0, 0, -90, 0)
end 
addCommandHandler("aktest", test)

 

Link to comment
function test() 
  local x,y,z = getElementPosition(localPlayer)
  local weapon = createWeapon("ak-47", x, y, z) 
   setWeaponAmmo(weapon, 120) 
   setWeaponClipAmmo(weapon, 32) 
   setWeaponState(weapon, "ready") 
   setElementAlpha(weapon, 0) 
   local newAK = createObject(2965, x, y, z) 
  attachElements(newAK, weapon)
    exports['bone_attach']:attachElementToBone(localPlayer, newAK, 25, 0, 0, 0, 0, -90, 0)
end 
addCommandHandler("aktest", test)

 

Edited by Dimos7
Link to comment
attachElementToBone(element,ped,bone,x,y,z,rx,ry,rz)

Bone IDs:
1: head
2: neck
3: spine
4: pelvis
5: left clavicle
6: right clavicle
7: left shoulder
8: right shoulder
9: left elbow
10: right elbow
11: left hand
12: right hand
13: left hip
14: right hip
15: left knee
16: right knee
17: left ankle
18: right ankle
19: left foot
20: right foot

Link to comment

Ah, I can't figure out how to use those functions ... at current state the weapon fires only 1 if I clicks mouse1 and my character using "boxing" anim , can't aim with mouse2 and shoot normal like the default weapons (ak47,m4,etc...)

function test()
   x,y,z = getElementPosition(localPlayer)
   weapon = createWeapon("ak-47", x, y, z)
   setWeaponAmmo(weapon, 120)
   setWeaponClipAmmo(weapon, 32)
   setWeaponState(weapon, "ready")
   setElementAlpha(weapon, 0)
   local newAK = createObject(2965, x, y, z)
   attachElements(weapon, newAK)
   exports['bone_attach']:attachElementToBone(newAK, localPlayer, 12, 0, 0, 0, 0, -90, 0)
   fireWeapon(weapon)
end
bindKey("mouse1", "down", test)
addCommandHandler("aktest", test)

 

Link to comment
function test()
   x,y,z = getElementPosition(localPlayer)
   weapon = createWeapon("ak-47", x, y, z)
   setWeaponAmmo(weapon, 120)
   setWeaponClipAmmo(weapon, 32)
   setWeaponState(weapon, "ready")
   setElementAlpha(weapon, 0)
   local newAK = createObject(2965, x, y, z)
   attachElements(weapon, newAK)
   exports['bone_attach']:attachElementToBone(newAK, localPlayer, 12, 0, 0, 0, 0, -90, 0)
end
addCommandHandler("aktest", test)

addEventHandler("onClientKey", root, function(button, press)
    if button =="mouse1" and press or button =="lalt" and press or button =="lctrl" and press or button =="ralt" and press or button =="rctrl" and press then
      fireWeapon(weapon) 
      setWeaponState(weapon, "firing") 
      else 
      setWeaponState(weapon, "ready") 
    end 
    end 
  ) 

addEventHandler("onClientWeaponFire" , root, function(hitElement, hitX, hitY, hitZ)
    setPedAimTarget(localPlayer, hitX, hitY, hitZ) 
    end 
  ) 

 

  • Like 1
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...