Jump to content

Weapon is not demaging!


Xwad

Recommended Posts

Posted

Is it now good?

  
      
  
vehWeapons = {} 
function createM4Weapon() 
    if getElementModel(source) == 432 then 
     triggerServerEvent ( "MachineGun", localPlayer,  { 
    vehWeapons[source] = {} 
        local vX, vY, vZ = getElementPosition(source) 
        -- Wep 1 
        vehWeapons[source][1] = createWeapon("m4", vX, vY, vZ + 1) 
        setWeaponClipAmmo(vehWeapons[source][1], 500) 
        setWeaponState(vehWeapons[source][1], "ready") 
        attachElements(vehWeapons[source][1],source,0.7,2.4,0.7,0,0,90) 
        setWeaponFiringRate ( vehWeapons[source][1] , 63  ) 
    end 
end 
addEventHandler( "onClientVehicleEnter",getRootElement(),createM4Weapon) 
  
  
addEventHandler("onClientKey", root, 
function(button,state) 
    local veh = getPedOccupiedVehicle(localPlayer) 
    if veh then 
        if getElementModel(veh) == 432 then 
            if vehWeapons[veh][1] then 
                if button == "lctrl" and state == true then 
                    setWeaponState(vehWeapons[veh][1],"firing") 
                else 
                    setWeaponState(vehWeapons[veh][1],"ready") 
                end 
            end 
        end 
    end 
end) 
  
  
function destroyCurrentVehicleWeapons() 
    destroyElement(vehWeapons[source][1]) 
    vehWeapons[source] = false -- Destroy the Weapons 
end 
addEventHandler("onClientVehicleExit",root, destroyCurrentVehicleWeapons) 
addEventHandler("onClientVehicleExplode",root, destroyCurrentVehicleWeapons) 
  
addEvent ( "MachineGun2", true ); 
addEventHandler ( "MachineGun2", root, createM4Weapon ) 
  

Posted

no it's not try this now

vehWeapons = {} 
  
function createM4Weapon() 
    if getElementModel(source) == 432 then 
        triggerServerEvent ( "MachineGun", localPlayer) 
        local vX, vY, vZ = getElementPosition(source) 
        vehWeapons[source] = createWeapon("m4", vX, vY, vZ + 1) 
        setWeaponClipAmmo(vehWeapons[source], 500) 
        setWeaponState(vehWeapons[source], "ready") 
        attachElements(vehWeapons[source],source,0.7,2.4,0.7,0,0,90) 
        setWeaponFiringRate ( vehWeapons[source], 63  ) 
    end 
end 
addEventHandler( "onClientVehicleEnter",getRootElement(),createM4Weapon) 
  
  
addEventHandler("onClientKey", root, 
function(button,state) 
    local veh = getPedOccupiedVehicle(localPlayer) 
    if veh then 
        if getElementModel(veh) == 432 then 
            if vehWeapons[veh] then 
                if button == "lctrl" and state == true then 
                    setWeaponState(vehWeapons[veh],"firing") 
                else 
                    setWeaponState(vehWeapons[veh],"ready") 
                end 
            end 
        end 
    end 
end) 
  
  
function destroyCurrentVehicleWeapons() 
    if isElement(vehWeapons[source]) then  
    destroyElement(vehWeapons[source]) 
    vehWeapons[source] = false  
    end  
end 
addEventHandler("onClientVehicleExit",root, destroyCurrentVehicleWeapons) 
addEventHandler("onClientVehicleExplode",root, destroyCurrentVehicleWeapons) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

  • 5 months later...
Posted

why is the bind key not working? The debugscript says that the setWeaponState has a bad argumentum.

function createMachineGun(theWeapon, theState) 
    local x, y, z = getElementPosition(getLocalPlayer()) 
    local weapon = createWeapon("m4", x, y, z + 1) 
    setWeaponClipAmmo(weapon, 100) 
    setWeaponState(weapon, "ready") 
    setWeaponFiringRate ( weapon , 30  ) 
end 
addEventHandler('onClientResourceStart', getRootElement(), createMachineGun) 
  
  
  
function binds() 
bindKey ( "mouse1", "down", fire_start ) 
bindKey ( "mouse1", "up", fire_stop ) 
end 
addEventHandler('onClientResourceStart', getRootElement(), binds) 
  
  
function fire_start(theWeapon, theState) 
setWeaponState(weapon, "firing") 
end 
  
function fire_stop(theWeapon, theState) 
setWeaponState(weapon, "ready") 
end 
  

  • Moderators
Posted

Remove > local < from line 3.

When you set a variable to a local, it can only be used within the block and only in the lines bellow.

Line 1 t/m 7 is a block, a function block.

function createMachineGun(theWeapon, theState)

    local x, y, z = getElementPosition(getLocalPlayer())

    local weapon = createWeapon("m4", x, y, z + 1)

setWeaponClipAmmo(weapon, 100)

setWeaponState(weapon, "ready")

setWeaponFiringRate ( weapon , 30  )

end

addEventHandler('onClientResourceStart', getRootElement(), createMachineGun)

When you place a local variable outside a block(not in function/if elseif then do), the whole document will be considered as block.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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