Jump to content

helppp!!!


WASSIm.

Recommended Posts

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

  • Moderators

The weapon fire should be elementdata or it have to be registered at server side which weapon is firing. and no the code isn't yet fully synced.

It took me 6 hours to create the perfect lagg free code.

Edited by Guest
Link to comment
Fine, try this:

server:

addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
  
addEventHandler("onVehicleExit", root,function(player,seat) 
    triggerClientEvent ( "onExit",source,player,seat)  
end) 
addEvent("fire",false) 
addEventHandler("fire",root,function(state) 
    if state=="down"then 
        triggerClientEvent("onEnableFire",client) 
    elseif state=="up"then 
        triggerClientEvent ("onDisableFire",client) 
    end 
end) 

Client:

local miniguns = {} 
  
addEvent( "onEnter", true ) 
addEventHandler( "onEntre",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    miniguns[thePlayer] = {} 
    local x, y, z = getElementPosition ( source ) 
    local rx, ry, rz = getElementRotation ( source ) 
    miniguns[thePlayer][1] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][2] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][3] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][4] = createWeapon ("minigun",  x,  y,  z ) 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        setWeaponOwner ( minigun, thePlayer) 
        setElementAlpha ( minigun,0) 
    end 
    attachElements ( miniguns[thePlayer][1], source, 2.15, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][2], source, -2.10, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][3], source, 2.57, 0.5, -1.1, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][4], source, -2.52, 0.5, -1.1, 0, 0, 90 ) 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        bindKey ( key, "down",fire )         
        bindKey ( key, "up",fire ) 
    end 
end) 
  
addEvent( "onExit", true ) 
addEventHandler( "onEntre",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        destroyElement (minigun) 
    end 
    miniguns[thePlayer] = nil 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        unbindKey ( key, "down",fire )         
        unbindKey ( key, "up",fire ) 
    end 
end) 
function fire(_,state) 
    triggerServerEvent("fire",localPlayer,state) 
end 
  
function move(source) 
    local MiniSound = playSound3D("test.wav", x, y, z,false) 
    setSoundMaxDistance(MiniSound, 140) 
    setSoundEffectEnabled(MiniSound,"gargle",true) 
    attachElements ( MiniSound, getPedOccupiedVehicle(source), 0, 0.5, -1.1, 0, 0, 90 ) 
end 
addEvent( "onEnableFire", true ) 
addEventHandler( "onEnableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "firing") 
    end 
    move(source) 
end) 
addEvent( "onDisableFire", true ) 
addEventHandler( "onDisableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "ready") 
    end 
    move(source) 
end) 

You have a small problem here : )

addEvent( "onEnter", true ) 
addEventHandler( "onEntre",root,function(thePlayer, seat) 

Also Here.

addEvent( "onExit", true ) 
addEventHandler( "onEntre",root,function(thePlayer, seat) 

Link to comment

Can you please post any errors that comes up after we tell you try something, because we don't automatically know what's wrong with the script.

Anyways,

For what I know, the function setWeaponState doesn't work, or the weapon doesn't fire.

This is what I got for you:

Server:

addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
addEventHandler("onVehicleStartExit", root,function(player,seat) 
    triggerClientEvent("onExit",source,player,seat) 
end) 

Client:

local miniguns = {} 
local shootKey 
function move(source) 
    local MiniSound = playSound3D("test.wav", x, y, z,false) 
    setSoundMaxDistance(MiniSound, 140) 
    setSoundEffectEnabled(MiniSound,"gargle",true) 
    attachElements ( MiniSound, getPedOccupiedVehicle(source), 0, 0.5, -1.1, 0, 0, 90 ) 
end 
function fire() 
    if getKeyState(shootKey)then 
        if not getElementData(localPlayer,"minigunStatus")then 
            setElementData(localPlayer,"minigunStatus",true) 
        end 
    else 
        if getElementData(localPlayer,"minigunStatus")then 
            setElementData(localPlayer,"minigunStatus",false) 
        end 
    end 
end 
for key,_ in pairs(getBoundKeys("vehicle_fire"))do 
    shootKey = key 
    break 
end 
  
addEvent( "onEnter", true ) 
addEventHandler( "onEnter",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    miniguns[thePlayer] = {} 
    local x, y, z = getElementPosition ( source ) 
    miniguns[thePlayer][1] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][2] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][3] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][4] = createWeapon ( "minigun",  x,  y,  z ) 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        --setWeaponOwner(minigun, thePlayer) for some reason this doesn't work! 
        setElementAlpha ( minigun,255) 
    end 
    attachElements ( miniguns[thePlayer][1], source, 2.15, 0.5, -1.2, 70, 20, 100 ) 
    attachElements ( miniguns[thePlayer][2], source, -2.10, 0.5, -1.2, 70, 20, 100 ) 
    attachElements ( miniguns[thePlayer][3], source, 2.57, 0.5, -1.1, 70, 20, 100 ) 
    attachElements ( miniguns[thePlayer][4], source, -2.52, 0.5, -1.1, 70, 20, 100 ) 
    if thePlayer~=localPlayer then return end 
    addEventHandler("onClientRender",root,fire) 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
end) 
addEvent( "onExit", true ) 
addEventHandler( "onExit",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        destroyElement (minigun) 
    end 
    miniguns[thePlayer] = nil 
    if thePlayer~=localPlayer then return end 
    removeEventHandler("onClientRender",root,fire) 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
end) 
  
addEventHandler("onClientElementDataChange",root,function(name) 
    if name~="minigunStatus"then return end 
    if not isPedInVehicle(source)then return end 
    local state = getElementData(source,name) 
    if state and state==true then 
        for _,minigun in ipairs(miniguns[source])do 
            setWeaponState(minigun,"firing") 
        end 
    else 
        for _,minigun in ipairs(miniguns[source])do 
            setWeaponState(minigun,"ready") 
        end 
    end 
end) 

Link to comment
Can you please post any errors that comes up after we tell you try something, because we don't automatically know what's wrong with the script.

Anyways,

For what I know, the function setWeaponState doesn't work, or the weapon doesn't fire.

This is what I got for you:

...

error for that

sanstitrebnm.png

Fine, try this:

server:

addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
  
addEventHandler("onVehicleExit", root,function(player,seat) 
    triggerClientEvent ( "onExit",source,player,seat)  
end) 
addEvent("fire",false) 
addEventHandler("fire",root,function(state) 
    if state=="down"then 
        triggerClientEvent("onEnableFire",client) 
    elseif state=="up"then 
        triggerClientEvent ("onDisableFire",client) 
    end 
end) 

Client:

local miniguns = {} 
  
addEvent( "onEnter", true ) 
addEventHandler( "onEnter",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    miniguns[thePlayer] = {} 
    local x, y, z = getElementPosition ( source ) 
    local rx, ry, rz = getElementRotation ( source ) 
    miniguns[thePlayer][1] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][2] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][3] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][4] = createWeapon ("minigun",  x,  y,  z ) 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        setWeaponOwner ( minigun, thePlayer) 
        setElementAlpha ( minigun,0) 
    end 
    attachElements ( miniguns[thePlayer][1], source, 2.15, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][2], source, -2.10, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][3], source, 2.57, 0.5, -1.1, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][4], source, -2.52, 0.5, -1.1, 0, 0, 90 ) 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        bindKey ( key, "down",fire )         
        bindKey ( key, "up",fire ) 
    end 
end) 
  
addEvent( "onExit", true ) 
addEventHandler( "onExit",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        destroyElement (minigun) 
    end 
    miniguns[thePlayer] = nil 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        unbindKey ( key, "down",fire )         
        unbindKey ( key, "up",fire ) 
    end 
end) 
function fire(_,state) 
    triggerServerEvent("fire",localPlayer,state) 
end 
  
function move(source) 
    local MiniSound = playSound3D("test.wav", x, y, z,false) 
    setSoundMaxDistance(MiniSound, 140) 
    setSoundEffectEnabled(MiniSound,"gargle",true) 
    attachElements ( MiniSound, getPedOccupiedVehicle(source), 0, 0.5, -1.1, 0, 0, 90 ) 
end 
addEvent( "onEnableFire", true ) 
addEventHandler( "onEnableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "firing") 
    end 
    move(source) 
end) 
addEvent( "onDisableFire", true ) 
addEventHandler( "onDisableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "ready") 
    end 
    move(source) 
end) 

Link to comment

Actually, when you think about it, if multiple of players are in a hunter and it's synchronizing through the server with every other player, then you would need to added a table for a player so the resource could hold other players miniguns throughout the server.

This is the only way to sync the minigun through every player on the server.

Anyways, @WASSIm. , Try not to start/restart the resource when you're in the helicopter.

Link to comment

Here you are try this one and this one not tested but i hope it's work :

local miniguns = {} 
  
addEvent( "onEnter", true ) 
addEventHandler( "onEnter",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
 if not miniguns[thePlayer] then 
  miniguns[thePlayer] = {} 
 end 
    local x, y, z = getElementPosition ( source ) 
    local rx, ry, rz = getElementRotation ( source ) 
    miniguns[thePlayer][1] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][2] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][3] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][4] = createWeapon ("minigun",  x,  y,  z ) 
    for i = 1,#minigun[thePlayer] do 
        setWeaponOwner ( minigun[thePlayer][i], thePlayer) 
        setElementAlpha ( minigun[thePlayer][i],0) 
    end 
    attachElements ( miniguns[thePlayer][1], source, 2.15, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][2], source, -2.10, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][3], source, 2.57, 0.5, -1.1, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][4], source, -2.52, 0.5, -1.1, 0, 0, 90 ) 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        bindKey ( key, "down",fire )         
        bindKey ( key, "up",fire ) 
    end 
end) 
  
addEvent( "onExit", true ) 
addEventHandler( "onExit",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        destroyElement (minigun) 
    end 
    miniguns[thePlayer] = nil 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        unbindKey ( key, "down",fire )         
        unbindKey ( key, "up",fire ) 
    end 
end) 
function fire(_,state) 
    triggerServerEvent("fire",localPlayer,state) 
end 
  
function move(source) 
    local MiniSound = playSound3D("test.wav", x, y, z,false) 
    setSoundMaxDistance(MiniSound, 140) 
    setSoundEffectEnabled(MiniSound,"gargle",true) 
    attachElements ( MiniSound, getPedOccupiedVehicle(source), 0, 0.5, -1.1, 0, 0, 90 ) 
end 
addEvent( "onEnableFire", true ) 
addEventHandler( "onEnableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "firing") 
    end 
    move(source) 
end) 
addEvent( "onDisableFire", true ) 
addEventHandler( "onDisableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "ready") 
    end 
    move(source) 
end) 

And the server side use the same one .

Link to comment
local miniguns = {} 
  
addEvent( "onEnter", true ) 
addEventHandler( "onEnter",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
 if not miniguns[thePlayer] then 
  miniguns[thePlayer] = {} 
 end 
    local x, y, z = getElementPosition ( source ) 
    local rx, ry, rz = getElementRotation ( source ) 
    miniguns[thePlayer][1] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][2] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][3] = createWeapon ( "minigun",  x,  y,  z ) 
    miniguns[thePlayer][4] = createWeapon ("minigun",  x,  y,  z ) 
    for i = 1,#miniguns[thePlayer] do 
        setWeaponOwner ( miniguns[thePlayer][i], thePlayer) 
        setElementAlpha ( miniguns[thePlayer][i],0) 
    end 
    attachElements ( miniguns[thePlayer][1], source, 2.15, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][2], source, -2.10, 0.5, -1.2, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][3], source, 2.57, 0.5, -1.1, 0, 0, 90 ) 
    attachElements ( miniguns[thePlayer][4], source, -2.52, 0.5, -1.1, 0, 0, 90 ) 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        bindKey ( key, "down",fire )         
        bindKey ( key, "up",fire ) 
    end 
end) 
  
addEvent( "onExit", true ) 
addEventHandler( "onExit",root,function(thePlayer, seat) 
    if seat ~= 0 and getElementModel(source) ~= 425 then return end 
    for _,minigun in ipairs(miniguns[thePlayer])do 
        destroyElement (minigun) 
    end 
    miniguns[thePlayer] = nil 
    if thePlayer~=localPlayer then return end 
    toggleControl ( "vehicle_fire", false ) 
    toggleControl ( "vehicle_secondary_fire", false ) 
    for _,key in ipairs(getBoundKeys("vehicle_fire"))do 
        unbindKey ( key, "down",fire )         
        unbindKey ( key, "up",fire ) 
    end 
end) 
function fire(_,state) 
    triggerServerEvent("fire",localPlayer,state) 
end 
  
function move(source) 
    local MiniSound = playSound3D("test.wav", x, y, z,false) 
    setSoundMaxDistance(MiniSound, 140) 
    setSoundEffectEnabled(MiniSound,"gargle",true) 
    attachElements ( MiniSound, getPedOccupiedVehicle(source), 0, 0.5, -1.1, 0, 0, 90 ) 
end 
addEvent( "onEnableFire", true ) 
addEventHandler( "onEnableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "firing") 
    end 
    move(source) 
end) 
addEvent( "onDisableFire", true ) 
addEventHandler( "onDisableFire",root,function() 
    for _,minigun in ipairs(miniguns[source])do 
        setWeaponState ( minigun, "ready") 
    end 
    move(source) 
end) 

Link to comment

what i use server said ?

addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
  
addEventHandler("onVehicleExit", root,function(player,seat) 
    triggerClientEvent ( "onExit",source,player,seat) 
end) 
addEvent("fire",false) 
addEventHandler("fire",root,function(state) 
    if state=="down"then 
        triggerClientEvent("onEnableFire",client) 
    elseif state=="up"then 
        triggerClientEvent ("onDisableFire",client) 
    end 
end) 

addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
addEventHandler("onVehicleStartExit", root,function(player,seat) 
    triggerClientEvent("onExit",source,player,seat) 
end) 

Link to comment
what i use server said ?
addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
  
addEventHandler("onVehicleExit", root,function(player,seat) 
    triggerClientEvent ( "onExit",source,player,seat) 
end) 
addEvent("fire",false) 
addEventHandler("fire",root,function(state) 
    if state=="down"then 
        triggerClientEvent("onEnableFire",client) 
    elseif state=="up"then 
        triggerClientEvent ("onDisableFire",client) 
    end 
end) 

addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
addEventHandler("onVehicleStartExit", root,function(player,seat) 
    triggerClientEvent("onExit",source,player,seat) 
end) 

The second one .

Link to comment
what i use server said ?
addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
  
addEventHandler("onVehicleExit", root,function(player,seat) 
    triggerClientEvent ( "onExit",source,player,seat) 
end) 
addEvent("fire",false) 
addEventHandler("fire",root,function(state) 
    if state=="down"then 
        triggerClientEvent("onEnableFire",client) 
    elseif state=="up"then 
        triggerClientEvent ("onDisableFire",client) 
    end 
end) 

addEventHandler ("onVehicleEnter", root,function(player,seat) 
    triggerClientEvent("onEnter",source,player,seat)   
end) 
addEventHandler("onVehicleStartExit", root,function(player,seat) 
    triggerClientEvent("onExit",source,player,seat) 
end) 

The second one .

Link to comment
Can you tell us what's not working?

Is the minivan being created?

Is the minuting shooting?

Is the minigun killing other players/Peds?

These are the info we need!

Random problems:

-script not working

or

-working but to all vehicles and can't kill players/peds

or

-working but can't kill players/peds <---first problem

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