Well hi guys again !
As the title says I would like to know how you can do a system with a slider or a button in the clientmenu(the thing that goes in the utilities tab)
To set the weapon to use another texture, like for example instead of having a model of an ak47 with the normal skin you go to the tab and select skin01 you hit apply changes and then your weapon have that new skin.
Hope you guys understand my little explanation.
-bump-
Also I made a little code with help of an example but still nothing can you guys tell me how I could make this work ? :D
[CODE]AddCSLuaFile("autorun/css_shared.lua")
AddCSLuaFile("autorun/client/css_clientmenu.lua")
CreateClientConVar("css_ak47skin", "1", true, true)
NumberToAK47 = {[1] = "weapons/v_models/rif_ak47",
[2] = "weapons/v_models/rif_ak47/v_ak47_b_1111",
[3] = "weapons/v_models/rif_ak47/v_ak47_b_camo1",
[4] = "weapons/v_models/rif_ak47/v_ak47_c_spray1"}
local Ak47Mat, Ak47Mat2, Ak47Mat3, Ak47Mat4 = Material("weapons/v_models/rif_ak47"), Material("weapons/v_models/rif_ak47/v_ak47_b_1111"), Material("weapons/v_models/rif_ak47/v_ak47_b_camo1"), Material("weapons/v_models/rif_ak47/v_ak47_c_spray1")
local function CSS_ApplyRigNow(ply, com, args)
cvar = GetConVarNumber("css_ak47skin")
for k, v in pairs(ply:GetWeapons())
local t = NumberToAK47[GetConVarNumber("css_ak47skin")]
Ak47Mat:SetTexture("$basetexture", t and t or "weapons/v_models/rif_ak47")
Ak47Mat2:SetTexture("$basetexture", t and t or "weapons/v_models/rif_ak47/v_ak47_b_1111")
Ak47Mat3:SetTexture("$basetexture", t and t or "weapons/v_models/rif_ak47/v_ak47_b_camo1")
Ak47Mat4:SetTexture("$basetexture", t and t or "weapons/v_models/rif_ak47/v_ak47_c_spray1")
end
concommand.Add("css_skin_applynow", CSS_ApplyRigNow)[/CODE]
Someone ?
Well, I don't think what you're doing currently works because all you seem to be doing is overriding an IMaterial's texture. This doesn't actually modify the internal texture used by the weapon. I think you have to set the weapon's material once a user equips it (on the actual weapon entity) for this to work
[QUOTE=MPan1;50660834]Well, I don't think what you're doing currently works because all you seem to be doing is overriding an IMaterial's texture. This doesn't actually modify the internal texture used by the weapon. I think you have to set the weapon's material once a user equips it (on the actual weapon entity) for this to work[/QUOTE]
I kinda understand what do you say but I mean: The ak47 use for example rif_ak47 texture and I want to change the texture in game with a button that is in the tab utilities I hit the skin I want for example rif_ak47_camo and I hit apply skin and then I change the $basetexture of the vmt for another.
So that's what I'm trying to do I already made the utilities tab with all the buttons ready to be used but of course I need to know how to do a proper code to use with the buttons
I know what you're trying to do, but I don't think it's possible to override .vmt files using Garry's Mod- I might be wrong though, someone will probably post a way to do it
[QUOTE=MPan1;50661018]I know what you're trying to do, but I don't think it's possible to override .vmt files using Garry's Mod- I might be wrong though, someone will probably post a way to do it[/QUOTE]
The FA:S 2 weapons have that feature where you can change the skin colour and your gloves colour. So it's not impossible since someone already did it
Somebody knows how to do this ?
-bump-
-bump-
At least someone knows how to in function of the cvar change the bodygroup of the current weapon ?
Sorry for not replying sooner, I got your message but I haven't been on Facepunch for a few days. I'll try to make an example of what I was thinking, give me a minute...
[editline]9th July 2016[/editline]
This should work:
[CODE]
hook.Add( 'PlayerSwitchWeapon', 'Example_Hook', function( ply, oldWeapon, newWeapon ) -- This makes the ak47 texture change from the default one when the player switches to it
if IsValid( newWeapon ) and newWeapon:GetClass() == 'ak47' then -- only change the material if it's an ak47 (the class might be different to this though, you'll have to change it)
local texture = NumberToAK47[GetConVarNumber("css_ak47skin")]
newWeapon:SetMaterial( texture, true ) -- change the material
end
end )
[/CODE]
That only makes the texture change when the player has switched to the ak47 though. If you want it to live-update when you run that css_skin_applynow command, something like this might work for you:
[CODE]
local function CSS_ApplyRigNow( ply, command, args, argStr )
local texture = NumberToAK47[GetConVarNumber("css_ak47skin")]
for k,v in pairs( ply:GetWeapons() ) do
if IsValid( v ) and v:GetClass() == 'ak47' then
v:SetMaterial( texture, true ) -- change the material
end
end
end
[/CODE]
Note that with this you still have to have the previous PlayerSwitchWeapon code, because the code above only applies to the set of weapons the player CURRENTLY has, meaning that any new weapons they get later will not update automatically (unless the PlayerSwitchWeapon hook from before exists).
[QUOTE=MPan1;50677311]Sorry for not replying sooner, I got your message but I haven't been on Facepunch for a few days. I'll try to make an example of what I was thinking, give me a minute...
[editline]9th July 2016[/editline]
This should work:
[CODE]
hook.Add( 'PlayerSwitchWeapon', 'Example_Hook', function( ply, oldWeapon, newWeapon ) -- This makes the ak47 texture change from the default one when the player switches to it
if IsValid( newWeapon ) and newWeapon:GetClass() == 'ak47' then -- only change the material if it's an ak47 (the class might be different to this though, you'll have to change it)
local texture = NumberToAK47[GetConVarNumber("css_ak47skin")]
newWeapon:SetMaterial( texture, true ) -- change the material
end
end )
[/CODE]
That only makes the texture change when the player has switched to the ak47 though. If you want it to live-update when you run that css_skin_applynow command, something like this might work for you:
[CODE]
local function CSS_ApplyRigNow( ply, command, args, argStr )
local texture = NumberToAK47[GetConVarNumber("css_ak47skin")]
for k,v in pairs( ply:GetWeapons() ) do
if IsValid( v ) and v:GetClass() == 'ak47' then
v:SetMaterial( texture, true ) -- change the material
end
end
end
[/CODE]
Note that with this you still have to use the previous PlayerSwitchWeapon code, because the code above only applies to the set of weapons the player CURRENTLY has, meaning that any new weapons they get later will not update automatically (unless the PlayerSwitchWeapon hook from before exists).[/QUOTE]
It's okay thanks for the big help :'D
I'll give it a try right now !
By the way, if both of those things from before don't work, just make sure the weapon's class is ak47 and make sure the materials are correct, otherwise I think it'd work
[QUOTE=MPan1;50677412]By the way, if both of those things from before don't work, just make sure the weapon's class is ak47 and make sure the materials are correct, otherwise I think it'd work[/QUOTE]
Did everything like you said looks like this:
[CODE]AddCSLuaFile("autorun/css_shared.lua")
AddCSLuaFile("autorun/client/css_clientmenu.lua")
CreateClientConVar("css_ak47", "1", true, true)
NumberToAK47 = {[1] = "weapons/v_models/rif_ak47",
[2] = "weapons/v_models/rif_ak47/v_ak47_b_1111",
[3] = "weapons/v_models/rif_ak47/v_ak47_b_camo1",
[4] = "weapons/v_models/rif_ak47/v_ak47_c_spray1"}
local function CSS_ApplyRigNow( ply, command, args, argStr )
local texture = NumberToAK47[GetConVarNumber("css_ak47")]
for k,v in pairs( ply:GetWeapons() ) do
if IsValid( v ) and v:GetClass() == 'weapon_cssak47' then
v:SetMaterial( texture, true ) -- change the material
end
end
end
concommand.Add("css_skin_applynow", CSS_ApplyRigNow)
hook.Add( 'PlayerSwitchWeapon', 'Example_Hook', function( ply, oldWeapon, newWeapon ) -- This makes the ak47 texture change from the default one when the player switches to it
if IsValid( newWeapon ) and newWeapon:GetClass() == 'weapon_cssak47' then -- only change the material if it's an ak47 (the class might be different to this though, you'll have to change it)
local texture = NumberToAK47[GetConVarNumber("css_ak47")]
newWeapon:SetMaterial( texture, true ) -- change the material
end
end )[/CODE]
I think it's going to be easier to make bodygroups and just by getting the cvar number change it automatically without having to do a apply texture button like for example
this is an example of the idea [CODE] cvar = GetConVarNumber("css_ak47skin")
self.Owner:SetBodygroup(0, cvar) [/CODE]
With of course the if weapon class is ak47 then do it. But still don't know how to translate this in code
[QUOTE=Xanatos98;50677485]this is an example of the idea [CODE] cvar = GetConVarNumber("css_ak47skin")
self.Owner:SetBodygroup(0, cvar) [/CODE]
With of course the if weapon class is ak47 then do it. But still don't know how to translate this in code[/QUOTE]
Can't you just replace the SetMaterial bits with SetBodygroup instead? Also, are you sure the weapon model has bodygroups for all its skins?
[QUOTE=MPan1;50677522]Can't you just replace the SetMaterial bits with SetBodygroup instead? Also, are you sure the weapon model has bodygroups for all its skins?[/QUOTE]
Yep the model has bodygroups for all its skins it's okay
[CODE]AddCSLuaFile("autorun/css_shared.lua")
AddCSLuaFile("autorun/client/css_clientmenu.lua")
CreateClientConVar("css_ak47", "0", true, true)
local function CSS_ApplySkin( ply, command, args, argStr )
cvar = GetConVarNumber("css_ak47")
for k,v in pairs( ply:GetWeapons() ) do
if IsValid( v ) and v:GetClass() == 'weapon_cssak47' then
v:SetBodygroup( 0, cvar )
end
end
end
end )[/CODE]
Still nothing what i'm doing wrong ? (deleted the other stuff because is not needed)
You forgot to remove the ")" in the end .. and it looks like CSS_ApplySkin never gets called. You need to run the function.
I suggest calling the function in this hook: [url=http://wiki.garrysmod.com/page/GM/PlayerSwitchWeapon]GM:PlayerSwitchWeapon()[/url]
[QUOTE=Nak;50678017]I suggest calling the function in this hook: [url=http://wiki.garrysmod.com/page/GM/PlayerSwitchWeapon]GM:PlayerSwitchWeapon()[/url][/QUOTE]
I already said that before, and that hook wouldn't instantly update like he wants until you switch weapons, so you need both functions (as I said)
[editline]9th July 2016[/editline]
[QUOTE=Xanatos98;50677554]Still nothing what i'm doing wrong ? (deleted the other stuff because is not needed)[/QUOTE]
Are you still actually creating the concommand and using the PlayerSwitchWeapon hook? Both of those are completely needed
[QUOTE=MPan1;50678019]I already said that before, and that hook wouldn't instantly update like he wants until you switch weapons, so you need both functions (as I said)
[editline]9th July 2016[/editline]
Are you still actually creating the concommand and using the PlayerSwitchWeapon hook? Both of those are completely needed[/QUOTE]
[CODE]AddCSLuaFile("autorun/css_shared.lua")
AddCSLuaFile("autorun/client/css_clientmenu.lua")
CreateClientConVar("css_ak47", "0", true, true)
local function CSS_ApplyRigNow( ply, command, args, argStr )
cvar = GetConVarNumber("css_ak47")
for k,v in pairs( ply:GetWeapons() ) do
if IsValid( v ) and v:GetClass() == 'weapon_cssak47' then
v:SetBodygroup( 0, cvar )
end
end
end
concommand.Add("css_skin_applynow", CSS_ApplyRigNow)
hook.Add( 'PlayerSwitchWeapon', 'Example_Hook', function( ply, oldWeapon, newWeapon ) -- This makes the ak47 texture change from the default one when the player switches to it
cvar = GetConVarNumber("css_ak47")
if IsValid( newWeapon ) and newWeapon:GetClass() == 'weapon_cssak47' then -- only change the material if it's an ak47 (the class might be different to this though, you'll have to change it)
newWeapon:SetBodygroup( 0, cvar ) -- change the material
end
end )[/CODE]
I added the code you said but still not working... the function cvar css_skin_applynow is called in the client menu so it's okay the problem still is in here
Try looking at the weapon in third person/using a camera. I forgot to mention that code doesn't change the viewmodel of the weapon, for that you have to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/GetWeaponViewModel]Weapon:GetWeaponViewModel[/url] (I think)
[QUOTE=MPan1;50679076]Try looking at the weapon in third person/using a camera. I forgot to mention that code doesn't change the viewmodel of the weapon, for that you have to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/GetWeaponViewModel]Weapon:GetWeaponViewModel[/url] (I think)[/QUOTE]
At third person there is no bodygroup of course is only for the viewmodel I did
[CODE] local function CSS_ApplyRigNow( ply, command, args, argStr )
cvar = GetConVarNumber("css_akm")
for k,v in pairs( ply:GetWeaponViewModel() ) do
if IsValid( v ) and v:GetClass() == 'weapon_cssak47' then
v:SetBodygroup( 0, cvar )
end
end
end[/CODE]
gives: attempt to call method 'GetWeaponViewModel' (a nil value)
I meant something like this (untested though):
:snip: GetWeaponViewModel returns a string, I didn't notice, hang on...
[QUOTE=MPan1;50679093]I meant something like this (untested though):
:snip: GetWeaponViewModel returns a string, I didn't notice, hang on...[/QUOTE]
It's okay now gives: attempt to index a string value with bad key ('IsValid' is not part of the string library)
Try this, I have no clue if it will work or not but I guess it's worth a shot:
[CODE]
hook.Add( 'OnViewModelChanged', 'Testhook', function( viewmodel, oldmodel, newmodel ) -- run this clientside
if IsValid( viewmodel ) and viewmodel:GetModel() == 'whatever the ak47 model path is' then
viewmodel:SetBodygroup( 0, GetConVarNumber("css_akm") )
end
end )
[/CODE]
That should make the ak47 viewmodel bodygroup change when you switch weapons to it- but I can't seem to think of how to make it update without you having to switch weapons... just see if that works first
Whatever weapon I switch makes:
[CODE]
[ERROR] lua/includes/util.lua:181: attempt to index a string value with bad key ('IsValid' is not part of the string library)
1. error - [C]:-1
2. __index - lua/includes/extensions/string.lua:310
3. IsValid - lua/includes/util.lua:181
4. v - addons/cso2 weapons/lua/autorun/css_shared.lua:19
5. unknown - lua/includes/modules/hook.lua:84
6. SelectWeapon - [C]:-1
7. SwitchToDefaultWeapon - lua/includes/extensions/player.lua:203
8. RunClass - gamemodes/sandbox/gamemode/player_class/player_sandbox.lua:78
9. Call - gamemodes/base/gamemode/player.lua:317
10. PlayerSpawn - gamemodes/base/gamemode/player.lua:274
11. unknown - gamemodes/sandbox/gamemode/init.lua:41
[/CODE]
There is not a way to change the viewmodel bodygroup by getting only the cvar instead of having to do an apply function ? I mean for example in the clientmenu I choose the skin spray and the cvar goes to css_ak47skin "1" so that should be setbodygroup(0, cvar) or in this case (0, 1) and done
Not really need a button to update it or anything
[QUOTE=Xanatos98;50679119]There is not a way to change the viewmodel bodygroup by getting only the cvar instead of having to do an apply function ? I mean for example in the clientmenu I choose the skin spray and the cvar goes to css_ak47skin "1" so that should be setbodygroup(0, cvar) or in this case (0, 1) and done
Not really need a button to update it or anything[/QUOTE]
If it's a custom SWEP then there's a pretty easy way - I bet it's been a custom SWEP this whole time and I've just been leading you into a deeper and deeper hole
[editline]9th July 2016[/editline]
Also, I updated the code I posted before. Again, I didn't notice that the thing I was checking was a string. It should be checking the actual viewmodel now.
[QUOTE=MPan1;50679200]If it's a custom SWEP then there's a pretty easy way - I bet it's been a custom SWEP this whole time and I've just been leading you into a deeper and deeper hole
[editline]9th July 2016[/editline]
Also, I updated the code I posted before. Again, I didn't notice that the thing I was checking was a string. It should be checking the actual viewmodel now.[/QUOTE]
Gives me this error with the new code: [CODE]lua/includes/util.lua:181: attempt to index a string value with bad key ('IsValid' is not part of the string library)
1. error - [C]:-1
2. __index - lua/includes/extensions/string.lua:310
3. IsValid - lua/includes/util.lua:181
4. unknown - addons/cso2 weapons/lua/autorun/css_shared.lua:10
5. unknown - lua/includes/modules/concommand.lua:54
[/CODE]
It's not in the shared.lua of the weapon it's on the shared.lua of the autorun since is a function I want for changing the bodygroups of the weapons by doing the cvar change by the utilities tab
the point is to make in the autorun shared the get cvar and then change bodygroup that would be easier instead of doing all the stuff up there
and only needs to retrieve the cvar number if weapon is ak47 then css_ak47skin cvar , if weapon is m4 then css_m4skin cvar.
Okay, if the weapon is a SWEP that you can edit the SWEP code of, then this might work if you shove it in the SWEP's Think function or something like that:
[CODE]
local vm = self.Owner:GetViewModel() -- get the SWEP's viewmodel
vm:SetBodygroup( 0, GetConVarNumber("css_akm") ) -- update it frequently
[/CODE]
Also, sorry if this was for a SWEP you were fine with editing all along, it's much easier to do it for one of them than it is using the stupid method I posted before.
[QUOTE=MPan1;50689002]Okay, if the weapon is a SWEP that you can edit the SWEP code of, then this might work if you shove it in the SWEP's Think function or something like that:
[CODE]
local vm = self.Owner:GetViewModel() -- get the SWEP's viewmodel
vm:SetBodygroup( 0, GetConVarNumber("css_akm") ) -- update it frequently
[/CODE]
Also, sorry if this was for a SWEP you were fine with editing all along, it's much easier to do it for one of them than it is using the stupid method I posted before.[/QUOTE]
Thank you so much for all your help you're the real man!
Sorry, you need to Log In to post a reply to this thread.