• Dorkslayz Mini Scripts #1 - Custom Spawn Points
    31 replies, posted
  • Avatar of Dorkslayz
  • 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. [url=http://dorkslayz.info/dl/miniscripts/Dorkslayz%20Mini%20Scripts%20-%20%231%20-%20Custom%20Spawn%20Points.zip]Download[/url] If you have any suggestions, bugs or questions - Let me know.
  • Avatar of Dorkslayz
  • [QUOTE=DrJenkins;34741249]Great to see a [U]good[/U] coder releasing free scripts for the community :)[/QUOTE] I wouldnt call myself a good coder.
  • Avatar of Hugabuga
  • 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?
  • Avatar of Hugabuga
  • I also added some comments, which I hope will explain the stuff I did a bit. It's also tested on Sandbox, and works. [lua] -- 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 ) [/lua] [lua] -- 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 ) [/lua]
  • Avatar of Epinephrine
  • 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.
  • Avatar of Hugabuga
  • 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.
  • Avatar of Dorkslayz
  • 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.
  • Avatar of Hugabuga
  • 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 (;
  • Avatar of Dorkslayz
  • [QUOTE=Persious;34747748]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 (;[/QUOTE] Yeah, thanks. Sometimes I dont code the optimal way.
  • Avatar of lorde banana
  • [QUOTE=Dorkslayz;34747664]however I wont add concommands due to the possibility of it not being suitable to some users and some security issues.[/QUOTE] if you make them correctly then they don't cause "security issues"
  • Avatar of alexanderk
  • [QUOTE=DrogenViech;34749691]Whats with all the dumb ratings the OP got? Am i missing something?[/QUOTE] he's not the most popular fellow in the Lua section
  • Avatar of Drakehawke
  • [QUOTE=DrogenViech;34749691]Whats with all the dumb ratings the OP got? Am i missing something?[/QUOTE] He uses SethHack and likes to devnull servers, garry permabanned him once.
  • Avatar of Hugabuga
  • “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.
  • Avatar of Dorkslayz
  • [QUOTE=Drakehawke;34749834]He uses SethHack and likes to devnull servers, garry permabanned him once.[/QUOTE] 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. [editline]18th February 2012[/editline] [QUOTE=Knallex;34749767]he's not the most popular fellow in the Lua section[/QUOTE] 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.
  • Avatar of Bawbag
  • [QUOTE=Dorkslayz;34753349]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.[/QUOTE] It might be because you half-arsed the script.
  • Avatar of lorde banana
  • [QUOTE=Dorkslayz;34754894]If it works, its fine.[/QUOTE] kontrol worked, so it must be fine granted you could type 1 concommand and get superadmin, but still, it worked!
  • Avatar of Dorkslayz
  • [QUOTE=Banana Lord.;34755400]kontrol worked, so it must be fine granted you could type 1 concommand and get superadmin, but still, it worked![/QUOTE] 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.
  • Avatar of lorde banana
  • [QUOTE=Dorkslayz;34755573]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.[/QUOTE] but if you're learning then you should do things right, not half-ass stuff. you don't learn that way
  • Avatar of Hugabuga
  • 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.
  • [QUOTE=Dorkslayz;34754894]If it works, its fine.[/QUOTE] 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. [editline]18th February 2012[/editline] 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.
  • Avatar of Dorkslayz
  • [QUOTE=hexpunK;34756607]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. [editline]18th February 2012[/editline] 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.[/QUOTE] I have had moments when thinking about things like your example (50 if statements), I just dont know what I can substitute them with.
  • [QUOTE=Dorkslayz;34756704]I have had moments when thinking about things like your example (50 if statements), I just dont know what I can substitute them with.[/QUOTE] 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 [B]or[/B] and [B]and[/B] keywords; [lua] 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 [/lua] 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; [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexe499.html?title=More_tricks_with_conditions[/url] 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.
  • Avatar of Hentie
  • 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.
  • Avatar of Dorkslayz
  • [QUOTE=Hentie;34759563]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.[/QUOTE] Yeah, im ashamed of my past and ive attempted to contribute to the community multiple times ([url=http://www.facepunch.com/threads/1163626]1[/url], [url=http://www.facepunch.com/threads/1164569?p=34759926]2[/url])