• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
[QUOTE=Vipes;45586800]I'm having a small problem. Don't know if it's because I didn't put it in the right area, or if something is wrong with it. [code]if ( game.GetMap() == "dm_chiron" ) then for k, v in pairs( ents.FindByClass( "weapon_357" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_alyxgun" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_annabelle" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_ar2" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_brickbat" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_bugbait" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_crossbow" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_crowbar" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_frag" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_physcannon" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_pistol" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_rpg" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_shotgun" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_smg1" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_striderbuster" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_stunstick" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "weapon_slam" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_357" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_357_large" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_ar2" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_ar2_altfire" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_ar2_large" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_crate" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_crossbow" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_pistol" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_pistol_large" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_smg1" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_smg1_grenade" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_ammo_smg1_large" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_battery" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_box_buckshot" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_healthcharger" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_healthkit" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_healthvial" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_rpg_round" ) ) do v:Remove() end for k, v in pairs( ents.FindByClass( "item_suitcharger" ) ) do v:Remove() end end[/code] Put in lua/autorun[/QUOTE] Ever heard of tables? Or the fact that instead of doing weapon_name you can do weapon_* ?
How can I check if a string contains Numbers? In this case my string is the value of a DTextEntry Thanks.
[QUOTE=TheDoggy;45588718]How can I check if a string contains Numbers? In this case my string is the value of a DTextEntry Thanks.[/QUOTE] [LUA]("ab1d"):find( "%d" )[/LUA]
[QUOTE=rejax;45589009][LUA]("ab1d"):find( "%d" )[/LUA][/QUOTE] This only seems to detect if there is a number at the start of the string, not if it's at the end or middle?!
[QUOTE=TheDoggy;45589196]This only seems to detect if there is a number at the start of the string, not if it's at the end or middle?![/QUOTE] Seems to work for me: [code] // input print( ( "1bcd" ):find( "%d" ) ) print( ( "a2cd" ):find( "%d" ) ) print( ( "ab3d" ):find( "%d" ) ) print( ( "abc4" ):find( "%d" ) ) // output 1 1 2 2 3 3 4 4 [/code]
[QUOTE=HumbleTH;45589228]Seems to work for me: [/QUOTE] You're right it was working, I was just being special needs: I thought it returned 0 or 1, but it doesn't just return that lol. Thanks
-snip-
If function returns nothing, does it equal false?
[QUOTE=TheMostUpset;45591281]If function returns nothing, does it equal false?[/QUOTE] No, but it will evaluate to false. [code] local value = nil if not value then print("This prints") end if value == false then print("This doesn't") end [/code]
Hello there again! I have come back with edits to my code. So far this is what I see: [LUA] [ERROR] addons/ulx/lua/ulx/modules/sh/givepoints.lua:11: '<eof>' expected near 'end' 1. unknown - addons/ulx/lua/ulx/modules/sh/givepoints.lua:0 [/LUA] Here is my code: [LUA] local CATEGORY_NAME = "Pointshop Commands" function ulx.givepoints( calling_ply, target_plys, should_silent, points ) for i=1, #target_plys do target_plys[ i ]:PS_GivePoints(points) end if points < 0 then ply:ChatPrint("You can't give a negative amount of points") return end ulx.fancyLogAdmin( calling_ply, true, "#A gave #T #i pointshop credits", target_plys, points ) end local givepoints = ulx.command( CATEGORY_NAME, "ulx givepoints", ulx.givepoints, "!givepoints") givepoints:addParam{ type=ULib.cmds.PlayersArg } givepoints:addParam{ type=ULib.cmds.NumArg, hint="Points", ULib.cmds.round } givepoints:setOpposite( "ulx silent givepoints", {_, _, _, true}, "!sgivepoints", true ) givepoints:help( "Gives the <target(s)> Pointshop Points." ) [/LUA] I want to request help. I got alot of drafts of this bit of code because I missed some entries. I feel like its a very simple, but stupid mistake. Please correct me on this. Thanks in advanced.
How to get if a prop is frozen by the physgun? And to an extent freeze it with lua.
[QUOTE=aurum481;45594328]How to get if a prop is frozen by the physgun? And to an extent freeze it with lua.[/QUOTE] [URL="http://wiki.garrysmod.com/page/GM/OnPhysgunFreeze"]GM:OnPhysgunFreeze[/URL] is called when a player freezes a prop with their physgun, if that is what you are looking for. To freeze a prop, you could do [URL="http://wiki.garrysmod.com/page/PhysObj/EnableMotion"][B]ent:GetPhysicsObject():EnableMotion( false )[/B][/URL].
I am trying to make something that unequips/unholsters a gun with the same Slot/Kind in TTT when they equip a new gun. Not sure if there is a PointShop function for this but I haven't found it. [CODE] ITEM.Name = 'Tempest SMG' ITEM.Price = 0 ITEM.Model = 'models/weapons/w_rif_galil.mdl' ITEM.WeaponClass = 'tempest_smg' ITEM.Slot = 3 function ITEM:OnEquip(ply) for k,v in pairs(ply:GetWeapons()) do if(v.Kind == self.Slot) then ply:StripWeapon( v.Gun ) ply:PS_HolsterItem( v.Gun ) end end ply:Give(self.WeaponClass) ply:SelectWeapon(self.WeaponClass) end [/CODE] I can't seem to get PS_HolsterItem to work, it strips the item but does not holster it. Please let me know if there is an easier way to do this or the error in my usage of PS_HolsterItem. I do acknowledge the fact I suck at Lua so there is a large probability that there is a easier way to do this =) EDIT: The ITEM.Slot is because I couldn't find a way to pull the actual weapon slot from the item, so I decided to manually add it to the script to be used on the slot check.
Hmmm, what's going on with http.Fetch? This is my code [code] http.Fetch( "http://steamcommunity.com/profiles/" .. id .. "/games?tab=all&xml=1", -- then my success function, fail function )[/code] Now, everything works if the link doesn't redirect, example being my profile [url]http://steamcommunity.com/profiles/76561198063776439/games?tab=all&xml=1[/url] That gets redirected to [url]http://steamcommunity.com/id/anontakesover/games?tab=all&xml=1&l=english[/url] So, I don't get anything, body is blank, code is 0, len is 0. It's annoying. Anyone got any suggestions? I can't think of a way to get their id either :/.
[QUOTE=AnonTakesOver;45596942]Hmmm, what's going on with http.Fetch? This is my code [code] http.Fetch( "http://steamcommunity.com/profiles/" .. id .. "/games?tab=all&xml=1", -- then my success function, fail function )[/code] Now, everything works if the link doesn't redirect, example being my profile [url]http://steamcommunity.com/profiles/76561198063776439/games?tab=all&xml=1[/url] That gets redirected to [url]http://steamcommunity.com/id/anontakesover/games?tab=all&xml=1&l=english[/url] So, I don't get anything, body is blank, code is 0, len is 0. It's annoying. Anyone got any suggestions? I can't think of a way to get their id either :/.[/QUOTE] [URL=https://developer.valvesoftware.com/wiki/Steam_Web_API#JSON]Why not use the web API? what exactly are you trying to do?[/URL]
[QUOTE=rejax;45597006][URL=https://developer.valvesoftware.com/wiki/Steam_Web_API#JSON]Why not use the web API? what exactly are you trying to do?[/URL][/QUOTE] That should work, cheers.
Is there a method to paint TF2 hats/entities, such as those being used in pointshop? EDIT: I think I can just use the matmaterial from the TF2 painter addon
-snip- I was missing an argument
How do you define the player in a serverside function?! :P Well, can you even do it?
[QUOTE=TheDoggy;45598015]How do you define the player in a serverside function?! :P Well, can you even do it?[/QUOTE] Huh? Explain what you are trying to do?
[QUOTE=AnonTakesOver;45598024]Huh? Explain what you are trying to do?[/QUOTE] Well some code might explain it: [CODE] function GetMoney() local getmoney = db:query("SELECT cash FROM player_data WHERE steam_id ='"..ply:SteamID().."'") //rest of function yadadyayayda [/CODE] But of course gmod be like, 'wtf is ply you haven't defined it fgt' But you can't just add it in the function arguments like you can do with some other gamemode functions. I hope you'll understand this lol
[code]ply =FindMetaTable("Player") function ply:GetMoney() local getmoney = db:query("SELECT cash FROM player_data WHERE steam_id ='"..self:SteamID().."'") //other sh*t end [/code]
[QUOTE=TheDoggy;45598064]Well some code might explain it: [CODE] function GetMoney() local getmoney = db:query("SELECT cash FROM player_data WHERE steam_id ='"..ply:SteamID().."'") //rest of function yadadyayayda [/CODE] But of course gmod be like, 'wtf is ply you haven't defined it fgt' But you can't just add it in the function arguments like you can do with some other gamemode functions. I hope you'll understand this lol[/QUOTE] you can also do this [code] function GetMoney( ply ) local getmoney = db:query("SELECT cash FROM player_data WHERE steam_id ='"..ply:SteamID().."'") //rest of function yadadyayayda [/code] then when you could do this [code] hook.Add( "PlayerInitialSpawn", "swag", function( ply ) GetMoney( ply ) end) [/code] or [code] for k,v in pairs(player.GetAll()) do GetMoney(v) end [/code] you can get the player object through hooks mainly. What frietje2008 is better though.
[QUOTE=baboomerang;45592275]Hello there again! I have come back with edits to my code. So far this is what I see: [LUA] [ERROR] addons/ulx/lua/ulx/modules/sh/givepoints.lua:11: '<eof>' expected near 'end' 1. unknown - addons/ulx/lua/ulx/modules/sh/givepoints.lua:0 [/LUA] [/QUOTE] Your code is fine. Try making a new Lua file and pasting what you gave us back in.
Hmmm not too sure if these are best suited to my needs to be honest. In whole, what I am trying to do is retrieve the money of the player from the db, send it to the client so it can be drawn on their hud. I just can't figure it out yet :/ Thanks anyway though!
[QUOTE=TheDoggy;45598149]Hmmm not too sure if these are best suited to my needs to be honest. In whole, what I am trying to do is retrieve the money of the player from the db, send it to the client so it can be drawn on their hud. I just can't figure it out yet :/ Thanks anyway though![/QUOTE] There's probably 4 parts to this: 1. The function to get the player's money (as seen above) 2. The event/hook where you call the function above 3. The networking part where you send the info you gained from the above 4. The client hud display part where it shows the money Try and do 1 at a time, then combine it to make it work.
[QUOTE=Blasteh;45598173]There's probably 4 parts to this: 1. The function to get the player's money (as seen above) 2. The event/hook where you call the function above 3. The networking part where you send the info you gained from the above 4. The client hud display part where it shows the money Try and do 1 at a time, then combine it to make it work.[/QUOTE] Yeah thats basically what I have got mapped out in my mind, its just getting it right thats the problem at the moment :)
How would i make a realisitic recoil on sweps when i try to use EyeAngles it will fail upon sideways movement(with mouse)[serverside ofc] [LUA] local eyeang = self.Owner:EyeAngles() eyeang.pitch = eyeang.pitch - self.Primary.Recoil self.Owner:SetEyeAngles( eyeang )[/LUA] What hooks could i make use of ?
I haven't had a problem with hooks, but what load order are they in? Where can I see the source code for how hooks work? I'm curious.
[QUOTE=AnonTakesOver;45602961]I haven't had a problem with hooks, but what load order are they in? Where can I see the source code for how hooks work? I'm curious.[/QUOTE] [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/includes/modules/hook.lua[/url] you can't see the loading order directly, but, [code] local ohA = hook.Add function hook.Add( event, uname, func ) local s_uname = tostring(uname) -- ents as uname etc. print(event .. " was hooked by " .. s_uname ) return ohA( event, uname, func ) end [/code]
Sorry, you need to Log In to post a reply to this thread.