hipolitalakaj Posted January 16, 2019 Posted January 16, 2019 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)
AncienT Posted January 16, 2019 Posted January 16, 2019 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) 1
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 (edited) Thanks for your reply, now the weapon creates. But the object not and can't attach it to player. I got this error in debugscript: https://imgur.com/a/ICuMSA2 Edited January 16, 2019 by hipolitalakaj
Dimos7 Posted January 16, 2019 Posted January 16, 2019 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) 1
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 Okay, now works. But at current state it's just an object and not in my hand + I can't use as weapon. I can't aim , shoot etc...How can I do that?
Dimos7 Posted January 16, 2019 Posted January 16, 2019 (edited) You need attach it to player hand attachElements getKeyState fireWeapon setWeaponState setPedAimTarget Edited January 16, 2019 by Dimos7
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 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.
Dimos7 Posted January 16, 2019 Posted January 16, 2019 We can't provide you code you need start learning
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 I don't want the full code. Just wants to know how to start with the bone_attach resource.
Dimos7 Posted January 16, 2019 Posted January 16, 2019 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
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 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)
Dimos7 Posted January 16, 2019 Posted January 16, 2019 (edited) 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 January 16, 2019 by Dimos7
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 Same, it's not attach it to my hand. Just creates the object where's my right hand
Zorgman Posted January 16, 2019 Posted January 16, 2019 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
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 Yes, I already did with the ID 12 too, but nothing changed.
Zorgman Posted January 16, 2019 Posted January 16, 2019 (edited) attachElements(weapon, newAK) exports['bone_attach']:attachElementToBone(newAK, localPlayer, 12, 0, 0, 0, 0, -90, 0) Edited January 16, 2019 by Zorgman 1
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 That's it! lol, but I already tried this before I posted with the ID 25. Thanks.
Zorgman Posted January 16, 2019 Posted January 16, 2019 You were attaching the player to the weapon object. Cheers!
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 Umm, I don't wanna be rude, you guys helped me a lot but which functions I need to make the attached object can aim and shooting if I press right / left mouse button?
Dimos7 Posted January 16, 2019 Posted January 16, 2019 onClientWeaponFire fireWeapon setWeaponState setPedAimTarget getKeyState
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 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)
Dimos7 Posted January 16, 2019 Posted January 16, 2019 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 ) 1
hipolitalakaj Posted January 16, 2019 Author Posted January 16, 2019 Thanks man! it's fire now, but what can I do with the aim? I can't aim with mouse2 ... and my character is "boxing" if I click mouse1, like my current weapon is meele.
Dimos7 Posted January 16, 2019 Posted January 16, 2019 (edited) setPedAnimation getPedTarget On client key put if button is mouse2 and find the correct anim Edited January 16, 2019 by Dimos7
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