![]() |
|
09-21-2012
|
1 |
|
Circus
Join Date: Sep 2011
Location: London
Posts: 2,090
|
A little script help...
So I've been trying to make a parrot script where the image of this parrot repeats whatever you say, which is easy (this.chat=player.chat) however, I need to be able to disable this script by the command of a player, this is what I came up with so far: function onPlayerChats() { if (player.chat == "stop") { this.chat = "*Squawk*Bye!*Squawk*"; sleep(1); hide; } else if (player.chat == "talk") { this.chat = "*Squawk*Hello!*Squawk*"; show; sleep(1); this.chat = ""; } } Rep for anyone who helps me the most
|
|
09-21-2012
|
2 |
|
Coder
Join Date: Sep 2011
Posts: 298
|
use a this. var as a boolean to toggle it on and off. function onCreated() { this.enabled = true; } function onPlayerChats() { if (player.chat == "your toggle command") { // enable or disable here this.enabled = !this.enabled; } elseif (this.enabled) { // if its enabled, repeat what player says } } |
|
09-21-2012
|
3 | |
|
Circus
Join Date: Sep 2011
Location: London
Posts: 2,090
|
this is what i picked up: function onCreated() { this.enabled = true; } function onPlayerChats() { if (player.chat == "stop") { enable; this.enabled = !this.enabled; } elseif (this.enabled) { // if its enabled, repeat what player says } } |
|
|
09-21-2012
|
4 |
|
Coder
Join Date: Sep 2011
Posts: 298
|
anyything in a line past two forward slashes is just a comment, and does not affect the script. // this is a comment so, take a look at the following script. when it is "created" it sets this.enabled to true. When a player says "birdie!" this.enabled is set to the negation of itself. That setting of the negation is what causes the the toggling between the parrot repeating mode 'On' and 'Off'. Whenever the player says something that is not "birdie!", it checks if this.enabled is true. If that checks out, it repeats what the player says. function onCreated() { this.enabled = true; } function onPlayerChats() { if (player.chat == "birdie!") { // enable or disable here this.enabled = !this.enabled; } elseif (this.enabled) { // if its enabled, repeat what player says this.chat = player.chat; } } |
|
09-21-2012
|
5 | |
|
Circus
Join Date: Sep 2011
Location: London
Posts: 2,090
|
and i dont know where in the script it represents this... sorry if you have put it all in i just have not learned this far into gs2 |
|
|
09-21-2012
|
6 |
|
Coder
Join Date: Sep 2011
Posts: 298
|
ok, i misunderstood part of what you were wanting. function onCreated() { this.enabled = true; } function onPlayerChats() { if (player.chat == "enable") { this.enabled = true; } elseif (player.chat == "disable") { this.enabled = false; } elseif (this.enabled) { // if its enabled, repeat what player says this.chat = "*squawk*" @ player.chat @ "*squawk*"; } } does that make more sense? ![]() the @ operator is a concatination thing. so this is like putting "*squawk*" at the beginning and end of whatever the player says: "*squawk*" @ player.chat @ "*squawk*" |
|
09-21-2012
|
7 | |
|
Circus
Join Date: Sep 2011
Location: London
Posts: 2,090
|
thanks so much heres your well deserved rep
|
|