Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Help me please (https://forums.graalonline.com/forums/showthread.php?t=134267092)

iCoke 09-09-2012 01:28 AM

Help me please
 
Hello, I posted it here because I didnt see anywere else to post it, but anyways I need help with this script. The problem is there is a syntax error.

Script:

function onPlayerchats()
{
if (player.chat == "/open")
{
if (player.weapons.index(findweapon("-Bank/Account")) > 0)
{
say2("You already have a bank account");
}
else
{
say2("You have opened a bank account!");
player.addWeapon("-Bank/Account");
}
}

Starfire2001 09-09-2012 01:35 AM

Quote:

Originally Posted by iCoke (Post 1703384)
Hello, I posted it here because I didnt see anywere else to post it, but anyways I need help with this script. The problem is there is a syntax error.

Script:

function onPlayerchats()
{
if (player.chat == "/open")
{
if (player.weapons.index(findweapon("-Bank/Account")) > 0)
{
say2("You already have a bank account");
}
else
{
say2("You have opened a bank account!");
player.addWeapon("-Bank/Account");
}
}

You are missing a }. Should style it, makes those type of errors obvious and makes things just generally easier to read.

PHP Code:

function onPlayerchats(){
  if (
player.chat == "/open"){
    if (
player.weapons.index(findweapon("-Bank/Account")) > 0){
      
say2("You already have a bank account");
    }
    else{
      
say2("You have opened a bank account!");
      
player.addWeapon("-Bank/Account");
    }
  } 


iCoke 09-09-2012 02:03 AM

Now it says

"missing ] after element list"

callimuc 09-09-2012 02:18 AM

try using something like this:
PHP Code:

function onPlayerchats(){
  if (
player.chat == "/open"){
    if (!(
"-Bank/Account" in player.weapons)){
      
say2("You already have a bank account");
    }
    else{
      
say2("You have opened a bank account!");
      
player.addWeapon("-Bank/Account");
    }
  } 



iCoke 09-09-2012 03:25 AM

Nope not working :O :( :'(... I wonder why?

callimuc 09-09-2012 03:31 AM

if you are trying this in the offline editor, ignore the errors there and upload it. the offline editor just debugs that for the GS1 scripts, not GS2

iCoke 09-09-2012 04:09 AM

Im not, I am putting it on as a "Weapon" on a server.

Starfire2001 09-09-2012 05:06 AM

Quote:

Originally Posted by iCoke (Post 1703394)
Im not, I am putting it on as a "Weapon" on a server.

onPlayerChats doesn't work serverside in weapons, so you have to make the script you have clientside. However you can't add weapons to the player clientside, so you are going to have to use triggerserver to add the weapon. If you don't know anything about triggering try this thread.

http://forums.graal2001.com/forums/s...ad.php?t=84321

Using callimuc's script, you'll end up with something like...

PHP Code:

function onActionserverside(){
  
//add the weapon
}

//#CLIENTSIDE
function onPlayerchats(){
  if (
player.chat == "/open"){
    if (!(
"-Bank/Account" in player.weapons)){
      
say2("You already have a bank account");
    }
    else{
      
say2("You have opened a bank account!");
      
//triggerserver goes here
    
}
  } 



iCoke 09-09-2012 03:20 PM

So would it be like this?

Script:

PHP Code:

function onActionserverside(){
  
//add the weapon
}

//#CLIENTSIDE
function onPlayerchats(){
  if (
player.chat == "/open"){
    if (!(
"-Bank/Account" in player.weapons)){
      
say2("You already have a bank account");
    }
    else{
      
say2("You have opened a bank account!");
      
//// This is my clientside part of the script.
//#CLIENTSIDE
function onCreated() {
  
this.myatm "myatm.png";
  
triggerserver("png"this.name"myatm.png"this.myatm);
}
    }
  } 


cbk1994 09-09-2012 04:08 PM

Please wrap your code in [PHP] tags when you post here. That way it's formatted nicely (look at callimuc and Starfire2001's posts). I have to strain to read the code you're posting because there's no indentation.

callimuc 09-09-2012 07:06 PM

Quote:

Originally Posted by iCoke (Post 1703420)
So would it be like this?

Script:

PHP Code:

function onActionserverside(){
  
//add the weapon
}

//#CLIENTSIDE
function onPlayerchats(){
  if (
player.chat == "/open"){
    if (!(
"-Bank/Account" in player.weapons)){
      
say2("You already have a bank account");
    }
    else{
      
say2("You have opened a bank account!");
      
//// This is my clientside part of the script.
//#CLIENTSIDE
function onCreated() {
  
this.myatm "myatm.png";
  
triggerserver("png"this.name"myatm.png"this.myatm);
}
    }
  } 


maybe you should start with more basic stuff


All times are GMT +2. The time now is 01:17 PM.

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