Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-07-2007, 03:59 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
if (this.something1 in player.chat) {}

This is something I'd like to know for vulgar language kind of stuff.

If I were to do the below script and if someone said "You fuken stupid a$$!" would the player chatting say "Don't be mean"?
PHP Code:
//#CLIENTSIDE
function onCreated() this.vulgar = { "a$$","b1tch","fuk" };
function 
onPlayerChats() {
 if (
this.vulgar in player.chat) {
  
player.chat "Don't be mean";
 }

If not, how could I make it do so?

Note: I had to evade the curse filter for people to see this correctly, sorry.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #2  
Old 11-07-2007, 04:26 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
PHP Code:
function onCreated() this.vulgar = { "a$$","b1tch","fuk" };
function 
onPlayerChats() {
  for (
temp.wordthis.vulgar) {
    if (
player.chat.contains(temp.word))
      
player.chat "Don't be mean.";
  }

__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #3  
Old 11-07-2007, 05:48 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
PHP Code:
//#CLIENTSIDE
function onCreated()
  
this.vulgar = { "a$$","b1tch","fuk" };

function 
onPlayerChats() {
 if (
this.vulgar in player.chat.tokenize()) {
  
player.chat "Don't be mean";
 }


You could probably do that.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #4  
Old 11-07-2007, 07:08 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
PHP Code:
//#CLIENTSIDE

function onCreated()
{
  
this.badwords = {"one""two""three"};
}

function 
onPlayerChats()
{
  for (
temp.wordplayer.chat.tokenize())
  {
    if (
temp.word in this.badwords)
    {
      
player.chat "bzzt";
    }
  }

... to do it using tokens of the player's chat text.
__________________
Skyld
Reply With Quote
  #5  
Old 11-07-2007, 08:41 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
people. you do know that it only finds an individual string in an array right? you can't do array in array...
__________________
Reply With Quote
  #6  
Old 11-07-2007, 11:21 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
PHP Code:
function onPlayerChat()
{
  
player.chat "";

This'll prevent any vulgar words in any language from being said.
Reply With Quote
  #7  
Old 11-07-2007, 11:47 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Quote:
Originally Posted by Novo View Post
PHP Code:
function onPlayerChat()
{
  
player.chat "";

This'll prevent any vulgar words in any language from being said.
Rofl
__________________
Reply With Quote
  #8  
Old 11-08-2007, 12:31 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by Novo View Post
PHP Code:
function onPlayerChat()
{
  
player.chat "";

This'll prevent any vulgar words in any language from being said.
You're a genius!
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #9  
Old 11-08-2007, 03:22 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by Skyld View Post
PHP Code:
//#CLIENTSIDE

function onCreated()
{
  
this.badwords = {"one""two""three"};
}

function 
onPlayerChats()
{
  for (
temp.wordplayer.chat.tokenize())
  {
    if (
temp.word in this.badwords)
    {
      
player.chat "bzzt";
    }
  }

... to do it using tokens of the player's chat text.
What's the : for and what's it mean, so I can use it later? Also, what's a ? used for in some scripts after the name of a string or something... offtopic on that bu wanted to know xD
Quote:
Originally Posted by Novo View Post
PHP Code:
function onPlayerChat()
{
  
player.chat "";

This'll prevent any vulgar words in any language from being said.
lurvsu!
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #10  
Old 11-08-2007, 03:31 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
NPC Code:
for (needle: haystack) {
// "needle" now points to the address of a value in "haystack"
statements;
}


Known as a for-each statement.

NPC Code:
condition?true-case:false-case


Known as the tertiary operator.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #11  
Old 11-08-2007, 03:35 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by Tolnaftate2004 View Post
NPC Code:
condition?true-case:false-case


Known as the tertiary operator.
Explain more?
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #12  
Old 11-08-2007, 03:40 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
PHP Code:
if (this.bla "lol") {
  
this.wow "ohmy";
}
else {
  
this.wow "egad";

Becomes...
PHP Code:
this.wow this.bla=="lol"?"ohmy":"egad"
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #13  
Old 11-08-2007, 03:51 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
I Saids Explain
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #14  
Old 11-08-2007, 04:06 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
It evaluates a condition and depending on whether it is true or false, it will execute the true-case or the false-case.

I say 'execute', but in practice, using this as flow-control is bad.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #15  
Old 11-08-2007, 04:13 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
That's basically "if () { } else {}"
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #16  
Old 11-08-2007, 04:46 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Switch View Post
That's basically "if () { } else {}"
An if statement is certainly less useful in situations such as:
PHP Code:
echo(temp.amount " apple" @ ((temp.amount != 1)?"s":""); 
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #17  
Old 11-08-2007, 05:34 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
So explain, what does the ? do EXACTLY, what does the : do EXACTLY?
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #18  
Old 11-08-2007, 06:14 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Switch View Post
what does the ? do EXACTLY
? separates the condition from two statements that could be made:
condition?statements;

Quote:
Originally Posted by Switch View Post
what does the : do EXACTLY?
: separates the two statements apart from one another:
statement1:statement2


All they do is tell the computer where one piece ends and another starts. Both the ? and the : need to be present for the operator to function correctly.

They can also be nested:
a?b?c:d:e is "translated" into a?(b?c:d):e
You will always have # statements = # conditions + 1.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #19  
Old 11-08-2007, 06:22 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
Quote:
Originally Posted by Switch View Post
So explain, what does the ? do EXACTLY, what does the : do EXACTLY?
Before the ? you put a condition. If that condition is true, the code between the ? and the : is executed*. If it's not true, then the code after the : is executed.

*It would be more accurate to say that the code/content either before or after the : replaces the entire statement, but the way it's phrased above makes it easier to understand.
__________________
Reply With Quote
  #20  
Old 11-11-2007, 05:43 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by Tolnaftate2004 View Post
? separates the condition from two statements that could be made:
condition?statements;


: separates the two statements apart from one another:
statement1:statement2


All they do is tell the computer where one piece ends and another starts. Both the ? and the : need to be present for the operator to function correctly.

They can also be nested:
a?b?c:d:e is "translated" into a?(b?c:d):e
You will always have # statements = # conditions + 1.
That explains how to use them, thanks
Quote:
Originally Posted by Googi View Post
Before the ? you put a condition. If that condition is true, the code between the ? and the : is executed*. If it's not true, then the code after the : is executed.

*It would be more accurate to say that the code/content either before or after the : replaces the entire statement, but the way it's phrased above makes it easier to understand.
That explains what they do, thanks

But sometimes I see someone's script and it doesnt have a ? in it, so clearly you don't ALWAYS have to use a ?. What are examples like that and what happens in them?
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #21  
Old 11-11-2007, 05:57 PM
Knightmare1 Knightmare1 is offline
Billy Allan
Knightmare1's Avatar
Join Date: Apr 2007
Posts: 804
Knightmare1 can only hope to improve
lol the swear filter i have makes you say funny stuff and logs you. like i said oh sh!t, and it made me say, "i eat tampons"
__________________
I am the devil, I am here to do to devils work.
Reply With Quote
  #22  
Old 11-11-2007, 06:02 PM
Arch_Angel Arch_Angel is offline
Registered User
Join Date: Apr 2007
Posts: 482
Arch_Angel is on a distinguished road
Send a message via AIM to Arch_Angel
Quote:
Originally Posted by Knightmare1 View Post
lol the swear filter i have makes you say funny stuff and logs you. like i said oh sh!t, and it made me say, "i eat tampons"
Thats not really.. a swear... nvm
Reply With Quote
  #23  
Old 11-11-2007, 06:06 PM
Knightmare1 Knightmare1 is offline
Billy Allan
Knightmare1's Avatar
Join Date: Apr 2007
Posts: 804
Knightmare1 can only hope to improve
i used i not ! tho
__________________
I am the devil, I am here to do to devils work.
Reply With Quote
  #24  
Old 11-11-2007, 06:44 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
back on topic please?
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #25  
Old 11-11-2007, 10:41 PM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
Quote:
Originally Posted by Switch View Post
But sometimes I see someone's script and it doesnt have a ? in it, so clearly you don't ALWAYS have to use a ?. What are examples like that and what happens in them?
Are you talking about when there's a for loop with two "variables" seperated by a colon? Like "for (this.var : this.array)"

In this case, you have to put an array on the right side of the colon. The for loop is then executed a number of times equal to the length of the array, and this.var is set to the corresponding value in the array each time.

So if this.array = {8, 20, 1, 6}, then the loop will be executed 4 times, and this.var will be set to 8 the first time, 20 the second time, 1 the third time and 6 the fourth time.

Of course, this.var can be any type of variable (you could just name it "i" as is standard in for loops), it doesn't have to be a this. variable.
__________________
Reply With Quote
  #26  
Old 11-12-2007, 01:26 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
That helpd a bunch, thanks
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #27  
Old 11-13-2007, 11:42 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
The colon in a for loop and the colon in a conditional assignment are completely different.
__________________
Do it with a DON!
Reply With Quote
  #28  
Old 11-14-2007, 12:07 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
I know, Googi said that. I asked how they were different.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 09:27 AM.


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