Changing the world model if a player has a set "skin"
2 replies, posted
I have an addon for our server which reskins the crowbar. (Basically strips the normal crowbar and gives another via weapon class)
Now, I also have an addon "Disguised Ak47" which essentially is an ak 47 but the world model is a normal crowbar.
I've been trying to change the world model is a player has a certain crowbar skin because it would give away whether or not the player was a traitor.
Ex: Ply 1 has a katana, buys the disguised ak47, world model is shown as a crowbar, gets killed because he has a custom model.
I put together a crappy code (Well an attempt at least..) I had a little bit of an idea what I was doing but I don't know what I'm doing with it anymore. All I know is, i'm using HasWeapon wrong. I'm only supposed to be receiving a boolean from it.
Help would be appreciated.
[CODE]function SWEP.Initialize(ply)
print( ply:HasWeapon("weapon_katana") )
if ply:HasWeapon("weapon_katana") then
SWEP.WorldModel = "models/weapons/w_katana.mdl"
elseif
ply:HasWeapon("weapon_diamond_pick") then
SWEP.WorldModel = "models/weapons/w_diamond_mc_pickaxe.mdl"
elseif
ply:HasWeapon("weapon_fish") then
SWEP.WorldModel = "models/weapons/w_knife_f.mdl"
elseif
ply:HasWeapon("weapon_light_saber") then
SWEP.WorldModel = "models/weapons/v_crewbar.mdl"
elseif
ply:HasWeapon("weapon_tomahawk") then
SWEP.WorldModel = "models/tiggomods/weapons/ACIII/w_Tomahawk.mdl"
elseif
ply:HasWeapon("weapon_toy_hammer") then
SWEP.WorldModel = "models/weapons/w_knife_ree_toyhammer.mdl"
else
SWEP.WorldModel = "models/weapons/w_crowbar.mdl"
end
end[/CODE]
This code is inside the diguisedak lua file
Obviously I'm using HasWeapon incorrectly as I get a "Nil" error in console.
If it's something too complex forget about it. I'll live without it
Try something like this
[code]
local wepmdltranslate = {
["weapon_katana"] = "models/weapons/w_katana.mdl",
["weapon_diamond_pick"] = "models/weapons/w_diamond_mc_pickaxe.mdl", --etc
}
function SWEP:Initialize() -- Important that you use : here and not .
local ply = self:GetOwner() -- Initialize doesn't give any ply like you specified, instead you have to get ply like this
for class, mdl in pairs(wepmdltranslate) do -- Loop through the table we made earlier
if ply:HasWeapon(class) then -- If the player has this class
self.WorldModel = mdl -- Set the worldmodel to the model, self is the weapon itself here.
break -- We found what we're looking for so don't want to loop anymore.
end
end
end[/code]
However I'm not sure setting WorldModel like this in code will actually make it change, try it.
[QUOTE=Donkie;51567264]Try something like this
[code]
local wepmdltranslate = {
["weapon_katana"] = "models/weapons/w_katana.mdl",
["weapon_diamond_pick"] = "models/weapons/w_diamond_mc_pickaxe.mdl", --etc
}
function SWEP:Initialize() -- Important that you use : here and not .
local ply = self:GetOwner() -- Initialize doesn't give any ply like you specified, instead you have to get ply like this
for class, mdl in pairs(wepmdltranslate) do -- Loop through the table we made earlier
if ply:HasWeapon(class) then -- If the player has this class
self.WorldModel = mdl -- Set the worldmodel to the model, self is the weapon itself here.
break -- We found what we're looking for so don't want to loop anymore.
end
end
end[/code]
However I'm not sure setting WorldModel like this in code will actually make it change, try it.[/QUOTE]
Thank you for the quick reply! It does in fact work, however it only works client side. Other players still see it as a normal crowbar unfortunately
Sorry, you need to Log In to post a reply to this thread.