Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-22-2003, 05:07 AM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
Talking 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)
Reply With Quote
  #2  
Old 12-22-2003, 06:36 AM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
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
Reply With Quote
  #3  
Old 12-22-2003, 07:22 AM
ForgottenLegacy ForgottenLegacy is offline
-Backtoscripts-
Join Date: Aug 2003
Location: California
Posts: 289
ForgottenLegacy is on a distinguished road
Send a message via AIM to ForgottenLegacy
Can you please put that in CODE tags?
NPC Code:
Like this

__________________
"The higher you fly, the harder it is to breathe."

[Kaidenn] Maybe I will somehow take control of Lance's body when he isn't looking, have him log onto Kingdoms, update one script, and leave.
[Kaidenn] And leave him exactly where I found him, unchanged and completely unnaware of what just took place the last two minutes.
[GrowlZ] Lance: You might want to lock your bedroom door tonight
Reply With Quote
  #4  
Old 12-22-2003, 07:37 AM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
When firing a weapon put:
NPC Code:

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:

NPC Code:

function keys(){
for (i=0;i<10;i++)
this.keydown[i] = keydown(i) ? this.keydown[i] + 1 : 0;
}



NPC Code:

command = lindexof(#c,commands);
if (command == 0) playerhearts = playerfullhearts;
if (command == 1) playerhearts = 0;
if (command == 2) warpto localstartarea.nw,30,30;


NPC Code:

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;
}



\----\

Binary to Digit:
NPC Code:

function bintodig(){
for (i=0;i<sarraylen(binary);i++){
value = strtofloat(#I(binary,i));
number = (value == 1) ? number + 2^i : number;
}
}



Digit to Binary:
NPC Code:

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;
}
}



Want to Test it out?
NPC Code:

if (playerchats){
number = #v(strtofloat(#c));
digtobin();
message #s(binary);
}

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;
}
}



Well... Hope that helps.
Reply With Quote
  #5  
Old 12-22-2003, 03:20 PM
osrs osrs is offline
Graalian since 1998
osrs's Avatar
Join Date: Mar 2002
Location: Brazil
Posts: 2,724
osrs is on a distinguished road
Send a message via ICQ to osrs Send a message via AIM to osrs Send a message via MSN to osrs Send a message via Yahoo to osrs
Erm, nice gift. :|
__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /
Reply With Quote
  #6  
Old 12-22-2003, 05:30 PM
tlf288 tlf288 is offline
Registered User
tlf288's Avatar
Join Date: Nov 2001
Location: new account: Trevor
Posts: 0
tlf288 is on a distinguished road
Send a message via AIM to tlf288 Send a message via Yahoo to tlf288
nice. i really like the binary functions.
__________________
new account: Trevor
Reply With Quote
  #7  
Old 12-22-2003, 11:32 PM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
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:

if (weaponfired){
if (this.on == 0){
this.on = 1;
timeout = 0.05;
}
if (this.on == 1) this.on = 0;
}



Whereas that could just be used as:
NPC Code:

if (weaponfired){
this.on = (this.on + 1)%2;
timeout = 0.05;
}


or
NPC Code:

if (weaponfired){
this.on = this.on == 0 ? 1 : 0;
timeout = 0.05;
}


or
NPC Code:

if (weaponfired){
this.on = abs(this.on - 1);
timeout = 0.05;
}



There is many ways of doing it... I personally rather the:
NPC Code:

this.on = (this.on + 1)%2;



Think of any other way that goes in one line?

- Rance Vicious
Reply With Quote
  #8  
Old 12-23-2003, 12:22 AM
ZeLpH_MyStiK ZeLpH_MyStiK is offline
Scripter
ZeLpH_MyStiK's Avatar
Join Date: May 2003
Location: NYC
Posts: 553
ZeLpH_MyStiK is on a distinguished road
Send a message via MSN to ZeLpH_MyStiK Send a message via Yahoo to ZeLpH_MyStiK
heh, tnx, I think =/
__________________
Reply With Quote
  #9  
Old 12-23-2003, 01:25 AM
osrs osrs is offline
Graalian since 1998
osrs's Avatar
Join Date: Mar 2002
Location: Brazil
Posts: 2,724
osrs is on a distinguished road
Send a message via ICQ to osrs Send a message via AIM to osrs Send a message via MSN to osrs Send a message via Yahoo to osrs
You probably posted all of them.
__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /
Reply With Quote
  #10  
Old 12-23-2003, 01:33 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally posted by Termina_Owner
stuff
eww, %
this.on = 1 - this.on;
Reply With Quote
  #11  
Old 12-23-2003, 02:01 AM
Lance Lance is offline
dark overlord
Lance's Avatar
Join Date: Sep 2003
Location: Space Jam Mountain
Posts: 5,072
Lance is on a distinguished road
Quote:
Originally posted by Python523


eww, %
this.on = 1 - this.on;
You beat me to it.
Reply With Quote
  #12  
Old 12-23-2003, 10:10 AM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
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
Reply With Quote
  #13  
Old 12-23-2003, 06:53 PM
Hevaricubed Hevaricubed is offline
Registered User
Join Date: Aug 2003
Posts: 262
Hevaricubed is on a distinguished road
Send a message via AIM to Hevaricubed Send a message via Yahoo to Hevaricubed
NPC Code:
NPC Code:

// NPC made by R0bin
if (playerchats&&startswith(dec,#c)) {
tokenize #c;
if (strlen(#t(1)) < 10) {
a=strtofloat(#t(1));
setplayerprop #c,;
message Converting #v(a) into binary!;
sleep 0.5;
setstring d,;
setstring bin,;
b=a;
while (b!=0) {
b=int(a/2);
c=a%2;
setstring d,#v(c)#s(d);
a=b;
}
message #s(d);
} else {
message Want to lag graal?;
}
}




NPC Code:
NPC Code:

if (playerchats&&startswith(bin,#c)) {
setstring str.a,#c;
setplayerprop #c,;
setarray arr.b,strlen(#s(str.a));
message Converting #s(str.a) into decimal!;
sleep 0.5;
arr.b[0] = 1;
for (i=0;i<strlen(#s(str.a));i++;) {
if (i > 0) arr.b[i] = arr.b[i-1]*2;
}
k=strlen(#s(str.a));
for (i=0;i<arraylen(arr.b);i++;) {
k--;
l=strtofloat(#e(k,1,#s(str.a)));
m=l*arr.b[i];
j=j+m;
}
message #v(j);
}




Just incase you dont understand all that

? :

stuff :P
__________________
Reply With Quote
  #14  
Old 12-23-2003, 08:55 PM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
? :


flag ? True Result : False Result;

Like:
NPC Code:

if (playerenters){
a = 1;
if (a == 1){
a = 1;
} else if (a != 1){
a = 2;
}
message #v(a);
}


is the same as:
NPC Code:

if (playerenters){
a = 1;
a = a == 1 ? 1 : 2;
message #v(a);
}



:P For those who doesn't know.

Nice technique though Hev... Haven't thought of it like that, but I guess they also work.
Reply With Quote
  #15  
Old 12-23-2003, 09:15 PM
zell12 zell12 is offline
Gone
zell12's Avatar
Join Date: Jun 2001
Location: Alberta, Canada
Posts: 8,541
zell12 has a spectacular aura about
Send a message via ICQ to zell12 Send a message via AIM to zell12 Send a message via MSN to zell12
Wow, I am never taking cal.
__________________
Reply With Quote
  #16  
Old 12-23-2003, 10:20 PM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
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.)
Reply With Quote
  #17  
Old 12-23-2003, 11:36 PM
Luigi1 Luigi1 is offline
The OtherOther Shaded Leg
Join Date: Jul 2003
Location: In front of a monitor
Posts: 333
Luigi1 is on a distinguished road
Quote:
Originally posted by osrs
Erm, nice gift. :|
It's almost Christmas.
__________________
Quote:
Originally Posted by mystic2k
that post did really makes me think how much braincells you have.
*waits for nifty Graal admin person to tell me what happened to vip.graal.net*
Reply With Quote
  #18  
Old 12-23-2003, 11:51 PM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
*shifts eyes from left to right to left again*

Erm.. Christmas... Where's my present! :P Merry Christmas People!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:56 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.