So I've been trying to make the same weapon (AK-47) have two different skins, depending on what weapon the player has (assigned via setElementData). Here's the code (clientside only):
function onClientPlayerSkinChange()
if getElementData(localPlayer,"currentweapon_1") == "FN FAL" then
weapontxd = engineLoadTXD ("mods/fnfal.txd");
engineImportTXD (weapontxd, 355);
weapondff = engineLoadDFF ("mods/fnfal.dff", 355);
engineReplaceModel (weapondff, 355);
elseif getElementData(localPlayer,"currentweapon_1") == "G36C" then
weapontxd = engineLoadTXD ("mods/g36c.txd");
engineImportTXD (weapontxd, 355);
weapondff = engineLoadDFF ("mods/g36c.dff", 355);
engineReplaceModel (weapondff, 355);
elseif getElementData(localPlayer,"currentweapon_1") == "AK-47" then
engineRestoreModel(355)
else return
end
end
addEventHandler("onClientPlayerWeaponSwitch",localPlayer,onClientPlayerSkinChange)
I can't really tell if the code works...because the game starts to massively lag when switching between weapons, and even though the player has the weapon equipped (checked with getPedWeapon), he doesn't hold it in his hand. Could it be a bug with "onClientPlayerWeaponSwitch"?
Another attempt I made was to do it via a timer...but the character is "spazing" out and you can't properly aim (obviously, because the skin gets changed every X seconds), so that's a failure. I tried to use killTimer, but the skin didn't change at all...though it can be assumed that I did it wrong, somehow.
My question now is: Does anyone have any idea how to let the same weapon have different skins? It doesn't matter if other players perceive the weapon as something entirely different, I just want to know if there is a way.
Also, while we are at it: I assume it is not possible to let skins change "locally" and "globally"? Locally would mean only the client would see the changed skin, while other players would just see a normal/standard weapons, and globally means the skin changes for every player who has the weapon equipped.