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-30-2003, 03:16 AM
Goboom Goboom is offline
Pixel Monkey
Goboom's Avatar
Join Date: Dec 2001
Location: Michigan
Posts: 1,702
Goboom is on a distinguished road
Send a message via ICQ to Goboom Send a message via AIM to Goboom Send a message via MSN to Goboom Send a message via Yahoo to Goboom
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;
}

__________________

Last edited by Goboom; 12-30-2003 at 03:30 AM..
Reply With Quote
  #2  
Old 12-30-2003, 03:18 AM
MarkB MarkB is offline
Sparked.
MarkB's Avatar
Join Date: Jun 2003
Location: Archaic
Posts: 881
MarkB is on a distinguished road
Cool
__________________


Graal Kingdoms Event Master
I am tired to wake up the morning to see the forum going each day worst and worst because of a few people trying to ruin this forums. If you don't play any more Graal neither like the managment then what are you doing there ? I will not let anyone ruin the friendship of the community, we are there to have fun and not to have stress ! If you have bad energy to spend against something, then take a punching ball. This is the Third time i warn to not continue this way, so the next step will be to put out of the community trouble makers. -Unixmad

My point of view is your tooth are not big enough to hit me because if it were you will have eaten me since a while. Personaly i will never eat you because it will really taste bad. -Unixmad
Reply With Quote
  #3  
Old 12-30-2003, 05:13 AM
screen_name screen_name is offline
is watching you
Join Date: Mar 2002
Location: The 3rd Dimension
Posts: 2,160
screen_name is on a distinguished road
Send a message via AIM to screen_name Send a message via MSN to screen_name
Goboom, just curious, but...

Why did you put;

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

?
__________________
[signature]insert here[/signature]
Reply With Quote
  #4  
Old 12-30-2003, 05:33 AM
Blue_Dragn Blue_Dragn is offline
Registered User
Join Date: Jul 2003
Posts: 302
Blue_Dragn is on a distinguished road
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
__________________
No longer a Advertisement Goat
Reply With Quote
  #5  
Old 12-30-2003, 07:44 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
*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)
__________________
"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
  #6  
Old 12-30-2003, 08:33 AM
Blue_Dragn Blue_Dragn is offline
Registered User
Join Date: Jul 2003
Posts: 302
Blue_Dragn is on a distinguished road
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.
__________________
No longer a Advertisement Goat
Reply With Quote
  #7  
Old 12-30-2003, 04:32 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Or you could just format them correctly as you write them, thus saving yourself a great deal of trouble.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #8  
Old 12-30-2003, 07:35 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
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};
}

__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /

Last edited by osrs; 12-30-2003 at 07:46 PM..
Reply With Quote
  #9  
Old 12-30-2003, 10:21 PM
HoudiniMan HoudiniMan is offline
Playerworld Administrator
HoudiniMan's Avatar
Join Date: Dec 2001
Location: Calfiornia - USA
Posts: 3,512
HoudiniMan will become famous soon enough
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...
__________________
-HoudiniMan (Chief Playerworld Administrator)
Compulsive Support Center Checker - 5 Years and Change
Graal Support Center

Reply With Quote
  #10  
Old 12-30-2003, 10:32 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
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.
__________________
new account: Trevor
Reply With Quote
  #11  
Old 12-30-2003, 10:33 PM
Thought Thought is offline
PipBoy Extraordinaire!
Thought's Avatar
Join Date: Nov 2001
Location: Long Beach, California.
Posts: 692
Thought is on a distinguished road
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?
__________________
Rick ([email protected])
#gscript on FreeNode (#gscript Guild, #gscript Information)
Graal User Statistics

I am now using my new account, Rick.
Reply With Quote
  #12  
Old 12-30-2003, 11:04 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
haha, rick. i beat you by one minute.
__________________
new account: Trevor
Reply With Quote
  #13  
Old 12-31-2003, 12:35 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
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:
__________________
"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
  #14  
Old 12-31-2003, 04:13 AM
HoudiniMan HoudiniMan is offline
Playerworld Administrator
HoudiniMan's Avatar
Join Date: Dec 2001
Location: Calfiornia - USA
Posts: 3,512
HoudiniMan will become famous soon enough
got it
__________________
-HoudiniMan (Chief Playerworld Administrator)
Compulsive Support Center Checker - 5 Years and Change
Graal Support Center

Reply With Quote
  #15  
Old 01-05-2004, 12:50 AM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
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
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
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:30 AM.


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