murilo2929 Posted June 5, 2020 Share Posted June 5, 2020 Hey guys, i just want add new types of weapons for this script but don't know how, i tried to replicate the functions and change the parameters but no success. Can anyone help me? Obs: The system is set to M4 only. Client-side guns = { {"M4A1",2726}, -- Weapon, Object {"M4A3 CCO",1730}, {"AK-74",1851}, {"AKS Gold",1882}, {"PKP",1822}, {"M240",1769}, {"FN FAL",2644}, {"M4A1 CCO SD",1852}, } weapsIDs = {356} for i,weapID in pairs(weapsIDs)do txd = engineLoadTXD("models/None.txd",weapID) engineImportTXD(txd,weapID) dff = engineLoadDFF("models/None.dff",weapID) engineReplaceModel(dff,weapID) end for i,weaponData in pairs(guns) do file = weaponData[1]:gsub(' ','') if fileExists("models/"..file..".txd") and fileExists("models/"..file..".dff")then txd = engineLoadTXD("models/"..file..".txd",weaponData[2]) engineImportTXD(txd,weaponData[2]) dff = engineLoadDFF("models/"..file..".dff",weaponData[2]) engineReplaceModel(dff,weaponData[2]) else outputChatBox("ERROR: models/"..file) end end function playerJoined() local Variavel_1 = isWorldSoundEnabled ( 5 ) -- Colocamos esta variável aqui para verificar. setWorldSoundEnabled ( 5, not Variavel_1 ) -- E aqui a alternância acontece. end addEvent("playerJoined",true) addEventHandler("playerJoined",getRootElement(),playerJoined) function PlaySound(ID) wpn1 = getElementData(source,"cweapon") x,y,z = getPedWeaponMuzzlePosition(source) for _,weap in pairs(guns)do soundName = weap[1]:gsub(' ','') if wpn1 == weap[1] then if not fileExists("Sounds/Primary/"..soundName..".wav")then return end sound = playSound3D("Sounds/Primary/"..soundName..".wav",x,y,z, false) setSoundMaxDistance(sound,200) end end end addEventHandler("onClientPlayerWeaponFire",root,PlaySound) -- GUI PART GUIEditor = { gridlist = {}, window = {} } GUIEditor.window[1] = guiCreateWindow(0.21, 0.36, 0.18, 0.36, "NEW WEAPONS", true) guiWindowSetSizable(GUIEditor.window[1], false) guiSetVisible(GUIEditor.window[1], false) GUIEditor.gridlist[1] = guiCreateGridList(0.06, 0.12, 0.87, 0.85, true, GUIEditor.window[1]) guiGridListAddColumn(GUIEditor.gridlist[1], "guns", 0.9) for data,item in pairs(guns) do for i = 0, data do guiGridListAddRow(GUIEditor.gridlist[1]) end guiGridListSetItemText(GUIEditor.gridlist[1], data, 1, item[1], false, false) end function guiOpen() if (guiGetVisible(GUIEditor.window[1]) == true) then guiSetVisible(GUIEditor.window[1], false) showCursor(false) else guiSetVisible(GUIEditor.window[1], true) showCursor(true) end end bindKey("F2", "down", guiOpen) function click ( button, state, sx, sy, x, y, z, elem, gui ) if ( guiGridListGetSelectedItem ( GUIEditor.gridlist[1] ) ) then local getwep = guiGridListGetSelectedItemText ( GUIEditor.gridlist[1] ) for data,item in ipairs(guns) do setElementData(getLocalPlayer(),"cweapon",getwep) end end end addEventHandler ( "onClientGUIClick", GUIEditor.gridlist[1], click ) function guiGridListGetSelectedItemText ( gridList, column ) local item = guiGridListGetSelectedItem ( gridList ) if item then return guiGridListGetItemText ( gridList, item, column or 1 ) end return false end addEventHandler("onClientRender", root, function () local currentWeapon = getElementData(localPlayer, "cweapon") dxDrawText("Current weapon: "..currentWeapon, 10, 200) end ) Server-side guns = { {"M4A1",2726}, -- Weapon, Object {"M4A3 CCO",1730}, {"AK-74",1851}, {"AKS Gold",1882}, {"PKP",1822}, {"M240",1769}, {"FN FAL",2644}, {"M4A1 CCO SD",1852}, } elementWeaponRaplace = {} function weaponReplace(previousWeaponID,currentWeaponID) local weapon = getElementData(source,"cweapon") if not weapon then return end local x,y,z = getElementPosition(source) local rx,ry,rz = getElementRotation(source) local interior = getElementInterior(source) local dimension = getElementDimension(source) if previousWeaponID and getPedWeaponSlot(source) == 0 then if elementWeaponRaplace[source] then detachElementFromBone(elementWeaponRaplace[source]) destroyElement(elementWeaponRaplace[source]) elementWeaponRaplace[source] = false end for id,item in ipairs(guns)do if weapon == item[1] then elementWeaponRaplace[source] = createObject(item[2],x,y,z) setObjectScale(elementWeaponRaplace[source],0.825) setElementInterior(elementWeaponRaplace[source], interior) setElementDimension(elementWeaponRaplace[source], dimension) end end attachElementToBone(elementWeaponRaplace[source],source,12,0,0,0,0,270,0) elseif currentWeaponID and getPedWeaponSlot(source) == 5 or previousWeaponID and getPedWeaponSlot(source) == 2 then detachElementFromBone(elementWeaponRaplace[source]) if elementWeaponRaplace[source] then destroyElement(elementWeaponRaplace[source]) end elementWeaponRaplace[source] = false end end addEventHandler("onPlayerWeaponSwitch", getRootElement(), weaponReplace) function removeQuit() if elementWeaponRaplace[source] then detachElementFromBone(elementWeaponRaplace[source]) destroyElement(elementWeaponRaplace[source]) elementWeaponRaplace[source] = false end end addEventHandler("onPlayerQuit",getRootElement(),removeQuit) addEventHandler("onPlayerWasted",getRootElement(),removeQuit) function giveNewWeapon(player,wep) if not player or getElementType(player) ~= "player" then return false end local weapon = getElementData(player, "cweapon") if type(wep) == "string" then giveWeapon(player,31,9999) setElementData(player,"cweapon",wep) return true end end function loadweapon1(account) if account then local source = getAccountPlayer(account) local emp = getElementData ( source, "cweapon" ) or false setAccountData ( account, "cweapon", emp ) end end function loadweapon(account) if not (isGuestAccount (account)) then if (account) then local source = getAccountPlayer(account) local emp = getAccountData ( account, "cweapon" ) or false setElementData ( source, "cweapon", emp ) end end end addEventHandler("onPlayerLogin", root, function( _, acc ) setTimer(loadweapon,50,1,acc) end ) function sair ( quitType ) local acc = getPlayerAccount(source) if not (isGuestAccount (acc)) then if acc then loadweapon1(acc) end end end addEventHandler ( "onPlayerQuit", getRootElement(), sair ) All credits to Furzy. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now