--[[
#---------------------------------------------------------------#
背包与枪械模型显示加载项
#---------------------------------------------------------------#
]]
function rearmPlayerWeapon(weaponName, slot)
takeAllWeapons(source)
local ammoData, weapID = getWeaponAmmoType(weaponName)
if getElementData(source, ammoData) <= 0 then
triggerClientEvent(source, "displayClientInfo", source, "Rearm", shownInfos.nomag, 255, 22, 0)
return
end
setElementData(source, "currentweapon_" .. slot, weaponName)
local weapon = getElementData(source, "currentweapon_1")
if weapon then
local ammoData, weapID = getWeaponAmmoType(weapon)
giveWeapon(source, weapID, getElementData(source, ammoData), false)
end
local weapon = getElementData(source, "currentweapon_2")
if weapon then
local ammoData, weapID = getWeaponAmmoType(weapon)
giveWeapon(source, weapID, getElementData(source, ammoData), false)
end
local weapon = getElementData(source, "currentweapon_3")
if weapon then
local ammoData, weapID = getWeaponAmmoType(weapon)
giveWeapon(source, weapID, getElementData(source, ammoData), false)
end
if elementWeaponRaplace[source] then
detachElementFromBone(elementWeaponRaplace[source])
destroyElement(elementWeaponRaplace[source])
elementWeaponRaplace[source] = false
end
if elementfuWeaponRaplace[source] then
detachElementFromBone(elementfuWeaponRaplace[source])
destroyElement(elementfuWeaponRaplace[source])
elementfuWeaponRaplace[source] = false
end
if elementWeaponBack[source] then
detachElementFromBone(elementWeaponBack[source])
destroyElement(elementWeaponBack[source])
elementWeaponBack[source] = false
end
setElementModel(source, getElementData(source, "skin"))
end
addEvent("onPlayerRearmWeapon", true)
addEventHandler("onPlayerRearmWeapon", getRootElement(), rearmPlayerWeapon)
weaponIDtoObjectID = {
{46, 371},
{45, 369},
{44, 368},
{43, 367},
{42, 365},
{41, 365},
{40, 364},
{39, 363},
{38, 362},
{37, 361},
{36, 360},
{35, 359},
{34, 358},
{33, 357},
{32, 372},
{31, 356},
{30, 355},
{29, 253},
{28, 352},
{27, 351},
{26, 350},
{25, 349},
{24, 348},
{23, 347},
{22, 346},
{18, 344},
{17, 343},
{16, 342},
{15, 326},
{14, 325},
{12, 323},
{11, 322},
{10, 321},
{9, 341},
{8, 339},
{7, 338},
{6, 337},
{5, 336},
{4, 335},
{3, 334},
{2, 333},
{1, 331},
}----------------------直接复制黏贴下面的
function getWeaponObjectID (weaponID)
for i,weaponData in ipairs(weaponIDtoObjectID) do
if weaponID == weaponData[1] then
return weaponData[2]
end
end
end
--------------背包模型
local elementBackpack = {}
function backPackBack (dataName,oldValue)
if getElementType(source) == "player" and dataName =="MAX_Slots" then
local newValue = getElementData(source,dataName)
if elementBackpack[source] then
detachElementFromBone(elementBackpack[source])
destroyElement(elementBackpack[source])
elementBackpack[source] = false
end
local x,y,z = getElementPosition(source)
local rx,ry,rz = getElementRotation(source)
if newValue == 36 then
elementBackpack[source] = createObject(1761,x,y,z)------小包
elseif newValue == 0 then
end
attachElementToBone(elementBackpack[source],source,3,0,-0.225,0.05,90,0,0)
end
end
addEventHandler ( "onElementDataChange", getRootElement(), backPackBack )
function backpackRemoveQuit ()
if elementWeaponRaplace[source] then
detachElementFromBone(elementWeaponRaplace[source])
destroyElement(elementWeaponRaplace[source])
elementWeaponRaplace[source] = false
end
if elementBackpack[source] then
detachElementFromBone(elementBackpack[source])
destroyElement(elementBackpack[source])
end
if elementWeaponBack[source] then
detachElementFromBone(elementWeaponBack[source])
destroyElement(elementWeaponBack[source])
elementWeaponBack[source] = false
end
if elementfuWeaponRaplace[source] then
detachElementFromBone(elementfuWeaponRaplace[source])
destroyElement(elementfuWeaponRaplace[source])
elementfuWeaponRaplace[source] = false
end
end
addEventHandler ( "onPlayerQuit", getRootElement(), backpackRemoveQuit )
------------------------------给予武器一个模型
elementWeaponRaplace = {}
function weaponReplace ( previousWeaponID, currentWeaponID )
local weapon1 = getElementData(source,"currentweapon_1")
if not weapon1 then return end
local ammoData1,weapID1 = getWeaponAmmoType(weapon1)
local x,y,z = getElementPosition(source)
local rx,ry,rz = getElementRotation(source)
if currentWeaponID == weapID1 then
if elementWeaponRaplace[source] then
detachElementFromBone(elementWeaponRaplace[source])
destroyElement(elementWeaponRaplace[source])
elementWeaponRaplace[source] = false
end
if weapon1 == "Double" then
elementWeaponRaplace[source] = createObject(2255,x,y,z)
elseif weapon1 == "Remington" then
elementWeaponRaplace[source] = createObject(2257,x,y,z)
end
attachElementToBone(elementWeaponRaplace[source],source,12,0,0,0,180,116,180)
elseif previousWeaponID == weapID1 then
detachElementFromBone(elementWeaponRaplace[source])
destroyElement(elementWeaponRaplace[source])
elementWeaponRaplace[source] = false
end
end
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponReplace )
elementfuWeaponRaplace = {}
function weaponReplace ( previousWeaponID, currentWeaponID )
local weapon2 = getElementData(source,"currentweapon_2")
local wpn2 = getPedWeapon(source)
if not weapon2 then return end
local ammoData2,weapID2 = getWeaponAmmoType(weapon2)
local x,y,z = getElementPosition(source)
local rx,ry,rz = getElementRotation(source)
if currentWeaponID == weapID2 then
if elementfuWeaponRaplace[source] then
detachElementFromBone(elementfuWeaponRaplace[source])
destroyElement(elementfuWeaponRaplace[source])
elementfuWeaponRaplace[source] = false
end
if weapon2 == "Markarov" then
elementfuWeaponRaplace[source] = createObject(1816,x,y,z)
elseif weapon2 == "M1911" then
elementfuWeaponRaplace[source] = createObject(1817,x,y,z)
-- elseif weapon2 == "M9 Knife" then
-- elementfuWeaponRaplace[source] = createObject(335,x,y,z)
end
attachElementToBone(elementfuWeaponRaplace[source],source,12,0,0,0,180,112,180)
elseif previousWeaponID == weapID2 then
detachElementFromBone(elementfuWeaponRaplace[source])
destroyElement(elementfuWeaponRaplace[source])
elementfuWeaponRaplace[source] = false
end
end
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponReplace )
---------------------------在玩家背后创建一个背枪模型
elementWeaponBack = {}
function weaponSwitchBack ( previousWeaponID, currentWeaponID )
local weapon1 = getElementData(source,"currentweapon_1")
if not weapon1 then return end
local ammoData1,weapID1 = getWeaponAmmoType(weapon1)
local x,y,z = getElementPosition(source)
local rx,ry,rz = getElementRotation(source)
if previousWeaponID == weapID1 then
if elementWeaponBack[source] then
detachElementFromBone(elementWeaponBack[source])
destroyElement(elementWeaponBack[source])
elementWeaponBack[source] = false
end
if weapon1 == "Double" then
elementWeaponBack[source] = createObject(2255,x,y,z)
setObjectScale(elementWeaponBack[source],0.875)
elseif weapon1 == "Remington" then
elementWeaponBack[source] = createObject(2257,x,y,z)
setObjectScale(elementWeaponBack[source],0.875)
else
elementWeaponBack[source] = createObject(getWeaponObjectID(weapID1),x,y,z)
setObjectScale(elementWeaponBack[source],0.875)
end
-- if elementBackpack[source] then
-- attachElementToBone(elementWeaponBack[source],source,3,0.19,-0.31,-0.1,0,270,-90)
-- else
-- attachElementToBone(elementWeaponBack[source],source,3,0.19,-0.11,-0.1,0,270,10)
-- end
attachElementToBone(elementWeaponBack[source],source,3,0.21,-0.12,-0.008,0,270,10)
elseif currentWeaponID == weapID1 then
detachElementFromBone(elementWeaponBack[source])
destroyElement(elementWeaponBack[source])
elementWeaponBack[source] = false
end
end
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitchBack )
function removeBackWeaponOnDrop ()
if elementWeaponRaplace[source] then
detachElementFromBone(elementWeaponRaplace[source])
destroyElement(elementWeaponRaplace[source])
elementWeaponRaplace[source] = false
end
if elementWeaponBack[source] then
detachElementFromBone(elementWeaponBack[source])
destroyElement(elementWeaponBack[source])
elementWeaponBack[source] = false
end
if elementfuWeaponRaplace[source] then
detachElementFromBone(elementfuWeaponRaplace[source])
destroyElement(elementfuWeaponRaplace[source])
elementfuWeaponRaplace[source] = false
end
end
addEvent("removeBackWeaponOnDrop",true)
addEventHandler("removeBackWeaponOnDrop",getRootElement(),removeBackWeaponOnDrop)
function removeAttachedOnDeath ()
if elementWeaponRaplace[source] then
detachElementFromBone(elementWeaponRaplace[source])
destroyElement(elementWeaponRaplace[source])
elementWeaponRaplace[source] = false
end
if elementBackpack[source] then
detachElementFromBone(elementBackpack[source])
destroyElement(elementBackpack[source])
end
if elementWeaponBack[source] then
detachElementFromBone(elementWeaponBack[source])
destroyElement(elementWeaponBack[source])
elementWeaponBack[source] = false
end
if elementfuWeaponRaplace[source] then
detachElementFromBone(elementfuWeaponRaplace[source])
destroyElement(elementfuWeaponRaplace[source])
elementfuWeaponRaplace[source] = false
end
end
addEvent("kilLDayZPlayer",true)
addEventHandler("kilLDayZPlayer",getRootElement(),removeAttachedOnDeath)
------------------删除
function weaponDelete(dataName,oldValue)
if getElementType(source) == "player" then -- check if the element is a player
local weapon1 = getElementData(source,"currentweapon_1")
local weapon2 = getElementData(source,"currentweapon_2")
local weapon3 = getElementData(source,"currentweapon_3")
if dataName == weapon1 or dataName == weapon2 or dataName == weapon3 then
if getElementData (source,dataName) == 0 then
local ammoData,weapID = getWeaponAmmoType(dataName)
takeWeapon (source,weapID)
end
end
local weapon1 = getElementData(source,"currentweapon_1")
local weapon2 = getElementData(source,"currentweapon_2")
local weapon3 = getElementData(source,"currentweapon_3")
local ammoData1,weapID1 = getWeaponAmmoType(weapon1)
local ammoData2,weapID2 = getWeaponAmmoType(weapon2)
local ammoData3,weapID3 = getWeaponAmmoType(weapon3)
if dataName == ammoData1 then
if not oldValue then return end
local newammo = oldValue - getElementData (source,dataName)
if newammo == 1 then return end
if getElementData (source,dataName) < oldValue then
takeWeapon (source,weapID1,newammo)
if elementWeaponBack[source] then
detachElementFromBone(elementWeaponBack[source])
destroyElement(elementWeaponBack[source])
elementWeaponBack[source] = false
end
if elementWeaponRaplace[source] then
detachElementFromBone(elementWeaponRaplace[source])
destroyElement(elementWeaponRaplace[source])
elementWeaponRaplace[source] = false
end
elseif getElementData (source,dataName) > oldValue then
giveWeapon(source,weapID1,getElementData (source,dataName)-oldValue,true)
end
end
if dataName == ammoData2 then
if not oldValue then return end
local newammo = oldValue - getElementData (source,dataName)
if newammo == 1 then return end
if getElementData (source,dataName) < oldValue then
takeWeapon (source,weapID2,newammo)
if elementfuWeaponRaplace[source] then
detachElementFromBone(elementfuWeaponRaplace[source])
destroyElement(elementfuWeaponRaplace[source])
elementfuWeaponRaplace[source] = false
end
elseif getElementData (source,dataName) > oldValue then
giveWeapon(source,weapID2,getElementData (source,dataName)-oldValue,false)
end
end
if dataName == ammoData3 then
if not oldValue then return end
local newammo = oldValue - getElementData (source,dataName)
if newammo == 1 then return end
if getElementData (source,dataName) < oldValue then
takeWeapon (source,weapID3,newammo)
elseif getElementData (source,dataName) > oldValue then
giveWeapon(source,weapID3,getElementData (source,dataName)-oldValue,false)
end
end
end
end
addEventHandler("onElementDataChange",getRootElement(),weaponDelete)
发表评论: