Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   if (this.something1 in player.chat) {} (https://forums.graalonline.com/forums/showthread.php?t=77469)

Switch 11-07-2007 03:59 AM

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. :frown:

coreys 11-07-2007 04:26 AM

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



Tigairius 11-07-2007 05:48 PM

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.

Skyld 11-07-2007 07:08 PM

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.

xAndrewx 11-07-2007 08:41 PM

people. you do know that it only finds an individual string in an array right? you can't do array in array...

Novo 11-07-2007 11:21 PM

PHP Code:

function onPlayerChat()
{
  
player.chat "";


This'll prevent any vulgar words in any language from being said.

Dan 11-07-2007 11:47 PM

Quote:

Originally Posted by Novo (Post 1356924)
PHP Code:

function onPlayerChat()
{
  
player.chat "";


This'll prevent any vulgar words in any language from being said.

Rofl

coreys 11-08-2007 12:31 AM

Quote:

Originally Posted by Novo (Post 1356924)
PHP Code:

function onPlayerChat()
{
  
player.chat "";


This'll prevent any vulgar words in any language from being said.

You're a genius!

Switch 11-08-2007 03:22 AM

Quote:

Originally Posted by Skyld (Post 1356879)
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 (Post 1356924)
PHP Code:

function onPlayerChat()
{
  
player.chat "";


This'll prevent any vulgar words in any language from being said.

lurvsu!

Tolnaftate2004 11-08-2007 03:31 AM

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.

Switch 11-08-2007 03:35 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1357032)
NPC Code:
condition?true-case:false-case


Known as the tertiary operator.

Explain more?

coreys 11-08-2007 03:40 AM

PHP Code:

if (this.bla "lol") {
  
this.wow "ohmy";
}
else {
  
this.wow "egad";


Becomes...
PHP Code:

this.wow this.bla=="lol"?"ohmy":"egad"


Switch 11-08-2007 03:51 AM

I Saids Explain >_<

Tolnaftate2004 11-08-2007 04:06 AM

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.

Switch 11-08-2007 04:13 AM

That's basically "if () { } else {}" :\

Tolnaftate2004 11-08-2007 04:46 AM

Quote:

Originally Posted by Switch (Post 1357047)
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":""); 


Switch 11-08-2007 05:34 AM

So explain, what does the ? do EXACTLY, what does the : do EXACTLY?

Tolnaftate2004 11-08-2007 06:14 AM

Quote:

Originally Posted by Switch (Post 1357061)
what does the ? do EXACTLY

? separates the condition from two statements that could be made:
condition?statements;

Quote:

Originally Posted by Switch (Post 1357061)
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.

Googi 11-08-2007 06:22 AM

Quote:

Originally Posted by Switch (Post 1357061)
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.

Switch 11-11-2007 05:43 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1357069)
? 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 :D
Quote:

Originally Posted by Googi (Post 1357071)
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 :D

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?

Knightmare1 11-11-2007 05:57 PM

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"

Arch_Angel 11-11-2007 06:02 PM

Quote:

Originally Posted by Knightmare1 (Post 1357797)
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 x_x

Knightmare1 11-11-2007 06:06 PM

i used i not ! tho

Switch 11-11-2007 06:44 PM

back on topic please? :\

Googi 11-11-2007 10:41 PM

Quote:

Originally Posted by Switch (Post 1357789)
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.

Switch 11-12-2007 01:26 AM

That helpd a bunch, thanks :D

zokemon 11-13-2007 11:42 AM

The colon in a for loop and the colon in a conditional assignment are completely different.

Switch 11-14-2007 12:07 AM

I know, Googi said that. I asked how they were different.


All times are GMT +2. The time now is 07:35 AM.

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