Jump to content

Vehicle minigun script


Xwad

Recommended Posts

Hi! I downloaded this script:

This script is only working on dayz mod (becaouse i need to move the item in the vehicles inventory). And i want to make that the minigun will be attached to the vehicle when the player enters the vehicle..I tryed to edit the script (with onCLientVehicleEnter) but it was not working, i just got errors..

So my question is that can you help me please to edit the script? So i want to make that the minigun will be attached when the player enters the vehicle

I hope you can help me..:) Thanks

these are just part of the script (parts where the minigun will be attached)

CLIENT.LUA

  
addEventHandler("onClientVehicleExit",getRootElement(),function()  
    triggerServerEvent("sv_destroyWeapon", getRootElement(), getLocalPlayer()) 
end) 
  
addEventHandler("onClientVehicleEnter",getRootElement(),function()  
    triggerServerEvent("sv_createWeapon", getRootElement(), getLocalPlayer()) 
end) 
  

SERVER.LUA

  
addEvent("sv_createWeapon", true) 
addEventHandler("sv_createWeapon", getRootElement(), function(item, loot, player) 
    if loot then 
    local veh = getElementData(loot,"parent") 
    local x,y,z = getElementPosition(veh) 
    local mid = getElementModel(veh) 
    if weapOff[mid] and item == minigun_name and not getElementData(veh, "weapon2") then 
        local weapon = createObject ( 362, x+weapOff[mid][1],y+weapOff[mid][2],z+weapOff[mid][3]) 
        local weapon_base = createObject ( 336, x+weapOff[mid][1],y+weapOff[mid][2],z) 
        attachElements ( weapon_base, veh, weapOff[mid][1], weapOff[mid][2], weapOff[mid][3], 0, 0, 0) 
        attachElements ( weapon, weapon_base, 0, -0.3, 0.9, weapOff[mid][4], weapOff[mid][5], weapOff[mid][6]) 
        setElementData(veh, "weapon", weapon_base) 
        setElementData(veh, "weapon2", weapon) 
    end 
    end 
    --triggerClientEvent("cl_waitForKey", getRootElement(), veh, weapon, player) 
end) 
  
  
  
  
  
addEvent("sv_destroyWeapon", true) 
addEventHandler("sv_destroyWeapon", getRootElement(), function(item, loot, player) 
    local veh = getElementData(loot,"parent") 
    if isElement(veh) and not getElementData(veh,"vehicle") then return end 
    if (getElementData(loot, minigun_name)or 0) <= 0 then 
        if getElementData(veh,"vehicle") then 
        destroyElement(getElementData(veh, "weapon2")) 
        destroyElement(getElementData(veh, "weapon")) 
        setElementData(veh, "weapon", false) 
        setElementData(veh, "weapon2", false) 
        end 
    end 
end) 
  

Link to comment
  • Moderators

Because it is most likely stolen if it is not on the community...

With other words, it is not on the community because he didn't want other people to have it. So... stolen and leaked.

If you want to use and edit leaked scripts, enjoy yourself. But don't be so disrespectful with somebody else his code and ask permission first.

Link to comment

1. Why are you using getRootElement(), getLocalPlayer()

Why not use the localPlayer as the source of the event?

2. You only trigger the localPlayer in your code.

That means you get only 1 argument in your function, the player, not item or loot.

You can't just write down "item" and expect it to become an item.

If you dont trigger item as an argument you cant use it.

Dont even understand what item or loot is.

Its like you just copy and paste, don't even think about what you wrote.

Try that:

addEventHandler("onClientVehicleExit",getRootElement(),function() 
    triggerServerEvent("sv_destroyWeapon", getLocalPlayer(), source) 
end) 
  
addEventHandler("onClientVehicleEnter",getRootElement(),function() 
    triggerServerEvent("sv_createWeapon", getLocalPlayer(), source) 
end) 

addEvent("sv_createWeapon", true) 
addEventHandler("sv_createWeapon", getRootElement(), function( veh ) 
    local x,y,z = getElementPosition(veh) 
    local mid = getElementModel(veh) 
    if weapOff[mid] and not getElementData(veh, "weapon2") then 
        local weapon = createObject ( 362, x+weapOff[mid][1],y+weapOff[mid][2],z+weapOff[mid][3]) 
        local weapon_base = createObject ( 336, x+weapOff[mid][1],y+weapOff[mid][2],z) 
        attachElements ( weapon_base, veh, weapOff[mid][1], weapOff[mid][2], weapOff[mid][3], 0, 0, 0) 
        attachElements ( weapon, weapon_base, 0, -0.3, 0.9, weapOff[mid][4], weapOff[mid][5], weapOff[mid][6]) 
        setElementData(veh, "weapon", weapon_base) 
        setElementData(veh, "weapon2", weapon) 
    end 
    --triggerClientEvent("cl_waitForKey", getRootElement(), veh, weapon, player) 
end) 

Not sure if its better to trigger the vehicle or get it serversided with getPedOccupiedVehicle.

Don't think there's much difference.

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