• My LUA variable wont work in another method?
    2 replies, posted
Hey! Im trying to make a SWEP which switches models. I make a variable in the initialise method named playerModel and set it equal to the current player model when the SWEP initialises. In the primary attack method I change the player model to something random. I then in the secondary attack method make it change the players model to the original model with the variable in the initialisation method. Any ideas? Code: [CODE] function SWEP:Initialize() self:SetWeaponHoldType("normal") if SERVER then playermodel = LocalPlayer():GetModel() end end function SWEP:PrimaryAttack() local trace = self.Owner:GetEyeTrace() if CLIENT then end if SERVER then self.Owner:SetModel("models/player/Group01/male_04.mdl") -- this works fine print(playermodel) end end function SWEP:SecondaryAttack() local trace = self.Owner:GetEyeTrace() if SERVER then self.Owner:SetModel(playermodel) -- this doesnt work at all. end end [/CODE]
You are not updating the variable when you change the model because of this playermodel is just going to stay the same as it was when initialized
Assuming this will work: [lua] function SWEP:Initialize() self:SetWeaponHoldType("normal") end function SWEP:Deploy() local owner = self.Owner self.OOldModel = owner:GetModel() self:SendWeaponAnim(ACT_VM_DRAW) return true end function SWEP:PrimaryAttack() if CLIENT then return end self.Owner:SetModel("models/player/Group01/male_04.mdl") end function SWEP:SecondaryAttack() if CLIENT then return end self.Owner:SetModel(self.OOldModel) end [/lua] I'm not sure who taught you how to indent your lines but they taught you wrong.
Sorry, you need to Log In to post a reply to this thread.