• Two Questions
    14 replies, posted
First question: How can i make my SWep stop its Timers when the player dies? I dont have any experience using hooks. -solved Second question: How can i make my gun check if CSS ist mountet? My SWep is using the Deagle model, but if the user dont have CSS it should show the HL2 Revolver. Thanks.
1) You have multiple options here: 1) SWEP:OnRemove 2) SWEP:Holster 3) GM:PlayerDeath 2) [url]http://wiki.garrysmod.com/page/engine/GetGames[/url]
1) actually i remove the timers with SWEP:Holster to safely switch weapons while shooting. is this really enough to prevent errors when dying? 2) actually i have no idea how to use this
Are you using timer.Destroy() inside SWEP:Holster ?
Im using timer.Remove()
I'll start by saying i'm not a real pro with sweps. You'll probably want to use timer.Destroy("YourTimer") inside Holster() , OnRemove() and OnDrop() then for your primary or secondary attack start the timer again. [CODE]function SWEP:Holster() /*--------------------------------------------------------- Name: SWEP:Holster() Desc: Weapon wants to holster. Return true to allow the weapon to holster. ---------------------------------------------------------*/ --timer.Destroy("YourTimer") return true end function SWEP:OnRemove() --timer.Destroy("YourTimer") end function SWEP:OnDrop() --timer.Destroy("YourTimer") end[/CODE] Edit: When clicking on timer.Remove() on the wiki, it automatically takes me to timer.Destroy() , I think timer.Remove is outdated and you should use Destroy instead.
Last time I tested SWEP:OnDrop didn't do shit.
I'm sure Robotboy knows his shit, so don't bother with SWEP:OnDrop.
[QUOTE=Winter;42934827]I'll start by saying i'm not a real pro with sweps. You'll probably want to use timer.Destroy("YourTimer") inside Holster() , OnRemove() and OnDrop() then for your primary or secondary attack start the timer again. [CODE]-snip-[/CODE] Edit: When clicking on timer.Remove() on the wiki, it automatically takes me to timer.Destroy() , I think timer.Remove is outdated and you should use Destroy instead.[/QUOTE] when i click on timer.Remove() on the wiki, i go to the timer.Remove page. Which wiki are you using? i already use timer.Remove() in SWEP:Holster(). i'll replace with timer.Destroy() and copy it to SWEP:OnRemove() and SWEP:OnDrop() [QUOTE=Robotboy655;42934878]Last time I tested SWEP:OnDrop didn't do shit.[/QUOTE] Maybe its useful when someone is using the "Drop weapons on death" addon. i dont think its wrong to use it. Im trying to get this SWep completely bug-free
This is where I got the info from. [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexa75a.html[/url] There are better more up to date resources out there like this one. [url]http://wiki.garrysmod.com/page/timer/Remove[/url] My statement about timer.Remove() being out dated may not be correct. ( I checked the updated wiki) Although I cannot distinguish the difference between the two, they both seem to do the same thing.
About question 1: I'll test my things soon. i think it will work. About question 2: I still dont know how to use [QUOTE=Robotboy655;42934425]2) [url]http://wiki.garrysmod.com/page/engine/GetGames[/url][/QUOTE]
Inside your game client do this: [CODE]lua_run_cl PrintTable(engine.GetGames()) [/CODE] You well see table index '2' is counterstrike, so we'll check if it is owned by you by doing this: [CODE]lua_run_cl print(engine.GetGames()[2]["owned"]) [/CODE] It will probably print "true". This is what you'll need to use in your swep: [CODE]if engine.GetGames()[2]["owned"] == true then print("true") else print("false") end[/CODE]
Counter-Strike:Source Realistic weapons does its check this way: [lua] for k,v in pairs(engine.GetGames()) do if v.depot == 240 then if !v.owned then end --CSS is owned if !v.mounted then end --CSS is mounted if !v.installed then end --CSS is installed break end end[/lua] This would be more useful to find out if the player actually has the models available.
Watch out though, I'm pretty sure it will never return false for CS:S on dedicated servers. Or at least it was like that a few months ago. May want to throw in a util.IsValidModel check as well.
Thank you people. I think everything works correctly but sadly, i cant test the Viewmodel now.
Sorry, you need to Log In to post a reply to this thread.