Jump to content

Weapon is not demaging!


Xwad

Recommended Posts

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 ) 
  

Link to comment

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) 

Link to comment
  • 5 months later...

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 
  

Link to comment
  • Moderators

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.

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