• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=YoutoYokodera;52421192]Is the weapon dropped pickup-able / Or how to disable pickup[/QUOTE] You can use this to disable pickup of those weapons: [url]http://wiki.garrysmod.com/page/GM/PlayerCanPickupWeapon[/url]
[QUOTE=YoutoYokodera;52421192]Is the weapon dropped pickup-able / Or how to disable pickup[/QUOTE] Those functions would cause the player to drop their weapon, so yes, unless you disabled the pickup. The best thing to do to accomplish what you're asking for, is when a player is killed, retrieve the model of the weapon they are holding. Then, create a prop and spawn it. You'll have to play with the angles and velocities to make it look realistic so that when they die, the gun falls properly. Otherwise, you have to disable picking up weapons from the ground, which could be problematic if you want players to ever pick up weapons at all. [lua] local gunprop = ents.Create("prop_physics_multiplayer") gunprop:SetModel(your_gun_model) gunprop:SetPos(ply:GetPos()) gunprop:Spawn() local gunphys = gunprop:GetPhysicsObject() gunphys:SetCollisionGroup(--[[pick a collision group]]) gunphys:EnableMotion() [/lua]
[QUOTE=Rory;52421223]Those functions would cause the player to drop their weapon, so yes, unless you disabled the pickup. The best thing to do to accomplish what you're asking for, is when a player is killed, retrieve the model of the weapon they are holding. Then, create a prop and spawn it. You'll have to play with the angles and velocities to make it look realistic so that when they die, the gun falls properly. Otherwise, you have to disable picking up weapons from the ground, which could be problematic if you want players to ever pick up weapons at all. [lua] local gunprop = ents.Create("prop_physics_multiplayer") gunprop:SetModel(your_gun_model) gunprop:SetPos(ply:GetPos()) gunprop:Spawn() local gunphys = gunprop:GetPhysicsObject() gunphys:SetCollisionGroup(--[[pick a collision group]]) gunphys:EnableMotion() [/lua][/QUOTE] I was wondering about the retrieve model part but code_gs told me a better way Tks all
Is it more efficient/cleaner to do: [b]A[/b] [lua] -- Item Function local function InventoryItem(ply, iTable, 1) local iName = iTable[1] local iDesc = iTable[2] local iWeight = iTable[3] local iWeight = iTable[4] if iName == nil then iName = "NAME MISSING" end if iDesc == nil then iDesc = "DESCR MISSING" end if iWeight == nil then iWeight = 0.0 end if iAmount == nil then iAmount = 1 end table.insert(ply.Inventory, new_item) end -- Pickup a Prop and turn it into an inventory item local function PickupItem(ply, key) -- if statements and etc removed, applicable code remains: local iName = ent:GetPropName() local iDesc = ent:GetPropDescription() local iWeight = ent:GetWeight() local iModel = ent:GetModel() local iTable = {[1] = iName, [2] = iDesc, [3] = iWeight, [4] = iModel} InventoryItem(ply, iTable, 1) end [/lua] [b]B[/b] [lua]-- Item Function local function InventoryItem(ply, iName, iDesc, iWeight, iModel, iAmount) if iName == nil then iName = "NAME MISSING" end if iDesc == nil then iDesc = "DESCR MISSING" end if iWeight == nil then iWeight = 0.0 end if iAmount == nil then iAmount = 1 end table.insert(ply.Inventory, new_item) end -- Pickup a Prop and turn it into an inventory item local function PickupItem(ply, key) -- if statements and etc removed, applicable code remains: local iName = ent:GetPropName() local iDesc = ent:GetPropDescription() local iWeight = ent:GetWeight() local iModel = ent:GetModel() InventoryItem(ply, iName, iDesc, iWeight, iModel, 1) end [/lua] Or are they two identical ways to accomplish the same thing..?
[QUOTE=Rory;52422176]Is it more efficient/cleaner to do: [/QUOTE] The best way is to use 'or' when defining them from the table like so: [CODE] local iName = iTable[1] or "NAME MISSING" local iDesc = iTable[2] or "DESCR MISSING" local iWeight = iTable[3] or 0 local iWeight = iTable[4] or 1 [/CODE]
[QUOTE=Rory;52422176]Is it more efficient/cleaner to do: [b]A[/b] [lua] -- Item Function local function InventoryItem(ply, iTable, 1) local iName = iTable[1] local iDesc = iTable[2] local iWeight = iTable[3] local iWeight = iTable[4] if iName == nil then iName = "NAME MISSING" end if iDesc == nil then iDesc = "DESCR MISSING" end if iWeight == nil then iWeight = 0.0 end if iAmount == nil then iAmount = 1 end table.insert(ply.Inventory, new_item) end -- Pickup a Prop and turn it into an inventory item local function PickupItem(ply, key) -- if statements and etc removed, applicable code remains: local iName = ent:GetPropName() local iDesc = ent:GetPropDescription() local iWeight = ent:GetWeight() local iModel = ent:GetModel() local iTable = {[1] = iName, [2] = iDesc, [3] = iWeight, [4] = iModel} InventoryItem(ply, iTable, 1) end [/lua] [b]B[/b] [lua]-- Item Function local function InventoryItem(ply, iName, iDesc, iWeight, iModel, iAmount) if iName == nil then iName = "NAME MISSING" end if iDesc == nil then iDesc = "DESCR MISSING" end if iWeight == nil then iWeight = 0.0 end if iAmount == nil then iAmount = 1 end table.insert(ply.Inventory, new_item) end -- Pickup a Prop and turn it into an inventory item local function PickupItem(ply, key) -- if statements and etc removed, applicable code remains: local iName = ent:GetPropName() local iDesc = ent:GetPropDescription() local iWeight = ent:GetWeight() local iModel = ent:GetModel() InventoryItem(ply, iName, iDesc, iWeight, iModel, 1) end [/lua] Or are they two identical ways to accomplish the same thing..?[/QUOTE] The first one is less efficient as it creates a table, but unless you call this function about a trillion times a second it won't make a difference Also you realize in hungarian notation iVariable means integer?
[QUOTE=Shakes Wilder;52422207]The best way is to use 'or' when defining them from the table like so: [CODE] local iName = iTable[1] or "NAME MISSING" local iDesc = iTable[2] or "DESCR MISSING" local iWeight = iTable[3] or 0 local iWeight = iTable[4] or 1 [/CODE][/QUOTE] Awesome information, thank you! I will switch to that right now. [QUOTE=MeepDarknessM;52422211]The first one is less efficient as it creates a table... ..Also you realize in hungarian notation iVariable means integer?[/QUOTE] I used it because "i" in my case is short for item, so instead of itemName I just did iName. Also, thanks for letting me know it was actually worse to make the table. It seemed cleaner to me but I realized, as you said, it just created a table that wasn't needed.
SetColor does not work for me if I create a Clientside Prop with ents.CreateClientProp or ClientsideModel. Any ideas why?
dumb question but i am trying to ignite player on touch of this entity but it ignites entity it self [lua]function ENT:Touch( entity,activator ) self:Ignite( 30 ) end[/lua]
[QUOTE=Spamppa2;52424951]dumb question but i am trying to ignite player on touch of this entity but it ignites entity it self [lua]function ENT:Touch( entity,activator ) self:Ignite( 30 ) end[/lua][/QUOTE] Because your using self instead of the entity that touched it.
[QUOTE=Sean Bean;52424971]Because your using self instead of the entity that touched it.[/QUOTE] oops how i should fix it then?
[QUOTE=Spamppa2;52424982]oops how i should fix it then?[/QUOTE] [code] function ENT:Touch( entity,activator ) if not IsValid(activator) or not activator:IsPlayer() then return end activator:Ignite( 30 ) end [/code] this can cause lag tho
[QUOTE=Tupac;52425336][code] function ENT:Touch( entity,activator ) if not IsValid(activator) or not activator:IsPlayer() then return end activator:Ignite( 30 ) end [/code] this can cause lag tho[/QUOTE] Use StartTouch instead
-snip-
How do you make an entity's color white? Just setting it to Color(0, 0, 0, 255) makes it the default color of the entity.
Set the material and all sub-materials to fully white ones.
How does one properly shut down a listen server? I'm trying to test something with the ShutDown hook but I can't get it to run when I close the server Also - Could I, theoretically, use Get/SetNWInt with strings? Seems to work when I try it
I need some help "linking" two entities together. The current structure I have is two entities (lets call them A and B) and a main script. The main script will contain a table of all B entities that are paired with entity A. When the use key is pressed on entity A, it should call a function in the main script which should then call a function on all linked B entities. However, I'm unsure of how to get entities to call functions on another script. How would I go about calling a function on the main script from within the entities? I need to do this whenever an A and B entity is created to let the main script "know" about them and also whenever ENT:Use() is ran on A.
[QUOTE=Shorthouse06;52427731]I need some help "linking" two entities together. The current structure I have is two entities (lets call them A and B) and a main script. The main script will contain a table of all B entities that are paired with entity A. When the use key is pressed on entity A, it should call a function in the main script which should then call a function on all linked B entities. However, I'm unsure of how to get entities to call functions on another script. How would I go about calling a function on the main script from within the entities? I need to do this whenever an A and B entity is created to let the main script "know" about them and also whenever ENT:Use() is ran on A.[/QUOTE] Use hook.run to create your own event, and/or use a global table as a namespace. For example, MYADDON.entityIsTouched = true This way you can declare variables in one script, and check/change them in a different one.
[QUOTE=MrRalgoman;52427781]Use hook.run to create your own event, and/or use a global table as a namespace. For example, MYADDON.entityIsTouched = true This way you can declare variables in one script, and check/change them in a different one.[/QUOTE] Thanks for the reply, hooks seem to be exactly what I'm looking for. How do I add custom hook to be run in the main script though, all the examples on the wiki seem to be adding new functions that run with existing hooks. Do I just create a new gamemode hook (e.g. function GM:MyHook() ) ?
[QUOTE=Shorthouse06;52427844]Thanks for the reply, hooks seem to be exactly what I'm looking for. How do I add custom hook to be run in the main script though, all the examples on the wiki seem to be adding new functions that run with existing hooks. Do I just create a new gamemode hook (e.g. function GM:MyHook() ) ?[/QUOTE] You use hook.Add.
[QUOTE=Sean Bean;52427848]You use hook.Add.[/QUOTE] I thought that hook.Add could only be used for adding functions to existing hooks? [CODE]hook.Add( string eventName, any identifier, function func ) [/CODE] The wiki says that eventName is the name of an existing hook and identifier is your own unique identifier. What do I set as the eventName / Identifier if I'm creating a completely new hook?
[CODE]function myFunc() -- do stuff hook.Run("thisJustHappened", args) end -- different file somewhere else hook.Add("thisJustHappened", "doingSomethingElse", function(args) -- do more stuff end) [/CODE]
[QUOTE=MrRalgoman;52427949][CODE]function myFunc() -- do stuff hook.Run("thisJustHappened", args) end -- different file somewhere else hook.Add("thisJustHappened", "doingSomethingElse", function(args) -- do more stuff end) [/CODE][/QUOTE] Thanks mate, that looks perfect. Can the identifier just be set to whatever then so long as it's unique? For a custom hook can I just set it as the same as the eventName to make things easier or will that mess things up?
You should look at the hook module to see how it works. [url]https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/includes/modules/hook.lua[/url] hook.Add adds the events and identifier to a table. hook.Call/Run runs the events added through hook.Add.
What would be faster? Entity:GetSomeNetworkVar() or Entity.dt.SomeNetworkVar I'm guessing this one: Entity.dt.SomeNetworkVar
[QUOTE=EvanCrow;52429409]What would be faster? Entity:GetSomeNetworkVar() or Entity.dt.SomeNetworkVar I'm guessing this one: Entity.dt.SomeNetworkVar[/QUOTE] I'm maybe wrong but - what difference would you even want out of this? A micro-micro-micro optimization? I think stick with the function because if in the future if the dt table gets changed, you won't have to change everything to fit it.
[lua] -- This is the example of my tables so you know what I'm doing ply.Inventory Index:1 Name Amount Index:2 Name....etc -- Note that the above is not coded in, rather a representation of what I'm trying to accomplish local function GetTableIndex(findIndex, term) for k,v in pairs(findIndex) do if findIndex[k]["name"] == term then return k end end end net.Receive("ChestDeposit", function(len, ply) local iName = net.ReadString() -- In my test case, this is coming in as "Soda Can" local iCount = net.ReadInt(32) -- In test case, this is coming in as 16 (the amount I have in my inventory) -- Retrieve the indicies where these items exist local index_from = GetTableIndex(ply.Inventory, iName) -- In the test case, this is returning "2" (which is correct) local index_to = GetTableIndex(ply.ChestInventory, ply.Inventory[index_from]["name"]) -- In the test case, returning "1" (which is correct) -- If the TO index exists, we need to add to what's there, not make a new one. local exists = false if index_to ~= nil then exists = true end if exists then -- In the test case, this returns TRUE, as it should be. print(iCount) -- Verify the count coming in ply.Inventory[index_from]["amount"] = ply.Inventory[index_from]["amount"] - iCount -- The math portion of this is ZERO, but is staying 16 ply.ChestInventory[index_to]["amount"] = ply.ChestInventory[index_to]["amount"] + iCount -- Math is 32, but is staying 16 print("[DEBUG] Depositing into Chest") else table.insert(ply.ChestInventory, ply.Inventory[index_from]) -- This also works but the test case isn't hitting this end -- Anytime an inventory changes, update it with the client(s) (These work, too) net.Start("InvUpdate") net.WriteTable(ply.Inventory) net.Send(ply) net.Start("ChestUpdate") net.WriteTable(ply.ChestInventory) net.Send(ply) end) [/lua] I can't take it anymore. I am at a loss of how to fix this. I've rewritten it 3 times and it still doesn't work. What it's supposed to do is find the item the player wants to deposit into their chest (index_from). Then, it searches to see if that item exists in the chest already (index_to). If it does (exists), then it will be ADDED to the one that is already there, subtracted from the amount the player has in their inventory. [b]What it's ACTUALLY doing:[/b] Nothing. Before I recoded it, it was increasing both the inventory and the chest inventory of the player by the given value. But after rewriting it, now it does nothing. I checked the math by putting the formula under "IF EXISTS THEN", into a PRINT... The math works out perfectly to zero. But when I execute the code, it stays at the currently value in both chests. Originally the problem was that the math would check out to zero, but the items in both the inventory and the chest inventory would double. So if I had 16 soda cans, and tried to put 16 soda cans into the chest, they would both go up to 32, not 0 in the inventory and 32 in the chest like it should. [b][update][/b] I added prints to the IF EXISTS THEN condition, here was the output: [lua] Inventory BEFORE Value: 16 Inventory AFTER Value: 0 Chest Inventory BEFORE Value: 0 Chest Inventory AFTER Value: 16 [/lua] The problem is that the values are both 16 to start with. [b][update][/b] If I stop doing math, and just make the ChestInventory swap with the Inventory, it works perfectly fine. It's removed from the Inventory and placed in the Chest, and no longer exists in the player's inventory... The problem is that I need to be able to dictate the amount they can put away.... They might not want 500 of them on them, and only put 200 of them in the chest. [b][final update][/b] I rewrote this as a stupidly simple function that just used "concommand.Add" with fake tables that I set up and preset values... It worked just fine. Something is wrong with my function above.
How do I make sure a specific lua file is loaded before other addons?
[QUOTE=PigeonTroll;52429669]How do I make sure a specific lua file is loaded before other addons?[/QUOTE] Make a single Lua file in lua/autorun, and have it load the addons from a different folder.
Sorry, you need to Log In to post a reply to this thread.