• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
Im making a cod kill confirmed type entity for my gamemode that spawns on player death and you get extra points for grabbing it and it prints something in chat. Entity file: [code] function ENT:Touch( ent ) if ent:IsPlayer() then ent:PS_GivePoints(20) ent:SetHealth( ent:GetMaxHealth() ) self:EmitSound( "items/battery_pickup.wav" ) ent:ChatPrint( "You gained 20 Rupees for collecting " .. victim:Nick() "'s trophy" ) end end [/code] Init: [code]function GM:DoPlayerDeath( victim, attacker, dmginfo ) victim:CreateRagdoll() local trophy = ents.Create( "trophy" ) if ( !IsValid( trophy ) ) then return end trophy:SetModel( "models/Gibs/HGIBS.mdl" ) trophy:SetPos( victim:GetPos() + Vector(0,10,0) ) trophy:Spawn() end[/code] It's probably wishful thinking for it to work that easily, but it cant get the victims name from another file so it returns an error for "victim". How would I fix this?
[QUOTE=Natahster;51732133]Im making a cod kill confirmed type entity for my gamemode that spawns on player death and you get extra points for grabbing it and it prints something in chat. Entity file: [code] function ENT:Touch( ent ) if ent:IsPlayer() then ent:PS_GivePoints(20) ent:SetHealth( ent:GetMaxHealth() ) self:EmitSound( "items/battery_pickup.wav" ) ent:ChatPrint( "You gained 20 Rupees for collecting " .. victim:Nick() "'s trophy" ) end end [/code] Init: [code]function GM:DoPlayerDeath( victim, attacker, dmginfo ) victim:CreateRagdoll() local trophy = ents.Create( "trophy" ) if ( !IsValid( trophy ) ) then return end trophy:SetModel( "models/Gibs/HGIBS.mdl" ) trophy:SetPos( victim:GetPos() + Vector(0,10,0) ) trophy:Spawn() end[/code] It's probably wishful thinking for it to work that easily, but it cant get the victims name from another file so it returns an error for "victim". How would I fix this?[/QUOTE] Add this when the entity is being created. [lua]trophy.victim = victim[/lua] Then access the victim in the entity with self.victim Be aware that the victim may no longer be a valid player when the trophy is picked up, so you might want to just store the victim's name instead of their player object.
How do I stop metropolice/antlion guards from making your screen flash red? I know for a fact there's no HUDShouldDraw element that you can hide it with, because I tried returning false regardless of element, and it still showed.
Is there a way to stop util.Effect from creating damage when used with certain effects, such as "Explosion?"
Im having a problem trying to make the f4 menu [code]-- CLIENT net.Receive("openf4", function() print("opened") local Frame = vgui.Create( "DFrame" ) Frame:SetPos( 5, 5 ) Frame:SetSize( 300, 150 ) Frame:SetTitle( "Name window" ) Frame:SetVisible( true ) Frame:SetDraggable( false ) Frame:ShowCloseButton( true ) Frame:MakePopup() end ) -- SERVER util.AddNetworkString("openf4") function GM:ShowSpare2(ply) print("sent") net.Start("openf4") net.Send(ply) end[/code] any idea?
I set the velocity of my faction so my player to 59.97 and it doesn't play any sound because there is a limit with the footsteps. Like I need velocity 100 that a footstep can get played. How can I change it?
[QUOTE=dx9er;51741094]The problem is not with my function, atleast now. Cleaned it up a little bit. It's just that it can't use "dmginfo" part of my code. My current function is: [code]function nopropdmg(target, dmginfo) -- disabled prop damage if dmginfo:GetDamageType(1) then return false end end hook.Add("EntityTakeDamage", "nopropdmg", nopropdmg)[/code] This is the error I get: [code] [ERROR] addons/propdmg/lua/autorun/server/sv_propdmg.lua:6: attempt to index local 'dmginfo' (a nil value) 1. nopropdmg - addons/propdmg/lua/autorun/server/sv_propdmg.lua:6 2. func - addons/propdmg/lua/autorun/server/sv_propdmg.lua:19 3. unknown - lua/includes/extensions/net.lua:32 [/code][/QUOTE] It's a problem with one of your other addons -- I put that exact code in lua/autorun/server to no errors at all.
[QUOTE=dx9er;51741258]Deleted everything, got the same error. Might aswell just post the whole code since I think there's a problem with it. [code] -- client hook.Add("OnPlayerChat", "togglepropdmg", function(ply, txt) -- command to toggle propdamage txt = string.lower(txt) if ply == LocalPlayer() then if txt == "!propdmg" then print("Sending a toggle command...") net.Start("stogglepropdmg") net.SendToServer() end end end) -- server util.AddNetworkString("stogglepropdmg") local IsPropDmgAllowed = true function nopropdmg(target, dmging) -- disabled prop damage if dmging:GetDamageType(1) then return false end end function togglepropdmg(target, dmginfo) -- toggle when we get the message print("We got it! Toggling prop damage...") if IsPropDmgAllowed == true then -- if prop damage is disabled then we enable it print("PROP DAMAGE ENABLED!") IsPropDmgAllowed = false elseif IsPropDmgAllowed == false then -- if prop damage is enabled we disable it print("PROP DAMAGE DISABLED!") IsPropDmgAllowed = true nopropdmg() end end hook.Add("EntityTakeDamage", "nopropdmg", nopropdmg) net.Receive("stogglepropdmg", togglepropdmg)[/code][/QUOTE] It's because you call nopropdmg() from togglepropdmg with no values passed to it
Hello guys, so im currently making an addon which will need to compare dates, and if 30 days have gone from a specific date i'd need to do some action. I was wondering what would be the best way to save and compare dates? is there any function i should use?
[QUOTE=tzahush;51742472]Hello guys, so im currently making an addon which will need to compare dates, and if 30 days have gone from a specific date i'd need to do some action. I was wondering what would be the best way to save and compare dates? is there any function i should use?[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/os/time]os.time[/url] 30 days in seconds would be 60 * 60 * 24 * 30, or 2592000
[QUOTE=dx9er;51741476]Changed it up, still doesn't work... I give up. No way I can get it to work.[/QUOTE] Is it all in one file? also I should have been more specific, just delete that line. I'll post again soon with corrected code. [editline]28th January 2017[/editline] I have tested the following and it works. It's a single file solution, put it in autorun. Or you can split it to two files again, whatever. Also spend some time reading: [url]http://wiki.garrysmod.org[/url] Always include all the variables in functions for hooks, and use descriptive names. Always use the enumeration names, i.e., DMG_CRUSH instead of 1. I commented it a lot to help you learn. [CODE] -- This is a single file solution if SERVER then -- Only run following code on SERVER util.AddNetworkString("toggle_prop_damage") -- register net messsage name on server local IsPropDmgAllowed = true -- global variable to hold state of prop damage allowance function noPropDamage(ent, dmgInfo) -- This function nullifies damage if prop damage is disabled -- it take 2 arguments, the entity being damaged, and -- a damage info object -- Currently then disable everything from taking crush(prop) damage -- Add a check below to make only players immune from it. -- if ent:IsPlayer() then if not IsPropDmgAllowed then -- check if it's not enabled if dmgInfo:GetDamageType(DMG_CRUSH) then -- check if damage type is crush, always use enums, not magic numbers dmgInfo:SetDamage(0) -- set the amount of damge to 0 end end -- end end function togglePropDamageServer(msgLength, ply) -- function to recieve message from client(player) IsPropDmgAllowed = not IsPropDmgAllowed if IsPropDmgAllowed then -- Check state of prop damage variable, notify player ply:ChatPrint("Prop Damage is ENABLED.") else ply:ChatPrint("Prop Damage is DISABLED.") end end hook.Add("EntityTakeDamage", "no_prop_damage", noPropDamage) -- hook noPropDamage to the EntityTakeDamage event net.Receive("toggle_prop_damage", togglePropDamageServer) -- setup net to recieve message from clients with function togglePropDamage end if CLIENT then -- Only run following code on the client function togglePropDamageClient( ply, txt, teamChat, isDead) -- function to check chat message for trigger txt = string.lower(txt) -- lower case the input for standarization if ply == LocalPlayer() then -- make sure chat if from local player if txt == "!propdmg" then -- check if chat message is the trigger net.Start("toggle_prop_damage") -- Start an message to the server net.SendToServer() -- send empty message to server end end end hook.Add("OnPlayerChat", "toggle_prop_damage", togglePropDamageClient) -- hook togglePropDamage to OnPlayerChat event end [/CODE] Hope this helped.
[QUOTE=Moat;51740895]Is "sent" printing? Have you tried using a hook rather than how you're doing it now? [editline]28th January 2017[/editline] Try adding a hook with [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/GM/PlayerShouldTakeDamage"]GM:PlayerShouldTakeDamage[/URL] and check if the attacker's class is prop_physics or prop_dynamic. (Return false to not allow damage) [editline]28th January 2017[/editline] Have tried using [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/GM/PlayerFootstep"]GM:PlayerFootstep[/URL] to suppress the sound rather than changing their velocity?[/QUOTE] what do you mean by suppress the sound I used PlayerFootstep to change the sound but when I set the velocity to 59.97 it doesn't make any sound only if I start running or yeah something that has a fast velocity.
[QUOTE=Maltech;51714238]is there a way to lock focus onto a specific frame? I have a main DFrame, with a button that pops up a smaller one, and I want the user to only be able to interact with the small one until they close it[/QUOTE] A bit late, but this is what you're looking for: [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/Panel/DoModal"]Panel:DoModal[/URL] Call it on the 'popup' panel. It will limit [B][U]ALL[/U][/B] interactions to that panel though, not just disable the parent's focus.
Would anyone know if a ClientsideModel or a prop_dynamic is more resource intensive? If I for example want to render a hat on a player's head, I could either make a prop_dynamic or a ClientsideModel and parent it to the player.
[QUOTE=Bohnenbaum;51745225]Would anyone know if a ClientsideModel or a prop_dynamic is more resource intensive? If I for example want to render a hat on a player's head, I could either make a prop_dynamic or a ClientsideModel and parent it to the player.[/QUOTE] I would definitely use a CliensideModel for this. The less entities on the server, the better. Be sure to remove it when the player leaves or unequips it(if applicable), or you'll have a memory leak. You can even control the rendering for this yourself clientside(set NoDraw to true, and call DrawModel manually in a PostPlayerDraw hook, that way you can determine PER player if the hat can draw (perhaps for a setting to disable drawing those things?) ).
[QUOTE=Brassx;51745322]I would definitely use a CliensideModel for this. The less entities on the server, the better. Be sure to remove it when the player leaves or unequips it(if applicable), or you'll have a memory leak. You can even control the rendering for this yourself clientside(set NoDraw to true, and call DrawModel manually in a PostPlayerDraw hook, that way you can determine PER player if the hat can draw (perhaps for a setting to disable drawing those things?) ).[/QUOTE] Thanks for the quick answer!
[QUOTE=bigdogmat;51742565][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/os/time]os.time[/url] 30 days in seconds would be 60 * 60 * 24 * 30, or 2592000[/QUOTE] I didn't really understand what it means. it says os.time() returns: " number: Seconds passed since Unix epoch", i might be retarded, but i dont understand what exactly it means.
[QUOTE=tzahush;51745708]I didn't really understand what it means. it says os.time() returns: " number: Seconds passed since Unix epoch", i might be retarded, but i dont understand what exactly it means.[/QUOTE] [url]http://lmgtfy.com/?q=Unix+epoch[/url]
[QUOTE=tzahush;51745708]I didn't really understand what it means. it says os.time() returns: " number: Seconds passed since Unix epoch", i might be retarded, but i dont understand what exactly it means.[/QUOTE] It means number of seconds since 00:00:00, 01 Jan 1970.
[QUOTE=Brassx;51745322]Be sure to remove it when the player leaves or unequips it(if applicable), or you'll have a memory leak. [/QUOTE] Really? Do you have any resources I can look at about why? I thought the garbage collector handled userdata somehow, and when a parent(the player) disconnected, any parented props would be available for garbage collection.
[QUOTE=Apickx;51747818]Really? Do you have any resources I can look at about why? I thought the garbage collector handled userdata somehow, and when a parent(the player) disconnected, any parented props would be available for garbage collection.[/QUOTE] [url]https://github.com/Facepunch/garrysmod-issues/issues/1387[/url] Also on the wiki: [quote] It's important to remove the entity with CSEnt:Remove when it's no longer needed, otherwise it will remain forever due to a bug (link) [/quote] I'm not too sure if directly parenting would resolve it, but it's better safe than sorry, so I'd definitely do checks to see if it exists after a d/c and call Remove on it.
Is it frowned upon to call something like GetGlobalInt in a paint hook? If so, what's an alternative?
[QUOTE=Triple-X;51751857]Is it frowned upon to call something like GetGlobalInt in a paint hook? If so, what's an alternative?[/QUOTE] [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]Proper networking.[/URL]
So basically, making it so when a player spawns props - it'll say how many they've spawned after they've stopped spawning. So basically if a player spawned 20 props, 5 seconds later it'll say "Minty Fresh has spawned 20 props." Upon clicking the "20 props" section of the text, it'll then print a list of the props to console. However, whilst using InsertClickableTextStart/End it just resizes the text and doesn't actually make it clickable. I feel like I might be doing something wrong, halp. [quote=Your Mom][vid]http://puu.sh/tHNJZ/fb43a817a7.webm[/vid][/quote] [code]function chatbox:ActionSignal( action, intent ) if ( action == "TextClicked" ) then if ( intent == "PrintProps" ) then RunConsoleCommand("kill") end end end[/code] However I believe it should be set up correctly... [code]chatbox:InsertClickableTextStart("PrintProps") chatbox:AppendText( args[2].. " props." ) chatbox:InsertClickableTextEnd()[/code]
[QUOTE=Tenrys;51751998][URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]Proper networking.[/URL][/QUOTE] Not true in every situation. With something like round time it's better to set and get a predicted GetGlobalFloat.
[QUOTE=Tenrys;51751998][URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]Proper networking.[/URL][/QUOTE] Well I'm working with an int that needs to be updated on the client every few seconds or so. Sending a net message every time would just have the same effect as SetGlobalInt, no?
[QUOTE=Triple-X;51755792]Well I'm working with an int that needs to be updated on the client every few seconds or so. Sending a net message every time would just have the same effect as SetGlobalInt, no?[/QUOTE] I am guessing that SetGlobalInt is also getting passed by a net, so yes.
[QUOTE=tzahush;51755880]I am guessing that SetGlobalInt is also getting passed by a net, so yes.[/QUOTE] They're passed by usermessages iirc
[QUOTE=code_gs;51755925]They're passed by usermessages iirc[/QUOTE] snip
I need to dock two derma panels vertically on top of each other with an invisible divider between them and I need the top panel to be 75% of the frame's vertical space where the other should take 25%. My initial idea was to use a horizontal divider, but that's draggable and I'm not seeing a panel:SetDraggable() function, so I think that's a no go. How would I approach this?
Sorry, you need to Log In to post a reply to this thread.