Hello I am trying to make an 'armor' system for Nutscript. Alls it does is set your playermodel to something when you equip. When you unequip it, it's supposed to grab the model you picked when making the character and set it back to that. However, I am not sure how to correctly grab the playermodel the user picked when making the character. I am hoping someone else does. Another method would be saving the user's current playermodel and then recalling it when equipped. Below is what I tried:
[CODE]
ITEM.name = "Enchanted Steel Armor Set"
ITEM.desc = "A heavy set of armor worn by great knights that was enchanted by ancient magic. It gives 300 armor when equipped."
ITEM.model = "models/nayrbarr/chest/chest.mdl"
ITEM.width = 3
ITEM.height = 3
ITEM.outfitCategory = "armorset"
ITEM.price = 12000
ITEM:hook("Equip", function(item)
item.player:EmitSound("items/ammo_pickup.wav", 80)
item.player:SetModel("models/humans/oro_knight.mdl")
item.player:SetArmor(0 + 2 * item.player:getChar():getData("Skill_ARMOR", 0) + 600)
item.player:notify("You equipped armor.")
end)
ITEM:hook("Unequip", function(item)
item.player:SetModel(self:getModel())
end)
[/CODE]
The code below this text is taken directly from Nutscript in the meta folder. It's how nutscript sets the default playermodel of a player when they spawn. However, this doesn't work for me when I do it for unequipping for some reason.
[CODE]
-- Sets up the "appearance" related inforomation for the character.
function CHAR:setup(noNetworking)
local client = self:getPlayer()
if (IsValid(client)) then
-- Set the faction, model, and character index for the player.
client:SetModel(self:getModel())
client:SetTeam(self:getFaction())
client:setNetVar("char", self:getID())
-- Apply saved body groups.
for k, v in pairs(self:getData("groups", {})) do
client:SetBodygroup(k, v)
end
-- Apply a saved skin.
client:SetSkin(self:getData("skin", 0))
-- Synchronize the character if we should.
if (!noNetworking) then
self:sync()
for k, v in ipairs(self:getInv(true)) do
v:sync(client)
end
end
hook.Run("CharacterLoaded", self:getID())
-- Close the character menu.
netstream.Start(client, "charLoaded")
self.firstTimeLoaded = true
end
end
[/CODE]
You need to actually define the the previous playermodel WHEN the player equips the item. If you just set the model to getModel(nutscript func?) it's going to grab the players current model.
So, if you make sure the previous model is defined before a new model is set, you can save it for later.
Like this:
[code]
ITEM.name = "Enchanted Steel Armor Set"
ITEM.desc = "A heavy set of armor worn by great knights that was enchanted by ancient magic. It gives 300 armor when equipped."
ITEM.model = "models/nayrbarr/chest/chest.mdl"
ITEM.width = 3
ITEM.height = 3
ITEM.outfitCategory = "armorset"
ITEM.price = 12000
ITEM:hook("Equip", function(item)
item.player.prevmodel = item.player:getModel() --store the player's current model into a value on the player
item.player:EmitSound("items/ammo_pickup.wav", 80)
item.player:SetModel("models/humans/oro_knight.mdl")
item.player:SetArmor(0 + 2 * item.player:getChar():getData("Skill_ARMOR", 0) + 600)
item.player:notify("You equipped armor.")
end)
ITEM:hook("Unequip", function(item)
item.player:SetModel(item.player.prevmodel or item.player:getModel()) --set the player's model to the value we stored earlier when the player equipped the item
item.player.prevmodel = nil --We don't need this anymore.
end)
[/code]
Sorry, you need to Log In to post a reply to this thread.