Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Gift: Tile Finder (https://forums.graalonline.com/forums/showthread.php?t=50006)

Goboom 12-30-2003 03:16 AM

Gift: Tile Finder
 
A simple tile finder, press the right and the left keys to scroll through the tiles or chat a number less than 4095 and greater than 0 and you can easily find the tile you need. Script could use some improvements, I will prolly improve it later on.
NPC Code:

if (created){
disabledefmovement;
playerx = x-3;
playery = y-1.5;
timeout = 0.05;
}
if (playerchats){
if (strequals(#c,#c)){
this.tile = strtofloat(#c);
}
}
if (timeout){
updateboard ,,64,64;
if (keydown(1)){
if (this.tile != 0)
this.tile = this.tile-1;
}
if (keydown(3)){
if (this.tile != 4095)
this.tile = this.tile+1;
}
tiles[x,y] = 0x+this.tile;
setplayerprop #c,Tile: 0x#v(this.tile);
timeout = 0.05;
}


MarkB 12-30-2003 03:18 AM

Cool

screen_name 12-30-2003 05:13 AM

Goboom, just curious, but...

Why did you put;

if (strequals(#c,#c)) {

?

Blue_Dragn 12-30-2003 05:33 AM

Quote:

Originally posted by screen_name
Goboom, just curious, but...

Why did you put;

if (strequals(#c,#c)) {

?

I had saw that method used before, not just leaving playerchats alone. I hadnt seen it used in a long time though

ForgottenLegacy 12-30-2003 07:44 AM

*The following is a guess*

I found it easier for styling issues for instead of removing the strequals, (used for debugging a script), you could just leave it in there and replace the second string with whatever the first string was. It's easier than just restyling the whole script by removing that line. (They don't have 'style' buttons online)

Blue_Dragn 12-30-2003 08:33 AM

Quote:

Originally posted by ForgottenLegacy
*The following is a guess*

I found it easier for styling issues for instead of removing the strequals, (used for debugging a script), you could just leave it in there and replace the second string with whatever the first string was. It's easier than just restyling the whole script by removing that line. (They don't have 'style' buttons online)

ok yeah, im glad i get to get to this first finally :)
There is no style button really but it is possibile to style your scripts online.

Quote:

There is now a new command on RC:

/style scripttype name

Scripttype can be class, npc or weapon.
It is reformatting the script to look nicer. Please test it before using, sometimes triggeractions can be messed up because it divides weapon names like Day-Night in Day - Night. You can change the style options in the server options:

scriptstyle=spaces=2,padding=oper,brackets=attach

Spaces gives the number of spaces to put in front of each line (indenting).

Padding says where to put spaces in between:
'oper' will put spaces behind commands like 'if' and before and after operands like '+' and '==',
'paren' will put spaces in [] and (),
'all' will do both.

Brackets says if it should break lines before and after { and } ('break'),
or if it should actually attach it to the previous 'if' or 'for' command ('attach'). Use 'linux' as option if you want to break declarations (array declarations like a = {1,23}) but want to attach brackets after commands.

The npcserver uses the astyle library to format the text.
I guess you or anyone on babylon was aware of this? Anyhow now you are, so its not a style button really, like i said, you have to type just a little but i guess you could get over that very easily. :)

adam 12-30-2003 04:32 PM

Or you could just format them correctly as you write them, thus saving yourself a great deal of trouble.

osrs 12-30-2003 07:35 PM

Nice :)

Here is a gift too, basic, but nice:

NPC Code:

//NPC made by *osrs
// Light effect

if(created){
color = {0.5,0.5,0.5,0.5};
timeout = 0.05;
}

if(timeout){
for(i = 0; i < 10; i ++){
this.a = (this.a < 10) ? (this.a + 0.5) : this.a = 0;
showimg this.a * i,light4.png,mousex - 3.5,mousey - 3.5;
changeimgcolors this.a * i,color[0],color[1],color[2],color[3];
changeimgzoom this.a * i,random(0.1,0.9);
changeimgvis this.a * i,1;
}
timeout = 0.05;
}

if(playerchats){
if(strequals(#c,/red)) color = {0.5,0,0,0.5};
elseif(strequals(#c,/green)) color = {0,0.5,0,0.5};
elseif(strequals(#c,/blue)) color = {0,0,0.5,0.5};
elseif(strequals(#c,/alpha)) color = {0.5,0.5,0.5,0.5};
}


HoudiniMan 12-30-2003 10:21 PM

Quote:

Originally posted by osrs

NPC Code:


if(playerchats){
if(strequals(#c,/red)) color = {0.5,0,0,0.5};
elseif(strequals(#c,/green)) color = {0,0.5,0,0.5};
elseif(strequals(#c,/blue)) color = {0,0,0.5,0.5};
elseif(strequals(#c,/alpha)) color = {0.5,0.5,0.5,0.5};
}


Why do people do those "elseif"s in this situation?
I KNOW for a fact "if" by itself would work fine, i was just wondering if there's acutally a viable reason for doing this...

tlf288 12-30-2003 10:32 PM

Quote:

Originally posted by HoudiniMan


Why do people do those "elseif"s in this situation?
I KNOW for a fact "if" by itself would work fine, i was just wondering if there's acutally a viable reason for doing this...

for effeciency. if your chat is '/red' then it obviously isn't going to be '/blue'; so there is no reason to check for it.

Thought 12-30-2003 10:33 PM

Quote:

Originally posted by HoudiniMan


Why do people do those "elseif"s in this situation?
I KNOW for a fact "if" by itself would work fine, i was just wondering if there's acutally a viable reason for doing this...

Optimization.
NPC Code:
// Both are being checked.
if (thing==A) {
}
if (thing==B) {
}

// If the first statement is false, check the second statement, else, skip the second statement.
if (thing==A) {
}
else if (thing==B) {
}



Think of it this way:

If thing is A, how could it ever be B? So why should you check it twice if thing is A?

tlf288 12-30-2003 11:04 PM

haha, rick. i beat you by one minute.

osrs 12-31-2003 12:35 AM

According to KSI-GS:

Quote:

Rule 8:

If your script is checking multiple possibilities and they are mutually exclusive (ie, they can't both be true), use elseif instead of a string of ifs. It's more efficient (Graal doesn't always need to evaluate all the conditions), and it adds implicit meaning to your code.
:grin:

HoudiniMan 12-31-2003 04:13 AM

got it

GoZelda 01-05-2004 12:50 AM

Another reason:

NPC Code:

if (letter==A){
type A;
} if (letter==B){
type B;
} else {
type CDEFGHIJKLMNOPQRSTUVWXYZ;
}


If the letter's A, you'll also get CDEFGHIJKLMNOPQRSTUVWXYZ.

Good way:
NPC Code:

if (letter==A){
type A;
} else if (letter==B){
type B;
} else {
type CDEFGHIJKLMNOPQRSTUVWXYZ;
}


This bugged me for a while in C++, until i showed the scripts to Tseng and he said he liked if else better, i used that and it was fixed . Me < Tseng


All times are GMT +2. The time now is 10:31 AM.

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