![]() |
Classes...
Erm... To think of it, classes are things that could be added to almost most NPCs... I've been scripting for a couple of years (6 to be exact), and well, I just wanted to show some nifty tricks to shorten scripts down (I rather an 100 line script then an 800 one)..
Weapon Key Touches: When firing a weapon put: setarray this.keydown,10; for (i=0;i<10;i++) this.keydown[i] = (i == 4) ? 1 : 0; Then, in the timeout loop, put keys(); then, outside everything, put: function keys(){ for (i=0;i<10;i++) this.keydown[i] = keydown(i) ? this.keydown[i] + 1 : 0; } That's for recording how much time you have a key down (The i == 4 thing is to avoid D being pressed twice in the same second, and thus to close the weapon selction or whatnot, you must release and press it again). Here's another trick... setstring commands,heal,die,unstick me; command = lindexof(#c,commands); if (command == 0) playerhearts = playerfullhearts; if (command == 1) playerhearts = 0; if (command == 2) warpto localstartarea.nw,30,30; Simple tricks like that reduce the ammount of lines, or at least the ammount of space taken (repeatedly using strequals(#c,...)). And it is much more reliable if you want to make some more dimensional commands along those lines... setstring commands,buy,add,remove,withdraw,deposit; tokenize #c; command = lindexof(#t(0),commands); if (command < 1){ // User Commands so-so; } else { // Admin Commands so-so; } That would be pretty useful if you want to make some player-oriented shops, or at least something of the kind. Well.. These are two parts that I find useful right now... I'll tell you more later (I just came back from a party) |
Okay... Here's another decent trick:
If you have a lot more options on your server, but don't want to end up with twenty differant set of varialbes... I'll show you some Binary Convertor and how it could help. For you who doesn't know binary, I'll explain shortly: Binary is a number composed of 0's and 1's... 1111 = 1 + 2 + 4 + 8 = 15 So basically, if you have number 15, and want to put it in binary, you'd have "1111" as number. How would this be useful? Lets say you have 10 possible on and off options, but don't want a string to look like: option=1,0,1,0,0,1,0,1,1,1 you could have it in a nice interger that hackers would have a hard time guessing.. Convert BINARY to DIGIT (incoming: put "binary" string as a binary list ^ As with option) function bintodig(){ for (i=0;i<sarraylen(binary);i++){ value = strtofloat(#I(binary,i)); number = (value == 1) ? number + 2^i : number; } } (outcoming: variable "number") -- (incoming: put variable "number" in) function digtobin(){ num = number; len = 0; for (i=0;len == 0;i++){ len = num < 2^i ? i : 0; } setstring binary,; for (i=(len-1);i>=0;i--){ value = number < 2^i ? 0 : 1; insertstring binary,0,#v(value); number = (number < 2^i) ? number : number - 2^i; } } (output: String List "Binary") ... There... Basically, if you want to test that, you could do this: if (playerchats){ number = #v(strtofloat(#c)); digtobin(); message #s(binary); } ^ if you say "15", it'll give you 1,1,1,1. If you say 16, it'll give you 0,0,0,0,1. And so on... This could shorten your script, however it could also never be placed anywhere at all. Hope this helps someone... :P - Rance Vicious |
Can you please put that in CODE tags?
NPC Code:Like this |
When firing a weapon put:
NPC Code: Then, in the timeout loop, put keys(); then, outside everything, put: NPC Code: NPC Code: NPC Code: \----\ Binary to Digit: NPC Code: Digit to Binary: NPC Code: Want to Test it out? NPC Code: Well... Hope that helps. |
Erm, nice gift. :|
|
nice. i really like the binary functions.
|
The binary ones should have been added to Graal a long time ago, but then again, I don't think much people think in binary anymore... It's a simple reproduction of what it would be in Graal's programming language. Erm...
Ahh... Another trick, that's pretty simple that I see little people use: NPC Code: Whereas that could just be used as: NPC Code: or NPC Code: or NPC Code: There is many ways of doing it... I personally rather the: NPC Code: Think of any other way that goes in one line? - Rance Vicious |
heh, tnx, I think =/
|
You probably posted all of them.
|
Quote:
this.on = 1 - this.on; |
Quote:
|
Ohh.. this.on = 1 - this.on;... Haven't thought of that one! Nice. I don't mind %'s as much... Learnt to like them so much I use it... Seems reliable to me, isn't it? Anyhow, most people don't understand it.
Erm... New things? Ahh... I'll be making some tutorial on string-based weapon system... I made one before, on my forum, however it got deleted ;P - RV |
NPC Code:NPC Code: NPC Code:NPC Code: Just incase you dont understand all that ? : stuff :P |
? :
flag ? True Result : False Result; Like: NPC Code: is the same as: NPC Code: :P For those who doesn't know. Nice technique though Hev... Haven't thought of it like that, but I guess they also work. |
Wow, I am never taking cal.
|
lol... This is old school for me... Damn Math class never taught me something new, so I learnt all this myself. I kinda with I didn't, because now the teacher's threatening me to send me to low math (Even though I have an above average mark) because I speak too much, or listen to her too little. (Talk about Attention Freaks.)
|
Quote:
|
*shifts eyes from left to right to left again*
Erm.. Christmas... Where's my present! :P Merry Christmas People! |
| All times are GMT +2. The time now is 02:31 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.