Jump to content

whats wrong with this script?


hipolitalakaj

Recommended Posts

7 minutes ago, hipolitalakaj said:

Thanks again!

You're really helped me a lot. I did the animation thing. It's possible to change the onclientkey press to hold? because the current state I can't fire and aim with the weapon constant...

Post the code so we help you 

Link to comment
addEventHandler("onClientKey", root, function(button, press)
    if button =="mouse1" and press or button =="lalt" and press or button =="lctrl" and press or $
      setPedAnimation(localPlayer, "rifle", "RIFLE_fire", -1, false, false, false, false)
      fireWeapon(weapon)
      setWeaponState(weapon, "firing")
      else
      setWeaponState(weapon, "ready")
    end
  if button =="mouse2" and press then
    if getControlState (localPlayer, "crouch") then
    setPedAnimation(localPlayer, "rifle", "RIFLE_crouchfire", -1, false, false, false, false)
  else
  setPedAnimation(localPlayer, "rifle", "RIFLE_fire", -1, false, false, false, false)
     setPedAimTarget(localPlayer, x, y, z)
  end
  end
  end)

anyways, the getcontrolstate not working or bugging if it is crouch? because then ignore the animation but if I change to jump or walk it's working...

Link to comment
addEventHandler("onClientKey", root, function(button, press)
    if button =="mouse1" and press or button =="lalt" and press or button =="lctrl" and press then
      setPedAnimation(localPlayer, "rifle", "rifle_fire", -1, false, false, false, false)
      fireWeapon(weapon)
      setWeaponState(weapon, "firing")
      else
      setWeaponState(weapon, "ready")
    end
  if button =="mouse2" and press then
    if button == "mouse2" and press and getControlState (localPlayer, "crouch") then
    setPedAnimation(localPlayer, "rifle", "rifle_crouchfire", -1, false, false, false, false)
  end
  setPedAnimation(localPlayer, "rifle", "rifle_fire", -1, false, false, false, false)
        end 
      else 
      setPedAnimation(localPlayer, false) 
      end
        if button =="mouse2" and press and button =="mouse1" and press then
         fireWeapon(weapon) 
          setWeaponState(weapon, "firing") 
          setPedAnimation(localPlayer, "rifle", "rifle_fire", - 1,false, false, false, false) 
      else 
      setPedAnimation(localPlayer, false)
      setWeaponState(weapon, "ready") 
    end 
          if button == "mouse1" and press and button =="mouse2" and press and getControlState(localPlayer, "crouch") then 
        fireWeapon(weapon) 
        setWeaponState(weapon, "firing") 
        setPedAnimation(localPlayer, "rifle", "rifle_crouchfire", - 1, false, false, false, false, false) 
        else 
        setPedAnimation(localPlayer, false) 
        setWeaponState(weapon, "ready") 
    end
  end
  end)

Try this 

Edited by Dimos7
Link to comment

You're forgot to close function at line 15 but I didn't get it where...

Loading script failed: aktest\client,lua:29: 'end' expected (to close 'function' at line 15) near 'else'

function test()
   x,y,z = getElementPosition(localPlayer)
   weapon = createWeapon("ak-47", x, y, z)
   setWeaponAmmo(weapon, 1)
   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 then
      setPedAnimation(localPlayer, "rifle", "rifle_fire", -1, false, false, false, false)
      fireWeapon(weapon)
      setWeaponState(weapon, "firing")
      else
      setWeaponState(weapon, "ready")
    end
  if button =="mouse2" and press then
    if button == "mouse2" and press and getControlState (localPlayer, "crouch") then
    setPedAnimation(localPlayer, "rifle", "rifle_crouchfire", -1, false, false, false, false)
  end
  setPedAnimation(localPlayer, "rifle", "rifle_fire", -1, false, false, false, false)
        end
      else
      setPedAnimation(localPlayer, false)
      end
        if button =="mouse2" and press and button =="mouse1" and press then
         fireWeapon(weapon)
          setWeaponState(weapon, "firing")
          setPedAnimation(localPlayer, "rifle", "rifle_fire", - 1,false, false, false, false)
      else
      setPedAnimation(localPlayer, false)
      setWeaponState(weapon, "ready")
    end
          if button == "mouse1" and press and button =="mouse2" and press and getControlState(localPlayer, "crouch") then
        fireWeapon(weapon)
        setWeaponState(weapon, "firing")
        setPedAnimation(localPlayer, "rifle", "rifle_crouchfire", - 1, false, false, false, false, false)
        else
        setPedAnimation(localPlayer, false)
        setWeaponState(weapon, "ready")
    end
  end
  end)

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

 

Link to comment
function test()
   x,y,z = getElementPosition(localPlayer)
   weapon = createWeapon("ak-47", x, y, z)
   setWeaponAmmo(weapon, 1)
   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 then
      setPedAnimation(localPlayer, "rifle", "rifle_fire", -1, false, false, false, false)
      fireWeapon(weapon)
      setWeaponState(weapon, "firing")
      else
      setPedAnimation(localPlayer, false) 
     setWeaponState(weapon, "ready")
    end
  if button =="mouse2" and press then
    if button == "mouse2" and press and getControlState (localPlayer, "crouch") then
    setPedAnimation(localPlayer, "rifle", "rifle_crouchfire", -1, false, false, false, false)
        else 
        setPedAnimation(localPlayer, false) 
  end
  setPedAnimation(localPlayer, "rifle", "rifle_fire", -1, false, false, false, false)
     else
      setPedAnimation(localPlayer, false)
      end
        if button =="mouse2" and press and button =="mouse1" and press then
         fireWeapon(weapon)
          setWeaponState(weapon, "firing")
          setPedAnimation(localPlayer, "rifle", "rifle_fire", - 1,false, false, false, false)
      else
      setPedAnimation(localPlayer, false)
      setWeaponState(weapon, "ready")
    end
          if button == "mouse1" and press and button =="mouse2" and press and getControlState(localPlayer, "crouch") then
        fireWeapon(weapon)
        setWeaponState(weapon, "firing")
        setPedAnimation(localPlayer, "rifle", "rifle_crouchfire", - 1, false, false, false, false, false)
        else
        setPedAnimation(localPlayer, false)
        setWeaponState(weapon, "ready")
    end
  end
  end)

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

 

Link to comment
9 minutes ago, Dimos7 said:

yes

What yes?

I said I doesn't have opened line but the debugscript says that "Loading script failed: aktest/client.lua:51: ')' expected (to close '(' at line 15) near 'end'"

1 minute ago, AlexRazor said:

You can make it a lot easier. Just make original weapon invisible(by editing txd) and then or attach object or attach weapon.

But I want to keep the original AK-47 too.

Link to comment

Yeah , but I can't do it for localplayer only in that way... because if someone uses eg.: camo ak-47 from their inventory then all other players who have ak-47 (id 30) seen camo ak

I did research about custom weapons example before I posted this, but found nothing custom weapons with txd and dff.. just with shaders (with png files) which are ugly.

Link to comment
function test()
   x,y,z = getElementPosition(localPlayer)
   weapon = createWeapon("ak-47", x, y, z)
   setWeaponAmmo(weapon, 1)
   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 then
             setPedAnimation(localPlayer, "rifle", "rifle_fire", -1, false, true, false, false)
             fireWeapon(weapon)
             setWeaponState(weapon, "firing")
         else
             setPedAnimation(localPlayer, false) 
             setWeaponState(weapon, "ready")
         end
         if button =="mouse2" and press then
              if button == "mouse2" and press and getControlState (localPlayer, "crouch") then
                   setPedAnimation(localPlayer, "rifle", "rifle_crouchfire", -1, false, true, false, false)
               else 
                   setPedAnimation(localPlayer, false) 
              end
              setPedAnimation(localPlayer, "rifle", "rifle_fire", -1, false, true, false, false)
         else
            setPedAnimation(localPlayer, false)
         end
    end
)

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

 

Edited by Dimos7
Link to comment

My character still "boxing" the air I think it's because the equiped weapon is meele (0) and I need to set the equipped weapon to ID 5 which is rifle, right?

https://wiki.multitheftauto.com/wiki/SetPedWeaponSlot

I trying to change the weaponslot to ID 5 , but it isn't working... the getpedweaponslot returns 0 in the chatbox after I run the command.

setPedWeaponSlot(localPlayer, 5)

And the "rifle_crouchfire" anim still not working if the state is crouch.

Link to comment
4 hours ago, hipolitalakaj said:

What yes?

I said I doesn't have opened line but the debugscript says that "Loading script failed: aktest/client.lua:51: ')' expected (to close '(' at line 15) near 'end'"

But I want to keep the original AK-47 too.

You can add original ak as custom weapon.
You replace objects with weapon skins and attach them to your hand.

Link to comment

And how can I do it that replace the weapon only for the localplayer who using the eg.: camo ak? because if I make the original ak inivisble and replace with the custom then changes the skin for everyone not just for localplayer who using the custom ak. isn't it? (eh my english is s.cks but hope u understand what I mean)

Link to comment
6 minutes ago, hipolitalakaj said:

And how can I do it that replace the weapon only for the localplayer who using the eg.: camo ak? because if I make the original ak inivisble and replace with the custom then changes the skin for everyone not just for localplayer who using the custom ak. isn't it? (eh my english is s.cks but hope u understand what I mean)

You should replace original AK model with invisible model and replace any usable object model with model of camo AK. Then you give player weapon(with invisible model) and attach camo AK model to his hand while he uses AK.

Edited by AlexRazor
Link to comment

It's okay but if I give ak to the player (I need to provide the default AK id 30) and the weapon ID 30 model ID is 355.. so if I do the "engineImportTXD" , "engineReplaceModel" I need to provide the 355 Model ID for every custom skin.. or can I give example weapon ID 30 with any usable object ID (2965) instead of 355 model ID?

Edited by hipolitalakaj
Link to comment
11 minutes ago, hipolitalakaj said:

It's okay but if I give ak to the player (I need to provide the default AK id 30) and the weapon ID 30 model ID is 355.. so if I do the "engineImportTXD" , "engineReplaceModel" I need to provide the 355 Model ID every custom skin.. or can I give example weapon ID 30 with any usable object ID (2965) instead of 355 model ID?

Didn't quite understand you.
First you replace original 355 model with invisible model.
Then you replace 2965(for example) model with AK model.
Then you replace 2966(for example) model with AK CAMO model.
When you want to give someone weapon you do giveWeapon(30) then createObject with model object ID of weapon of choice(2965 normal ak OR 2966 camo) and then attach thath object to player hand.

Edited by AlexRazor
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...