Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-03-2011, 06:39 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Chat customizer!

So i finally figure how to trigger serverside! Its opened a lot more options to me with GS2. Anyway, heres what i came up with. Hope you like it. Its only very simple but to me, its a huge step!

PHP Code:
//Scripted by Emera. Chat Customizer!
function ActionServerSide() {
  if ( 
params[0] == "chat" ) {
    
player.chat(params[1]);
  }
}
//#CLIENTSIDE
function onPlayerChats() {
if (
player.chat == player.chat) {
player.chat "Emera: "@player.chat;
}
}

for ( 
temp.allplayers ) {
  
with (temp.p) {
    
triggerServer"gui"this.name"chat"message );
  }

It starts of the players chat with the message in the script. You can change it from "Emera: " by typing other messages in. There is no on / off yet because i haven't got to that stuff yet. Thanks guys.
__________________
Reply With Quote
  #2  
Old 05-03-2011, 06:54 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Issues:

1. You shouldn't have code outside of functions, code placed like that is executed every time an event occurs.
2. You're comparing player.chat to itself, which is effectively the same as doing if (true) which is pointless.
3. player.chat is a variable not a function.
4. The way your loop is setup on the client-side you're sending (playercount+ircbots) triggers to the server which is really bad.
5. Code isn't indented properly.

PHP Code:
//Scripted by Emera. Chat Customizer!
function ActionServerSide() {
  if ( 
params[0] == "chat" ) {
    
player.chat(params[1]); // Issue 3: player.chat is a variable not a function.
  
}
}
//#CLIENTSIDE


function onPlayerChats() {
// Issue 5: Code isn't indented properly.
if (player.chat == player.chat) { // Issue 2: Comparing player.chat to itself, will always evaluate be true.
player.chat "Emera: "@player.chat;
}
}

// Issue 1: Code outside of a function.
for ( temp.allplayers ) { // Issue 4: Will send (playercount + ircbots) amount of triggerservers. You should only need to send one.
  
with (temp.p) {
    
triggerServer"gui"this.name"chat"message );
  }

Re-arranged and fixed issues:

PHP Code:
function ActionServerSide() { 
  if ( 
params[0] == "chat" ) { 
    for (
temp.pallplayers) {
      
with (temp.p) {
        
player.chat params[1];
      }
    }
  } 
}
 
//#CLIENTSIDE

function onPlayerChats() { 
  
triggerserver("gui"this.name"chat"player.chat);

I believe the above is what you were aiming for.
__________________
Quote:

Last edited by fowlplay4; 05-03-2011 at 07:08 PM..
Reply With Quote
  #3  
Old 05-03-2011, 06:57 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Oo Thanks for your help but thats way over my head.
__________________
Reply With Quote
  #4  
Old 05-03-2011, 07:08 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Emera View Post
Oo Thanks for your help but thats way over my head.
Updated and labeled the problem areas.
__________________
Quote:
Reply With Quote
  #5  
Old 05-03-2011, 07:14 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Thanks i see know!
Its all about simplicity.
__________________
Reply With Quote
  #6  
Old 05-03-2011, 10:01 PM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Dude you can just do.
PHP Code:
//#CLIENTSIDE
function onPlayerChats()
  {
  
temp.chat player.chat;
  
player.chat player.nick@": "@temp.chat;
  } 
Yes, its that simple
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #7  
Old 05-03-2011, 10:16 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Astram View Post
Dude you can just do.
PHP Code:
//#CLIENTSIDE
function onPlayerChats()
  {
  
temp.chat player.chat;
  
player.chat player.nick@": "@temp.chat;
  } 
Yes, its that simple
PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
  
player.chat player.nick ": " player.chat;

__________________
Reply With Quote
  #8  
Old 05-03-2011, 10:26 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by cbk1994 View Post
PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
  
player.chat player.nick ": " player.chat;

If this was all the original script was supposed to do, Wow.
__________________
Quote:
Reply With Quote
  #9  
Old 05-03-2011, 10:31 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
I think changing the player's chat calls onPlayerchats() so you might end up with:
"Emera: Emera: Emera: Emera: Emera: Emera: Emera: test"

I may be mistaken though.
Reply With Quote
  #10  
Old 05-03-2011, 10:52 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by DustyPorViva View Post
I think changing the player's chat calls onPlayerchats() so you might end up with:
"Emera: Emera: Emera: Emera: Emera: Emera: Emera: test"

I may be mistaken though.
Changing the player's chat will not invoke the event again.
Reply With Quote
  #11  
Old 05-05-2011, 07:30 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Oh it really that simple?
__________________
Reply With Quote
  #12  
Old 05-05-2011, 07:33 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
PHP Code:
 //#CLIENTSIDE 
function onPlayerChats() { 
  
player.chat player.nick ": " player.chat

This doesn't work. I tried it out in a separate script to test it out and i can't see my nickname at the start of the chat. Also, how can i turn my original script on / off using onWeaponFired() ?
__________________
Reply With Quote
  #13  
Old 05-05-2011, 11:01 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Have a variable in it:
PHP Code:
function onWeaponFired()
{
  
this.on=1-this.on;
  if (
this.on==1)
  {
    
//weapon is now on
  
}
  else 
  {
    
//weapon is now off
  
}

Reply With Quote
  #14  
Old 05-05-2011, 11:04 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
Quote:
Originally Posted by Emera View Post
PHP Code:
 //#CLIENTSIDE 
function onPlayerChats() { 
  
player.chat player.nick ": " player.chat

This doesn't work. I tried it out in a separate script to test it out and i can't see my nickname at the start of the chat. Also, how can i turn my original script on / off using onWeaponFired() ?
HTML Code:
//#CLIENTSIDE
function onWeaponFired() {
  this.on = !this.on;
  player.chat = "Nicknames" SPC (this.on? "on":"off");
}

function onPlayerChats() {
  if (this.on == false) return;
  player.chat = player.nick @ ":" SPC player.chat;
}
__________________
Reply With Quote
  #15  
Old 05-05-2011, 11:19 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xAndrewx View Post
code
You should use PHP tags for posting code—it looks a lot nicer .
__________________
Reply With Quote
  #16  
Old 05-05-2011, 11:23 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
shouldn't be evaling a bool like that,

if (this.on) is sufficient
Reply With Quote
  #17  
Old 05-06-2011, 08:22 AM
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
Quote:
Originally Posted by Mark Sir Link View Post
shouldn't be evaling a bool like that,

if (this.on) is sufficient
ohh- why? =o
__________________
Reply With Quote
  #18  
Old 05-06-2011, 09:08 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by xAndrewx View Post
ohh- why? =o
it depends on the compiler but I imagine in Graal's case, it's loading the variable (boolean), comparing the operator, then loading the global (TRUE), adding an extra step or two

it's true for variables that aren't obviously booleans (like possibly even "on") that evaluating like that makes the intention much clearer, but you could try naming the var something like "isOn", "isActive", etc
Reply With Quote
  #19  
Old 05-06-2011, 05:50 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
ois, ty
__________________
Reply With Quote
  #20  
Old 05-06-2011, 06:05 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Thnks andy.
__________________
Reply With Quote
  #21  
Old 05-06-2011, 06:20 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Mark Sir Link View Post
it depends on the compiler but I imagine in Graal's case, it's loading the variable (boolean), comparing the operator, then loading the global (TRUE), adding an extra step or two

it's true for variables that aren't obviously booleans (like possibly even "on") that evaluating like that makes the intention much clearer, but you could try naming the var something like "isOn", "isActive", etc
To get technical, GS2 doesn't have booleans (true is a compile-time constant for 1). The if statement accepts an integer (coercing anything else to an integer), and executes the first branch for any non-zero integer, and the second otherwise.

Some useful snippits supporting this:
PHP Code:
temp."test" == "test";
echo(
temp.x.type()); // type 0, an integer
echo(temp.x// 1

// ---- //

echo(true.type()); // type -1, because true is rewritten at compile-time, meaning the real expression is (1).type(), which evaluates to -1

// ---- //

if (2) {
  echo(
"success"); // it echos, meaning that the first branch executes for any non-zero integer




Checking something like if (temp.x == 1) would be useful in the case that temp.x can be 2 or 3.


However, in the case that temp.x will only ever be 0 or 1, it would be a useless operation. Look at how it evaluates:

When temp.x = 1:
NPC Code:
if (temp.x == 1)      =>     if (1 == 1)     =>     if (1)



When temp.x = 0:
NPC Code:
if (temp.x == 1)      =>     if (0 == 1)     =>     if (0)   



So in this case that temp.x is either 0 or 1, that == 1 is redundant.



My styling recommendation would be to do if (temp.x) in the case that you assuming temp.x is limited to 0 and 1, but if (temp.x == 1) in any other case.

The message being that we don't need to restrict our styling to GS2's type system, because it is not strongly enforced and we can be more expressive by breaking these bounds.



Note: Technically, GS2 doesn't even have integers, it only has floats. But that's a headache for another day...
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 11:51 PM.


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