Jump to content

Different Models for 1 weapon


knightscript

Recommended Posts

Hello, I am new to scripting and I´m trying to open my own server, everything has gone good, but I have a problem I have not been able to solve, i need to have for example different type of M4´s with different skins and different damage with also different sound, what I currently have is this:

Weapon Skin:

  
      engineReplaceModel(dff, 358) 
      txd = engineLoadTXD("awp.txd", 358 ) 
      engineImportTXD(txd, 358) 
      dff = engineLoadDFF("awp.dff", 358 ) 
      engineReplaceModel(dff, 358) 
  

Weapon Audio:

  
addEventHandler("onClientPlayerWeaponFire", getRootElement(), 
function ( weapon, ammo, ammoInClip ) 
                local x,y,z = getElementPosition(source) 
                if weapon == 34 then 
                local sound = playSound3D("awp.mp3", x,y,z) 
                setSoundMaxDistance(sound,75) 
        end 
    end 
) 
  

I have tried to use objects as weapons, but I have had no success, i heard for the weapon skin it is possible to put a shader over it, but I dont have idea on how to do so, I know it is possible since i saw this code for a DayZ Script:

function loadModels() 
    weapontxd1 = engineLoadTXD ("models/weap/ak47.txd"); 
    weapondff1 = engineLoadDFF ("models/weap/ak47.dff"); 
end 
addEventHandler("onClientResourceStart",root,loadModels) 
  
  
function onClientPlayerSkinChange() 
    if getElementData(localPlayer,"currentweapon_1") == "FNFAL" then 
     if getElementData(localPlayer,"done") == true then return end 
        engineImportTXD (weapontxd1, 355); 
        engineReplaceModel (weapondff1, 355); 
        setElementData( localPlayer, "done", true) 
        
    elseif getElementData(localPlayer,"currentweapon_1") == "AK-47" then 
        engineRestoreModel(355) 
        setElementData( localPlayer, "done", false) 
    else 
        engineRestoreModel(355) 
        setElementData( localPlayer, "done", false) 
    end 
end 
addEventHandler("onClientPlayerWeaponSwitch",localPlayer,onClientPlayerSkinChange) 

I don´t want the code, i just would like to know what functions to use, thank you.

Link to comment

Example Weapon Skin in client side

--------------AK 47--------------------- 
  
txd = engineLoadTXD("armas/ak47.txd") 
engineImportTXD(txd, 355) 
dff = engineLoadDFF("armas/ak47.dff", 355) 
engineReplaceModel(dff, 355) 
  
------------Desert eagle----------------------- 
  
txd = engineLoadTXD("armas/desert_eagle.txd") 
engineImportTXD(txd, 348) 
dff = engineLoadDFF("armas/desert_eagle.dff", 348) 
engineReplaceModel(dff, 348) 
  
--------------M4---------------------- 
  
txd = engineLoadTXD("armas/m4.txd") 
engineImportTXD(txd, 356) 
dff = engineLoadDFF("armas/m4.dff", 356) 
engineReplaceModel(dff, 356) 
-------------MP5----------------------- 
  
txd = engineLoadTXD("armas/mp5.txd") 
engineImportTXD(txd, 353) 
dff = engineLoadDFF("armas/mp5.dff", 353) 
engineReplaceModel(dff, 353) 
  
--------------shotgun---------------------- 
  
txd = engineLoadTXD("armas/chromegun.txd") 
engineImportTXD(txd, 349) 
dff = engineLoadDFF("armas/chromegun.dff", 349) 
engineReplaceModel(dff, 349) 
  
---------------Sniper--------------------- 
  
txd = engineLoadTXD("armas/sniper.txd") 
engineImportTXD(txd, 358) 
dff = engineLoadDFF("armas/sniper.dff", 358) 
engineReplaceModel(dff, 358) 
  
  
---------------shotgspa12--------------------- 
  
txd = engineLoadTXD("armas/shotgspa.txd") 
engineImportTXD(txd, 351) 
dff = engineLoadDFF("armas/shotgspa.dff", 351) 
engineReplaceModel(dff, 351) 

Example Weapon Sound in client side

local function playGunfireSound(weaponID) 
local source = getLocalPlayer() 
    local muzzleX, muzzleY, muzzleZ = getPedWeaponMuzzlePosition(source) 
    local px, py, pz = getElementPosition ( source ) 
  
       if weaponID == 22 then --colt45 
            local sound = playSound3D("sounds/weap/Colt45.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 23 then 
            local sound = playSound3D("sounds/weap/Silenced.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 24 then--deagle 
            local sound = playSound3D("sounds/weap/Deagle.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 25 then--shotgun 
            local sound = playSound3D("sounds/weap/Shotgun.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 26 then--sawn-off 
            local sound = playSound3D("sounds/weap/Sawed-Off.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 27 then--combat shotgun 
            local sound = playSound3D("sounds/weap/Combat Shotgun.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 28 then--uzi 
            local sound = playSound3D("sounds/weap/UZI.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 32 then--tec-9 
            local sound = playSound3D("sounds/weap/tec9.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 29 then--mp5 
            local sound = playSound3D("sounds/weap/MP5.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 30 then--ak47 
            local sound = playSound3D("sounds/weap/AK-47.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 31 then--m4 
            local sound = playSound3D("sounds/weap/M4.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 33 then--rifle 
            local sound = playSound3D("sounds/weap/Rifle.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
    elseif weaponID == 34 then--sniper 
            local sound = playSound3D("sounds/weap/Sniper.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40) 
                     elseif weaponID == 16 then--grenade 
            local sound = playSound3D("sounds/weap/Bomba.mp3", muzzleX, muzzleY, muzzleZ, false) 
            setSoundMaxDistance(sound, 40)  
    end 
end 
addEventHandler("onClientPlayerWeaponFire", root, playGunfireSound) 

Link to comment

No, it's not possible. Unless they had changed all weapon models' textures to full transparency and then attached MTA objects through bone_attach. Default MTA weapons aren't elements, and therefore you cannot target them with dxSetShaderTexture (however, you can target all weapons of a particular weapon, or rather, a specific texture from all models)

Link to comment
  • 1 year later...

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