![]() |
Zie's Scripting Project
Hello all, I would like to begin by saying I'm learning to script very slowly. I'm currently going through PA school and scripting gives me a break from my current studies. (sounds odd but learning something different lets my mind rest a little) I have a couple of projects that I like to work on whenever I can. I would like input on my scripts so that they are made better and secure, so one day I can put these to use or someone else could learn from or use them.
Thanks, Zie With that said this first script is fairly simple and straight foward, but I think there might be other ways to attempt this script. It is a hat viewer/collector. I made this awhile ago, but now I would like some feedback. PHP Code:
PHP Code:
|
Work on styling and consistency. As a temporary fix you can use this to style your code. For consistency, things like onPlayertouchsme should be onPlayerTouchsMe if you're going to use onActionServerSide.
It also seems like you're using the temp. prefix part of the time and not others. Pick one way and stick with it throughout your script so it's less confusing. As someone who didn't use it except when necessary for years and now does, I'd strongly recommend you use it always. In your long line of playerdir if-statements, you should be using player.dir, player.x, and player.y. Variables like playerdir and playerx are remnants from GS1 and shouldn't be used in new scripts. You can also probably simplify that entire bit with vecx/vecy. PHP Code:
It seems like your script is trying to be part weapon and part NPC. There's no reason to set its image in onCreated since that image is never used. In addition, the onPlayerTouchsMe will never be called in a weapon; that should be moved (along with onCreated) to a level NPC. Also note that you can't change clientr variables on clientside, so you'll have to trigger serverside to change those. This is a bit picky, but onCreated should always be at the top of your script (either the very top or right below //#CLIENTSIDE, depending on which side it's run on). |
Your code indenting/styling is very inconsistent, either use tabs only or spaces only.
A quick glance reveals this error: PHP Code:
Edit: Looks like you already touched on that cbk. You're drawing a hat on 199 but the others on 201, and 202. 199 is a global index so other player's would see that random hat but not the others. You might benefit from learning how to use functions to your advantage so you don't have everything in onKeyPressed. |
Thanks guys!
The first couple of lines should be in a level npc. I just recently was able to get into testbed, and I save scripts that go together all in one text file so I posted without realizing I hadn't moved that piece of the script around. There was an if statement but it wasn't working and just reset my hats back to 0-5 (was wanting some advice on that line about how to check, but I think I can use hasweapon). Next time I post something I'll be sure to make it look better and consistent. I'll play around with vecx and vecy to see if I can come up with some good coordinates that work. Also the 199 global image is intentional so other players can see the hat so if they wanted to trade/buy they could see it and the other player won't have to change his headgear (or could show off his hats). And what do you mean by using functions properly? Could you give me an example? Thanks, Zie |
I picked a bad choice of words before instead of 'use functions properly' I was trying to say 'use functions to your advantage':
PHP Code:
PHP Code:
I.e: In my example above I have the keyboard controls logic in onKeyPressed and my call to doAttack allows me to store all my attacking logic in doAttack. |
Ah I see what you mean, but if you look closely I used two functions that way. The rest of the vars and such. are all different from each button push which is why I didn't find it appropriate to place 3 or 4 different functions. I just changed the vars individually. Also for my created functions do they need to be at the end of the script?
It just makes more sense to put them before they are used, but I'm unsure of the styling or what's appropriate. |
Sorry for the double post. Is there anyway to detect gralats that have been laid, without a custom system? I realize that the player touches the gralat and gets it, but how would another npc detect them?
|
Quote:
PHP Code:
|
All times are GMT +2. The time now is 02:09 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.