Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   How to script chat-operated weapons? (https://forums.graalonline.com/forums/showthread.php?t=134263746)

xuntasi 07-04-2011 03:37 AM

How to script chat-operated weapons?
 
Ok, so I am deeply confused about how to script weapons that are affected by player chat. I made this script, and it is operated by chat commands, but when I make it a weapon it doesn't work. I've literally been sitting at my computer for over 2 hours now stuck on this one script. It works perfectly when made into a regular NPC, but it doesn't do jack as a weapon. I'm not asking for anyone to give me any script, I just need advice on what commands I should change to make this a weapon (or just a script that will work in all levels, not necessarily a weapon. Really the only problem now is that it only works in the room with the NPC.)

Here is my script:
PHP Code:

function onPlayerChats() {
  if(
player.chat.starts("/shonmessage ") && player.account=="Graal780973") {
    
shon.mess player.chat.substring("/shonmessage ".length());
    echo(
"Shonspeak message set to "@shon.mess);
  }
  if(
player.chat.starts("/shonaccount ") && player.account=="Graal780973") {
    
shon.acc findplayer(player.chat.substring("/shonaccount ".length()));
    echo(
"Shonspeak target set to "@shon.acc.account);
  }
  if(
player.chat=="/shonspeak" && player.account=="Graal780973") {
  
shon.acc.chat shon.mess;
  }


Any advice as to what I should do?

Tigairius 07-04-2011 03:40 AM

In a weapon, onPlayerChats() is only invoked on the clientside.

Tip: echo() will be sent to your F2 window on the clientside.

xuntasi 07-04-2011 03:44 AM

I know about the echo this, that was intentional, but what of the clientside thing? Do I just add //#CLIENTSIDE to the script and it will work?

Tigairius 07-04-2011 03:45 AM

Yes, it will work to an extent. I'm assuming you've defined "shon" to be some object somewhere else on the serverside, so, in order to get the complete desired effect, you will most likely have to use triggerserver() to send the information to the serverside.

xuntasi 07-04-2011 03:47 AM

Thanks man! lol Though I think I should read more GS2 tutorials before I do any more on that script, cause Idk what the serverside or clientside are, let alone how to access them.

xuntasi 07-04-2011 03:50 AM

Wait do I just put this in the script?
PHP Code:

function onCreated() {
  
triggerserver()


Cause that'd be pretty easy lol.

Tigairius 07-04-2011 03:52 AM

I'll do this one for you as an example, consider this your freebie. ;)
PHP Code:

function onActionServerside(commandparameter) {
  switch (
command) {
    case 
"mess":
      
shon.mess parameter;
      echo(
"Shonspeak message set to "shon.mess);
    break;

    case 
"acc":
      
shon.acc findplayer(parameter);
      echo(
"Shonspeak target set to "@shon.acc.account);
    break;

    case 
"accchat":
      
shon.acc.chat shon.mess;
    break;
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/shonmessage ") && player.account=="Graal780973") {
    
temp.mess player.chat.substring("/shonmessage ".length());
    
triggerserver("weapon"this.name"mess"temp.mess);
  }
  if (
player.chat.starts("/shonaccount ") && player.account=="Graal780973") {
    
temp.acc player.chat.substring("/shonaccount ".length());
    
triggerserver("weapon"this.name"acc"temp.acc);
  }
  if (
player.chat=="/shonspeak" && player.account=="Graal780973") {
    
triggerserver("weapon"this.name"accchat");
  }



xuntasi 07-04-2011 03:57 AM

Oh wow thanks dude! I'm gonna study this a lot, I need to figure out how to do this myself! Thank you very much for all your help! :)

Deas_Voice 07-04-2011 09:26 PM

you can also use if (player.account == "Graal780973") { above your if statements,
instead of repeating if (... && player.account == "Graal780973") { for every if condition you make that is "account locked".

e.g;
PHP Code:

if (player.account == "acc") {
  if (
player.chat == "something") { // only "acc" can call doStuffs(); by saying "something"
    
doStuffs();
  }
  if (
player.chat == "stuff") { // same here
    
doOtherStuffs();
  }




All times are GMT +2. The time now is 04:23 AM.

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