Lawliet Posted April 11, 2014 Posted April 11, 2014 (edited) 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. Edited April 12, 2014 by Guest
Castillo Posted April 12, 2014 Posted April 12, 2014 Try loading the models/textures when the resource starts, then inside the function executed by "onClientPlayerWeaponSwitch", import them.
Lawliet Posted April 12, 2014 Author Posted April 12, 2014 Try loading the models/textures when the resource starts, then inside the function executed by "onClientPlayerWeaponSwitch", import them. Tried that. Now the immense lag is gone - what remains is that the character is still not holding the corresponding weapon. New code (slightly edited): function loadModels() weapontxd1 = engineLoadTXD ("mods/fnfal.txd"); weapondff1 = engineLoadDFF ("mods/fnfal.dff", 0); weapontxd2 = engineLoadTXD ("mods/g36c.txd"); weapondff2 = engineLoadDFF ("mods/g36c.dff", 0); end addEventHandler("onClientResourceStart",root,loadModels) function onClientPlayerSkinChange() if getElementData(localPlayer,"currentweapon_1") == "FN FAL" then engineImportTXD (weapontxd1, 355); engineReplaceModel (weapondff1, 355); elseif getElementData(localPlayer,"currentweapon_1") == "G36C" then engineImportTXD (weapontxd2, 355); engineReplaceModel (weapondff2, 355); elseif getElementData(localPlayer,"currentweapon_1") == "AK-47" then engineRestoreModel(355) else engineRestoreModel(355) end end addEventHandler("onClientPlayerWeaponSwitch",localPlayer,onClientPlayerSkinChange) I can switch the weapon one time, but then, it simply stops. I am only able to use my fists then. Debugscript 3 doesn't output anything either.
Castillo Posted April 12, 2014 Posted April 12, 2014 Maybe "currentweapon_1" data is wrong? try checking what it outputs, like this: outputChatBox ( getElementData ( localPlayer, "currentweapon_1" ) )
-Blaze- Posted December 7, 2014 Posted December 7, 2014 hey , this is a beautiful idea of yours, and i think i found the problem in your code . this should work - 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) you must use an element data so that models don't replace again and again when you switch , and in " weapondff1 = engineLoadDFF ("models/weap/ak47.dff");", the invisibility was 0. That's the reason the models didn't appear.
DropDead41 Posted December 12, 2014 Posted December 12, 2014 hey ,this is a beautiful idea of yours, and i think i found the problem in your code . this should work - 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) you must use an element data so that models don't replace again and again when you switch , and in " weapondff1 = engineLoadDFF ("models/weap/ak47.dff");", the invisibility was 0. That's the reason the models didn't appear. does not work, you do not see the error seems to be all right.
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