1. Post #1
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    Every week, ill release a new Mini Script, whether it be in the form of a Serverside/Gamemode script or a Singleplayer Script.

    This week im releasing a Custom Spawn Point Script, This will allow you to define points (all over the map!) for your players to spawn. At the moment it only supports up to 10 Spawn Points but can be easily modified to have more.

    All install instructions are in the zip file, its not hard to miss.

    This is a gamemode script and ive tested it on sandbox and it works fine; I dont know about any other gamemode though.

    Download

    If you have any suggestions, bugs or questions - Let me know.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Dumb x 15Friendly x 6Winner x 1Optimistic x 1Artistic x 1 (list)

  2. Post #2
    Blue and Proud Of It.
    Dennab
    September 2011
    961 Posts
    Great to see a good coder releasing free scripts for the community :)
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Funny Funny x 10 (list)

  3. Post #3
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    Great to see a good coder releasing free scripts for the community :)
    I wouldnt call myself a good coder.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Agree Agree x 19 (list)

  4. Post #4
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    It's always nice seeing people try accomplishing and learning to code lua. I'm not near being good, but I desided to try and clean the code a bit. And I hope you'll let me post it here, so you can learn from it. (;

    So, do you give me permission to post it here?
    Reply With Quote Edit / Delete Reply Windows 7 Faroe Islands Show Events Friendly Friendly x 1 (list)

  5. Post #5
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    Go ahead.

  6. Post #6
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    I also added some comments, which I hope will explain the stuff I did a bit. It's also tested on Sandbox, and works.

    -- cspawn.lua --
    
    -- Dorkslayz MiniScripts - Custom Spawn
    
    include( 'cspawn_config.lua' )
    
    function SpawnEnt( )
    for _, v in pairs( Spawns ) do -- Instead of having lots of those, which are under us, lets loop through the spawns instead.
        local LocalSpawns = ents.Create( "info_player_cspawn" ) -- We'll create the ent
              LocalSpawns:SetPos( v ) -- Now we'll use the v from the table "Spawns" which is in cspawn_config
              LocalSpawns:Spawn( ) -- Spawn it
              LocalSpawns:Activate( ) -- Activate it
    	end
    end
    hook.Add( "InitPostEntity", "MapSpawn", SpawnEnt )
    
    function PlayerSpawning( pl ) -- I personally never like to hook anything to GM as I usually use hook.Add
    
    local LocalSpawns = { }
          LocalSpawns = ents.FindByClass( "info_player_cspawn" )
    
        if ( table.Count( LocalSpawns ) > 0 ) then return table.Random( LocalSpawns ) end
    end
    hook.Add( "PlayerSelectSpawn", "SpawnSelection", PlayerSpawning )
    

    -- cspawn_config.lua --
    
    -- Dorkslayz MiniScripts - Custom Spawn Config
    
    -- These are the spawn point positions; type getpos in console to get your player position.
      
    Spawns = {}
    
    Spawns[1] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    Spawns[2] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    Spawns[3] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    Spawns[4] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    Spawns[5] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    Spawns[6] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    Spawns[7] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    Spawns[8] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    Spawns[9] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    Spawns[10] 		= 		Vector( -3055.968750, 124.272644, 208.031250 )
    

  7. Post #7
    Epinephrine's Avatar
    March 2010
    79 Posts
    I think it'd be better if they weren't manual added spots like that, and the custom spawn points were stored somewhere so you can change them dynamically.

    Ie, in a txt file or on a sql database.
    Reply With Quote Edit / Delete Reply Windows 7 Anonymous Proxy Show Events Agree Agree x 3 (list)

  8. Post #8
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    Yeah, that's also possible. So you can like type "savespawn" and it'd append to a txt file, which you could string.Explode afterwards to add them.

    But I'm sure he'll get into it sometimes.

  9. Post #9
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    Ill update the OP with your code Persious and ill add come concommands only available to superadmins.

    EDIT - Updated it to Persious's code, however I wont add concommands due to the possibility of it not being suitable to some users and some security issues.

  10. Post #10
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    Do whatever you want, hopefully it helped you. There's still other way easier ways than mine, but I hope you got a point of a loop tho, and how it works (;

  11. Post #11
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    Do whatever you want, hopefully it helped you. There's still other way easier ways than mine, but I hope you got a point of a loop tho, and how it works (;
    Yeah, thanks.

    Sometimes I dont code the optimal way.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Funny Funny x 2 (list)

  12. Post #12
    Gold Banana
    Banana Lord.'s Avatar
    May 2010
    6,847 Posts
    however I wont add concommands due to the possibility of it not being suitable to some users and some security issues.
    if you make them correctly then they don't cause "security issues"
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 3 (list)

  13. Post #13
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    But to prevent security issues, you got to learn (;

  14. Post #14
    Gold Member
    DrogenViech's Avatar
    December 2006
    827 Posts
    Whats with all the dumb ratings the OP got? Am i missing something?

  15. Post #15
    Gold Member
    alexanderk's Avatar
    May 2007
    1,355 Posts
    Whats with all the dumb ratings the OP got? Am i missing something?
    he's not the most popular fellow in the Lua section
    Reply With Quote Edit / Delete Reply Windows 7 Norway Show Events Informative Informative x 1 (list)

  16. Post #16
    PROUD BRONY 4LYFE
    Drakehawke's Avatar
    February 2009
    3,312 Posts
    Whats with all the dumb ratings the OP got? Am i missing something?
    He uses SethHack and likes to devnull servers, garry permabanned him once.
    Reply With Quote Edit / Delete Reply Windows Vista United Kingdom Show Events Agree Agree x 2Informative Informative x 1 (list)

  17. Post #17
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    “Hate is too great a burden to bear. It injures the hater more than it injures the hated.”

    I've got nothing against him personally, until he does something against me. I will gladly help him no matter what, still tho I've also read about him using SethHack which I see no reason to use, which only points to a immature way of gaming.

  18. Post #18
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    He uses SethHack and likes to devnull servers, garry permabanned him once.
    That's a dumb-founded assumption that everybody who own's a copy of sethhack uses it and owns devnull.

    I haven't injected it for months and I dont own devnull.

    Edited:

    he's not the most popular fellow in the Lua section
    Because people are too immature to actually use the rating system properly and rate a user on that post, not on their history or their other posts.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Dumb Dumb x 3Agree Agree x 3Useful Useful x 1Disagree Disagree x 1 (list)

  19. Post #19
    Bawbag's Avatar
    December 2011
    530 Posts
    Because people are too immature to actually use the rating system properly and rate a user on that post, not on their history or their other posts.
    It might be because you half-arsed the script.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Agree Agree x 2Disagree Disagree x 2Zing Zing x 1 (list)

  20. Post #20
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    -snip-
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Dumb Dumb x 11 (list)

  21. Post #21
    Gold Banana
    Banana Lord.'s Avatar
    May 2010
    6,847 Posts
    If it works, its fine.
    kontrol worked, so it must be fine

    granted you could type 1 concommand and get superadmin, but still, it worked!
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Funny Funny x 1 (list)

  22. Post #22
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    kontrol worked, so it must be fine

    granted you could type 1 concommand and get superadmin, but still, it worked!
    What I mean is, its a small script which works fine and is safe and not exploitable and wont damage resource usage if its not optimized.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Dumb Dumb x 2 (list)

  23. Post #23
    Gold Banana
    Banana Lord.'s Avatar
    May 2010
    6,847 Posts
    What I mean is, its a small script which works fine and is safe and not exploitable and wont damage resource usage if its not optimized.
    but if you're learning then you should do things right, not half-ass stuff. you don't learn that way
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 4Lua Helper Lua Helper x 1 (list)

  24. Post #24
    Fight for justice, fight for Manning and Snowden.
    Persious's Avatar
    April 2010
    2,597 Posts
    Just let him be, he'll learn doing it safer and optimize it. It'll come. You can't start doing high-assed code when you start, so just chill.
    Reply With Quote Edit / Delete Reply Windows 7 Faroe Islands Show Events Dumb Dumb x 1 (list)

  25. Post #25
    Gold Member
    hexpunK's Avatar
    August 2008
    15,465 Posts
    If it works, its fine.
    And this is why you'll be a shitty developer. This mindset is the downfall of programmers everywhere. If you think at any point "Hey, it works, it's fine!" then you're not thinking about it right. You need to think of ways to optimise code, save lines, make it more readable for other developers, make it robust and secure. Just because a script doesn't look like it can be exploited, don't assume it won't be. People will find a way.

    When developing you should be constantly criticising your own code, looking at it and thinking "Mayhaps I could use a different control structure instead of 50 if statements?", there will be a point when you yourself cannot see any way to improve the code, then you call another developer in to reaffirm this idea. Having "working" scripts is different from having "good" scripts.

    Edited:

    Basically, just start thinking about your code, get it working, then improve it. Don't just throw it out to the public because it's working and leave it.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Agree Agree x 5 (list)

  26. Post #26
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    And this is why you'll be a shitty developer. This mindset is the downfall of programmers everywhere. If you think at any point "Hey, it works, it's fine!" then you're not thinking about it right. You need to think of ways to optimise code, save lines, make it more readable for other developers, make it robust and secure. Just because a script doesn't look like it can be exploited, don't assume it won't be. People will find a way.

    When developing you should be constantly criticising your own code, looking at it and thinking "Mayhaps I could use a different control structure instead of 50 if statements?", there will be a point when you yourself cannot see any way to improve the code, then you call another developer in to reaffirm this idea. Having "working" scripts is different from having "good" scripts.

    Edited:

    Basically, just start thinking about your code, get it working, then improve it. Don't just throw it out to the public because it's working and leave it.
    I have had moments when thinking about things like your example (50 if statements), I just dont know what I can substitute them with.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Dumb Dumb x 1 (list)

  27. Post #27
    Gold Member
    hexpunK's Avatar
    August 2008
    15,465 Posts
    I have had moments when thinking about things like your example (50 if statements), I just dont know what I can substitute them with.
    Sorry if that last post seemed a bit attacking. Anyhow, depending on how your if statements are structured depends what you can replace them with. For exmaple nested if statements can be compressed into one with or and and keywords;
    if (var1 == true) then
    	if (var2 == false) then
    		if (var3 == 3) then
    			[[Do something here I suppose]]
    		end
            else
    		[[If var2 is true, do what var1 being false would do]]
    	end
    else
    		[[If var1 is false, do something differently]]
    end
    
    [[Becomes]]
    
    if ((var1) and !(var2)) then [[We don't need to equate boolean variables to a value]]
    	if (var3 == 3) then
    		[[Do something]]
    	end
    else
    	[[This should function like the last example]]
    end
    

    There are more things you can do to make a control structure faster, and easier to read. This wiki page actually covers if statements and some ways to adjust them quite nicely to start with;
    http://maurits.tv/data/garrysmod/wik...ith_conditions
    You'll probably find your own preferred methods of doing it as time goes on. It's kind of a shame there's no switch-case structure in Lua, it can be quite useful for comparing one variable to multiple values that perform a different operation each. It's easier to type and nicer to look at in general.

  28. Post #28
    Gold Member
    Hentie's Avatar
    May 2010
    2,129 Posts
    Dorkslayz, fuck the h8erz.

    You made a script that actually works. Given, there are some syntax errors and some newbie errors, but you can always learn from them. Not a lot of people can do what you do.

    As for the people who are so harsh on him; who cares about his past and what he's done. He's trying to contribute to the community now. People grow out of things, you gotta realize that.

    And the "if it works, then it's fine" mentality is completely okay, just make sure you know what you're doing. After that stage of development, you have to think about, "okay now it works, how can I make it work faster?" or "how can I reduce the amount of lines in this code?" Optimization is great, it's the difference between an okay programmer and a great programmer.

    Come on guys, positive reinforcement! Let's go Pavlov on these newbies and classically condition them into being great programmers. The hostility is unneeded.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 4Winner Winner x 1 (list)

  29. Post #29
    Gold Member
    Dorkslayz's Avatar
    September 2009
    1,672 Posts
    Dorkslayz, fuck the h8erz.

    You made a script that actually works. Given, there are some syntax errors and some newbie errors, but you can always learn from them. Not a lot of people can do what you do.

    As for the people who are so harsh on him; who cares about his past and what he's done. He's trying to contribute to the community now. People grow out of things, you gotta realize that.

    And the "if it works, then it's fine" mentality is completely okay, just make sure you know what you're doing. After that stage of development, you have to think about, "okay now it works, how can I make it work faster?" or "how can I reduce the amount of lines in this code?" Optimization is great, it's the difference between an okay programmer and a great programmer.

    Come on guys, positive reinforcement! Let's go Pavlov on these newbies and classically condition them into being great programmers. The hostility is unneeded.
    Yeah, im ashamed of my past and ive attempted to contribute to the community multiple times (1, 2)
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Friendly Friendly x 1 (list)

  30. Post #30

    February 2012
    8 Posts
    this come in handy
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Funny Funny x 1 (list)

  31. Post #31
    I'm a tool
    KillerLUA's Avatar
    June 2009
    1,379 Posts
    A custom spawn system along the line of this?

    local CustomSpawns = {}
    
    if !file.Exists("dorkspawns.txt") then
       file.Write("dorkspawns.txt", glon.encode({}))
    end
    
    --Load spawns
    CustomSpawns = glon.decode(file.Read("dorkspawns.txt")) or {}
    
    --Add a spawn dynamically
    function AddSpawn(pos)
       table.insert(CustomSpawns, pos)
    end
    
    function RemoveSpawn(id)
       CustomSpawns[id] = nil
    end
    
    function SaveSpawns()
       file.Write("dorkspawns.txt", glon.encode(CustomSpawns))
    end
    

    Don't use this without testing, I made it in 3 minutes. I also agree with Percious.
    Reply With Quote Edit / Delete Reply Windows Vista United Kingdom Show Events Friendly Friendly x 1 (list)

  32. Post #32
    Ruzza's Avatar
    December 2011
    1,137 Posts
    A custom spawn system along the line of this?

    local CustomSpawns = {}
    
    if !file.Exists("dorkspawns.txt") then
       file.Write("dorkspawns.txt", glon.encode({}))
    end
    
    --Load spawns
    CustomSpawns = glon.decode(file.Read("dorkspawns.txt")) or {}
    
    --Add a spawn dynamically
    function AddSpawn(pos)
       table.insert(CustomSpawns, pos)
    end
    
    function RemoveSpawn(id)
       CustomSpawns[id] = nil
    end
    
    function SaveSpawns()
       file.Write("dorkspawns.txt", glon.encode(CustomSpawns))
    end
    

    Don't use this without testing, I made it in 3 minutes. I also agree with Percious.
    Why don't you just do

    local CustomSpawns = file.Exists( "dorkspawns.txt" ) and glon.decode( file.Read( "dorkspawns.txt" ) ) or {}