1. Post #481
    Anthos's Avatar
    April 2012
    153 Posts
    local dmginfo = DamageInfo();
    		dmginfo:SetDamage(20);
    		dmginfo:SetDamageType( DMG_BULLET );
    		dmginfo:SetAttacker(myself.Owner);
    		dmginfo:SetDamageForce(PropEntity:GetPhysicsObject():GetVelocity() * 1000);
    
    Target:TakeDamageInfo(dmginfo);
    

    I'm trying to make Target bounce away from PropEntity by passing PropEntity's velocity to it, but SetDamageForce doesn't seem to be doing anything. Anyone have a clue?
    Reply With Quote Edit / Delete Windows XP Netherlands Show Events

  2. Post #482
    Juze's Avatar
    November 2011
    57 Posts
    if GAMEMODE.Name != "The Stalker" then
        if SERVER then
            include stuff
        end
    end

    I'm trying to disable an addon if specific gamemode (The Stalker) is being played. However, the addon is loaded before the gamemode, and hence prints nil or runs the script anyway. Can't figure a way to post init it. Any help?

    EDIT: This is in the addon's autorun lua.
    EDIT2: Partly solved by cancelling all clientside rendering in client files if the gamemode is on stalker. Would like to still know your solutions.
    EDIT3: I gave up, removed PAC2.
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  3. Post #483
    Gold Member
    Sestze's Avatar
    March 2005
    1,062 Posts
    My code's at http://pastebin.com/VtMr33bv

    I'm trying to force players on the server to see an indicator that displays the location of a beacon "entity" for a pseudogamemode.

    It's pretty much the same sort of deal as any given basic esp, but for some reason, I can't get it to hook. Is there an error I'm missing?
    Reply With Quote Edit / Delete Windows 7 Show Events

  4. Post #484
    Sorlag's Avatar
    May 2012
    3 Posts
    I'm not a great lua scripter but I thought it would be easy to get the tool gun to work in the Elevator: Source gamemode.
    Turned out that gamemode doesn't recognize sandbox things like how the tool gun or the menu works.

    What I basically want to do is to copy the entities of Elevator: Source into another map and then use a permaprop tool on them.
    The entities does not work in sandbox so just transfering them into sandbox isn't an alternative, unless someone knows how to make them work in sandbox.

    So are there any easy ways to get the tool gun to work in non-sandbox based gamemodes?
    Egoistically bumping this in order to make people notice it
    inb4 ban
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events Dumb Dumb x 1 (list)

  5. Post #485
    sintwins's Avatar
    November 2009
    712 Posts
    I have been trying to make a DPanel draw ontop of a DList containing SpawnIcons, however whenever I do the icons just get drawn ontop of the panel and I can't seem to figure out how to stop this. Here is a snippet of the code, any help would be appreciated.
    http://pastebin.com/PugzqxFZ
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  6. Post #486
    Facepunch's #1 Huskybutt
    James xX's Avatar
    July 2011
    2,095 Posts
    Egoistically bumping this in order to make people notice it
    inb4 ban
    in the shared file in the first 10 - 20 lines there will be a function called "DeriveGamemode". Change the argument from "base" to sandbox
    Reply With Quote Edit / Delete Windows XP France Show Events

  7. Post #487
    Sorlag's Avatar
    May 2012
    3 Posts
    in the shared file in the first 10 - 20 lines there will be a function called "DeriveGamemode". Change the argument from "base" to sandbox
    Now I feel stupid for not noticing that hahaha! Amazing, thanks a lot!

    EDIT:
    Hm, how do you change the reload time and/or add a reload delay for a SWEP without animation?
    The swep creates an effect on function SWEP:Reload() but since there is no delay it spams the effect and it becomes laggy.
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  8. Post #488
    HeadInjuryGames's Avatar
    April 2010
    273 Posts
    How would I colorize the viewmodel of a SWEP? I'm the developer of Metastrike and I want a visual effect for when your weapon is "overheated" with the Overheating Guns mod.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  9. Post #489
    Gold Member
    TJ062's Avatar
    April 2011
    23 Posts
    MERCHANT_ATTACK = ai_schedule.New("Merchant_Attack")
    MERCHANT_ATTACK:EngTask( "TASK_STOP_MOVING",0 )
    MERCHANT_ATTACK:EngTask( "TASK_FACE_ENEMY",0 )
    MERCHANT_ATTACK:EngTask( "TASK_RANGE_ATTACK1",0 )
    MERCHANT_ATTACK:EngTask( "TASK_ANNOUNCE_ATTACK",0 )
    MERCHANT_ATTACK:EngTask( "TASK_RELOAD",0 )
    

    For some reason the game Crashes because of "TASK_RANGE_ATTACK1" i have no idea why, is it a bug? or is there a workaround?
    Reply With Quote Edit / Delete Windows 7 Czech Republic Show Events

  10. Post #490
    L33T Lau Coder
    Science's Avatar
    April 2011
    1,813 Posts
    So i am trying to fix up base wars but there is a problem, everytime i goto use the drug refinery, gun factory or any of those i get
    [LmaoLlamaBaseWars\gamemode\physables.lua:178] attempt to call method 'CanRefine' (a nil value)
    error.

    function ccSetRefineryMode( ply, cmd, args )
    	if (args[1]==nil || args[2] == nil) then 
    		return 
    	end
    	mode = tostring(args[2])
    	if !ValidEntity(ents.GetByIndex(args[1])) || (mode!="money" && mode!="offense" && mode!="defense" && mode!="weapmod" && mode!="eject" && mode!="uber") then
    		return 
    	end
    	local vault = ents.GetByIndex(args[1])
    	if (vault:GetClass()!="drugfactory" || ply:GetPos():Distance(vault:GetPos())>300) then return end
    	
    	local ref = vault:CanRefine(mode,ply)
    	if (ref==true) then
    		vault:SetMode(mode)
    	else
    		Notify(ply,4,3,ref)
    	end
    	umsg.Start( "killdrugfactorygui", ply );
    		umsg.Short( args[1] )
    	umsg.End()
    end
    concommand.Add( "setrefinerymode", ccSetRefineryMode );
    

    That is the code.
    Because the one you downloaded from dramaunlimited was the one that i never finished.
    It would take less time to rescript the entire gamemode.

    Sorry to disapoint.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Zing Zing x 1 (list)

  11. Post #491
    Gold Member
    Lexic's Avatar
    March 2009
    6,123 Posts
    A while back, Garry added a set of functions that allowed you to always locate a specific entity on the map (Given that Entity() is dependant on MaxPlayers() and usually changes each game.CleanUpMap())

    However, I can't find any info on the backup wiki. Can anyone remember what they were?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  12. Post #492
    Warsheep's Avatar
    June 2008
    183 Posts
    I'm in need of a method of making an entity move to a set of coordinates at a set speed. I've tried using ApplyForceCenter, but I can't seem to find a reliable way to move it. The speed will variate depending on the distance, and some objects will attempt to roll.

    I think this should be enough to describe what I need, but I'll include some other stuff in case it'll be of help.

    The entity should be able to be any kind of model, and there's only need for rotation around yaw(? left and right, not up and down or doing a roll). I've tried using constraint.Keepupright, but I can't get this to work.

    I've got no need for the speed to scale (f.ex. a smooth start, or slow end).

    edit:
    My main problem with applyforcecenter is that I found no clean way to set the speed, and there was really unnecessary ground friction. Something like the Hammer movelinear (I think it was) would be quite ideal. I need no collision, though it'd be nice if one could reduce the speed for a while, and then set the speed up again.
    Reply With Quote Edit / Delete Windows 7 Thailand Show Events

  13. Post #493
    Fantym420's Avatar
    October 2010
    901 Posts
    I'm in need of a method of making an entity move to a set of coordinates at a set speed. I've tried using ApplyForceCenter, but I can't seem to find a reliable way to move it. The speed will variate depending on the distance, and some objects will attempt to roll.

    I think this should be enough to describe what I need, but I'll include some other stuff in case it'll be of help.

    The entity should be able to be any kind of model, and there's only need for rotation around yaw(? left and right, not up and down or doing a roll). I've tried using constraint.Keepupright, but I can't get this to work.

    I've got no need for the speed to scale (f.ex. a smooth start, or slow end).

    edit:
    My main problem with applyforcecenter is that I found no clean way to set the speed, and there was really unnecessary ground friction. Something like the Hammer movelinear (I think it was) would be quite ideal. I need no collision, though it'd be nice if one could reduce the speed for a while, and then set the speed up again.
    Disable gravity on the physics object, set it's position to x units above the ground then set it's velocity instead of applying force. Have a timer to check when it's near it's destination and stop it or simply lerp it from one point to the other, from the sound of things you should probably lerp it.


    and now for some untested written in browser code:

    function lerpObject(obj, objDest, objStart, timeToDest, lerpStartTime)
    
    
    	if obj and ValidEntity(obj) then
    		
    		if !objDest then return end
    		if !objStart then objStart = obj:GetPos() + Vector(0,0,10) end
    		if !timeToDest then timeToDest = 2 end
    		if !lerpStartTime then lerpStartTime = CurTime() end
    		
    		local lerpDelta = CurTime() - lerpStartTime	
    		
    		lerpPerc = math.Clamp(lerpDelta / timeToDest, 0, 1)
    		
    		local objPhys = obj:GetPhysicsObject()
    		
    		if objPhys and objPhys:IsValid() then
    			
    			if lerpPerc < 1 then
    				objPhys:EnableGravity(false)
    			else
    				objPhys:EnableGravity(true)
    			end
    			
    		end
    		
    		obj:SetPos(LerpVector(lerpPerc, objStart, objDest))
    	
    		if lerpPerc < 1 then 
    			timer.Simple(0.1, lerpObject, obj, objDest, objStart, timeToDest, lerpStartTime)
    		end
    		
    	end
    	
    end
    
    the idea is that because it loops with a timer you run this on multiple things at a time and each will finish after x time, usage:


    lerpObject(myProp, Vector(234,1234,3432), , 2) -- that should move the myProp ent to vector(234,1234, 3432) over 2 seconds time

    hope that works and hope that helps, i'll test/ clean it later if it doesn't work and repost it.

    Edited:

    So just realized that's gonna be jerky only running once every tenth of a second, you can play with the setting till it looks good or you can even add some velocity to the object so it will reach the next point on it's own before the next iteration of the function runs.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Useful Useful x 1 (list)

  14. Post #494
    Warsheep's Avatar
    June 2008
    183 Posts
    Disable gravity on the physics object, set it's position to x units above the ground then set it's velocity instead of applying force. Have a timer to check when it's near it's destination and stop it or simply lerp it from one point to the other, from the sound of things you should probably lerp it.


    and now for some untested written in browser code:

    
    function lerpObject(obj, objDest, objStart, timeToDest, lerpStartTime)
    
    	if obj and ValidEntity(obj) then
    		
    		if !objDest then return end
    		if !objStart then objStart = obj:GetPos() + Vector(0,0,10) end
    		if !timeToDest then timeToDest = 2 end
    		if !lerpStartTime then lerpStartTime = CurTime() end
    		
    		local lerpDelta = CurTime() - lerpStartTime	
    		
    		lerpPerc = math.Clamp(lerpDelta / timeToDest, 0, 1)
    		
    		local objPhys = obj:GetPhysicsObject()
    		
    		if objPhys and objPhys:IsValid() then
    			
    			if lerpPerc < 1 then
    				objPhys:EnableGravity(false)
    			else
    				objPhys:EnableGravity(true)
    			end
    			
    		end
    		
    		obj:SetPos(LerpVector(lerpPerc, objStart, objDest))
    	
    		if lerpPerc < 1 then 
    			timer.Simple(0.1, lerpObject, obj, objDest, objStart, timeToDest, lerpStartTime)
    		end
    		
    	end
    	
    end
    

    the idea is that because it loops with a timer you run this on multiple things at a time and each will finish after x time, usage:


    lerpObject(myProp, Vector(234,1234,3432), , 2) -- that should move the myProp ent to vector(234,1234, 3432) over 2 seconds time

    hope that works and hope that helps, i'll test/ clean it later if it doesn't work and repost it.
    That seems really nice, thanks! :D
    I'll be heading to bed but I'll read over and implement it tomorrow. I think I got a good idea of how it works so I should be able to fix it myself should there be any issues.

    Again, thanks! :)
    Reply With Quote Edit / Delete Windows 7 Thailand Show Events

  15. Post #495
    Title

    August 2009
    301 Posts
    I'm not really sure on File.Read as I've not really used it. However just now I have this:

    local SpecialGuys = {
    	{steamid = "STEAM_0:0:22688997", team = 1, vip = 3},
    	{steamid = "BOT", team = 1, vip = 3},
    	{steamid = "STEAM_0:1:16970247", team = 9, vip = 3},
    }
    

    I'm wanting to change that from a Variable to being stored in a TXT file so I can run a function to read from that file and update the settings. I've gotten this so far and got stuck since I need team=9 etc.

    local function getAdmins()
        if !file.Exists("admins.txt") then return {} end
        return string.Explode(";;", file.Read("tagthinger/admins.txt"))
    end
    
    I'm not sure what to do here.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  16. Post #496
    ASK ME ABOUT MY SAM 6420 FETISH
    ArmageddonScr's Avatar
    July 2011
    691 Posts
    You could always do

    local myTable={"hi","hello"}
     file.Write("mytable.txt",glon.encode(myTable) ) 
    
     local table2=glon.decode(file.Read("mytable.txt")) 
    PrintTable(table2)

    Code:
    Output:
    hi
    hello
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  17. Post #497
    Title

    August 2009
    301 Posts
    You could always do
    local myTable={"hi","hello"}
    file.Write("mytable.txt",glon.encode(myTable) )
    
    local table2=glon.decode(file.Read("mytable.txt"))
    PrintTable(table2)
    
    I still don't understand from that how you would store this {steamid = "STEAM_0:1:16970247", team = 9, vip = 3} in each one of the txt files. Isn't what you posted doing pretty much the same as mine?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  18. Post #498
    wizardsbane's Avatar
    January 2008
    372 Posts
    I still don't understand from that how you would store this {steamid = "STEAM_0:1:16970247", team = 9, vip = 3} in each one of the txt files. Isn't what you posted doing pretty much the same as mine?
    Not the same at all. Full article on GLON: http://maurits.tv/data/garrysmod/wik...on&oldid=51465

    By encoding things, it means you can write objects to a file and read in objects from a file much easier, without having to parse things yourself. It also makes your objects "human readable". (Good reference: http://en.wikipedia.org/wiki/JSON)

    A nice example with a JSON API:
    http://api.tumblr.com/v2/blog/david....MC9ksuGPkK1BTt

    If you bring that output into python or whatever language and use a JSON decoder on it, you'll get a series of objects ready to use. Makes things tons easier.
    Reply With Quote Edit / Delete Windows Vista United States Show Events

  19. Post #499
    Title

    August 2009
    301 Posts
    Not the same at all. Full article on GLON: http://maurits.tv/data/garrysmod/wik...on&oldid=51465

    By encoding things, it means you can write objects to a file and read in objects from a file much easier, without having to parse things yourself. It also makes your objects "human readable". (Good reference: http://en.wikipedia.org/wiki/JSON)

    A nice example with a JSON API:
    http://api.tumblr.com/v2/blog/david....MC9ksuGPkK1BTt

    If you bring that output into python or whatever language and use a JSON decoder on it, you'll get a series of objects ready to use. Makes things tons easier.
    Could I get an example of how I would use that in this situation? I vaguely understand it.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  20. Post #500
    ASK ME ABOUT MY SAM 6420 FETISH
    ArmageddonScr's Avatar
    July 2011
    691 Posts
    You setup your table, encode it and write to a file with that data

    And then you then decode it along with file.Read, modify your new table and then re-encode it to a file.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  21. Post #501
    Title

    August 2009
    301 Posts
    You setup your table, encode it and write to a file with that data

    And then you then decode it along with file.Read, modify your new table and then re-encode it to a file.
    Well what I was preferring to do was Manually edit a TXT file and have a function read from the txt file (into my original function).
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  22. Post #502
    "The superior man understands what is right; the inferior man understands what will sell"
    Chessnut's Avatar
    August 2011
    3,558 Posts
    1. file.Write( blah, util.TableToKeyValues(your table) );
    2. file.Read(blah);
    3. util.KeyValuesToTable(file text)
    Reply With Quote Edit / Delete United States Show Events Agree Agree x 1 (list)

  23. Post #503
    Warsheep's Avatar
    June 2008
    183 Posts
    How should I tell the client to draw an effect, f.ex. an entity shooting?
    Send the event in an usermessage to the client? I'm just wondering because then it seems like I might want to do some syncing stuff.

    edit:
    Also,
    on the server:
    Code:
        umsg.Start(self.Entity:EntIndex() .. PERIODIC, self.Entity:GetOwner())
            umsg.Long = tonumber(self.target:EntIndex()) 
            umsg.Long = self.Energy
            umsg.Long = math.random(1, 10)
        umsg.End()
    and on the client, inside ENT:Initialize (so I can get the entindex)
    Code:
      usermessage.Hook(tostring(self.Entity:EntIndex()) .. PERIODIC, 
        function(data)
          self.Target = data:ReadLong()
          self.Energy = data:ReadLong()
          self.Kills = data:ReadLong()
          print("\nRecieved: ",tostring(self.Target), tostring(self.Energy), tostring(self.Kills))
        end)
    But it doesn't seem like any code is sent. The recieved part prints, but with nil's and 0's. Basically it seems to be sending empty data. The reason I've put this inside of initialize on the client is to be able to use "self.".
    I didn't manage to find a way to call a function such as ENT:Periodic(data), with variations of ENT. and including self as a parameter.

    My goal is to sync some data between the server side and the client side of an entity.
    Reply With Quote Edit / Delete Windows 7 Thailand Show Events

  24. Post #504
    kp3
    Gold Member
    kp3's Avatar
    January 2008
    2,987 Posts
    Might as well try my luck here. Posted in questions but no answer yet. Only been two days but I'm kind of impatient

        for KeyIcon, Model in pairs (ModelList) do
           local Icon = vgui.Create( "Spawnicon" )
            Icon:SetModel( Model )
            Icon:SetToolTip ("Spawn this!")
            Icon.DoClick = function()
                print(Model)
                RunConsoleCommand( "gm_spawn", Model )
            end
            Icon.OnCursorEntered = function()
                Hover[Icon] = true
            end
            Icon.OnCursorExited = function()
                Hover[Icon] = false
            end
            Icon.Paint = function()
                if Hover[Icon] == true then
                    draw.RoundedBox( 8, 0, 0, 64, 64, Color( 100, 0, 0, 200 ) )
                else
                    draw.RoundedBox( 8, 0, 0, 64, 64, Color( 0, 0, 0, 200 ) )
                end
            end
            DermaList:AddItem( Icon )
        end
    
    Icon.OnCursorExited and Entered both work fine. So does Icon.Paint.
    What doesn't work however is DoClick. Nothing happens when I press the icons (no errors either), Yet they get colored red when hovered perfectly fine and if I change the tooltip to "model" it'll display the appropriate model path.

    DoClick simply Isn't working. If I were to create all the icons individually instead of a loop it'd work which doesn't make sense to me.

    What am I missing here?
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  25. Post #505
    Awesome Gmod Servers!
    brandonj4's Avatar
    September 2011
    2,073 Posts
    Might as well try my luck here. Posted in questions but no answer yet. Only been two days but I'm kind of impatient

        for KeyIcon, Model in pairs (ModelList) do
           local Icon = vgui.Create( "Spawnicon" )
            Icon:SetModel( Model )
            Icon:SetToolTip ("Spawn this!")
            Icon.DoClick = function()
                print(Model)
                RunConsoleCommand( "gm_spawn", Model )
            end
            Icon.OnCursorEntered = function()
                Hover[Icon] = true
            end
            Icon.OnCursorExited = function()
                Hover[Icon] = false
            end
            Icon.Paint = function()
                if Hover[Icon] == true then
                    draw.RoundedBox( 8, 0, 0, 64, 64, Color( 100, 0, 0, 200 ) )
                else
                    draw.RoundedBox( 8, 0, 0, 64, 64, Color( 0, 0, 0, 200 ) )
                end
            end
            DermaList:AddItem( Icon )
        end
    
    Icon.OnCursorExited and Entered both work fine. So does Icon.Paint.
    What doesn't work however is DoClick. Nothing happens when I press the icons (no errors either), Yet they get colored red when hovered perfectly fine and if I change the tooltip to "model" it'll display the appropriate model path.

    DoClick simply Isn't working. If I were to create all the icons individually instead of a loop it'd work which doesn't make sense to me.

    What am I missing here?
    Show your ModelList table

    Edit: change
    RunConsoleCommand( "gm_spawn", Model )
    to
    LocalPlayer():ConCommand("gm_spawn "..Model)
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Dumb Dumb x 6Disagree Disagree x 1 (list)

  26. Post #506
    kp3
    Gold Member
    kp3's Avatar
    January 2008
    2,987 Posts
    Show your ModelList table

    Edit: change
    RunConsoleCommand( "gm_spawn", Model )
    to
    LocalPlayer():ConCommand("gm_spawn "..Model)

    ModelList is basically {"path/to/model.bla", "path/to/model2.bla", "path/to/model3.bla"} etc.

    I'll try doing what you said but the fact that I'm not getting the printed message either makes me believe it wont change anything. I'll edit in a minute.

    Edited:

    Didn't work :/ For some reason whatever i put inside DoClick never seems to happen but it's weird as i know DoClick work on spawn-models as I tested it and the other Paint and OnCursorEntered both work inside the loop. This would normally make me believe it's a syntax error or something but I copy and pasted the exact line from already working code so there is no error of that kind. Something in the loop makes DoClick not work properly.
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  27. Post #507
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    I made a function which should allow me to set model of a player depending on his team:

    function AddTeam(ID, Name, Model, Loadout, Salary, Color)
    table.insert(Teams, {ID = ID, Name = Name, Model = Model, Loadout = Loadout, Salary = Salary, Color = Color})
    end
    

    And to return the model I've tried a lot, but never got it working:

    function GM:PlayerSetModel(pl)
    
    	pl:SetModel(Teams[(pl:Team().Model)])
    
    end
    

    This thing gives me
    [gamemodes\Testing\gamemode\server\player.lua:3] attempt to index a number value(Hook: PlayerSetModel)
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  28. Post #508
    Gold Member
    Kogitsune's Avatar
    September 2005
    2,860 Posts
    pl:Team( ) returns the number index of their team, not the table.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  29. Post #509
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    pl:Team( ) returns the number index of their team, not the table.
    Im realy confused, lol.
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events Informative Informative x 1 (list)

  30. Post #510
    Gold Member
    thejjokerr's Avatar
    December 2007
    2,145 Posts
    change
    pl:SetModel(Teams[(pl:Team().Model)])
    to
    pl:SetModel(Teams[pl:Team()].Model)
    Reply With Quote Edit / Delete Windows 7 Netherlands Show Events Agree Agree x 2Friendly Friendly x 1 (list)

  31. Post #511
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    change
    pl:SetModel(Teams[(pl:Team().Model)])
    to
    pl:SetModel(Teams[pl:Team()].Model)
    Ah, thank you.

    Edited:

    Okay, one more question. If the Loadout is a table, how would I go about giving the person all the weapons from there?

    This is to give a single weapon

    pl:Give(Teams[pl:Team()].Loadout)

    - I'm pretty sure that it's a loop, tho I'm bad at thinking.
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  32. Post #512
    Gold Member
    cis.joshb's Avatar
    January 2011
    1,877 Posts
    for k, v in pairs(Teams[pl:Team()].Loadout) do
    ply:Give(v)
    end
    
    EDIT: Didn't tab, written in browser. Also look at dat postcount.

    Edited:

    Is using PData all the time less efficient than assigning ply.Variable = ply:GetPData("Variable") at the beginning and then setting the PData on DC?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  33. Post #513
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    Ah, I'm stupid. Why didn't I think about that. Appreciate a lot!
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  34. Post #514
    kp3
    Gold Member
    kp3's Avatar
    January 2008
    2,987 Posts
    I've seen other people do all kinds of "spawn-list" looking things, Even inventories should be done in some kind of loop. How are other people doing it since my way isn't working?
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  35. Post #515
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    After trying it, it says that the table isn't there

    Code:
    [@gamemodes\test\gamemode\server\player.lua:9] bad argument #1 to 'pairs' (table expected, got nil)(Hook: PlayerLoadout)
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  36. Post #516
    Gold Member
    cis.joshb's Avatar
    January 2011
    1,877 Posts
    Can you do
    function MyConCommand(ply, _, args)
    blah
    end
    
    concommand.Add("blah", MyConCommand)
    
    as in set cmd to _, in the style of setting k to _ in a for loop.
    1k posts.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Winner Winner x 1 (list)

  37. Post #517
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    Same error.

    This is how the table structure looks like:

    Code:
    1:
    		Loadout:
    				1	=	weapon_smg1
    				2	=	weapon_crowbar
    				3	=	weapon_crossbow
    Name	=	Police
    Model	=	models/police.mdl
    ID	=	2
    Color:
    		a	=	255
    		b	=	200
    		g	=	0
    		r	=	0
    Salary	=	50
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  38. Post #518
    Gold Member
    vexx21322's Avatar
    December 2008
    10,660 Posts
    Not exactly lua specific, but more programming specific.
    I remember someone explaining how to get the combined binary flag int and separate all the values. How do I do this?

    I'm talking about the spawnflags valve uses for entities.
    Reply With Quote Edit / Delete United States Show Events

  39. Post #519
    Gold Member
    Lexic's Avatar
    March 2009
    6,123 Posts
    Can you do
    function MyConCommand(ply, _, args)
    blah
    end
    
    concommand.Add("blah", MyConCommand)
    
    as in set cmd to _, in the style of setting k to _ in a for loop.
    1k posts.
    Variable names are non-compulsory. You can name anything whatever you like.
    For instance:
    datastream.Hook(name, function(who, _, _, _, data)
        callback(data, who);
    end);
    _ will be set to the fourth argument's value.
    Reply With Quote Edit / Delete Mac United Kingdom Show Events

  40. Post #520
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    Maybe the error lays in the function:

    
    function AddTeam(ID, Name, Model, Loadout, JoinMessage, Salary, Color)
    table.insert(Teams, {ID = ID, Name = Name, Model = Model, {Loadout = Loadout}, JoinMessage = JoinMessage, Salary = Salary, Color = Color})
    end
    

    Edited:

    Fixed it now. The {Loadout = Loadout} should be Loadout = Loadout
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events