Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   shop script help once again (https://forums.graalonline.com/forums/showthread.php?t=81748)

GULTHEX 09-10-2008 06:14 PM

shop script help once again
 
PHP Code:

function onCreated()
{
  
setshape 1,32,32;
}
function 
onActionbuy()
{
  if(
playerrupees>=100)
  {
    
addweapon Event/Headbob;
    
playerrupees-=100;
  }
}
//#CLIENTSIDE
function onPlayerchats()
{
  if(
player.chat=="buy Headbob")
  {
    
triggeraction(x,y,"buy","buy");
    
//the level npc triggeraction type
  
}


when i put this in a lvl npc and say buy Headbob nothing happens

how do i fix it???

[email protected] 09-10-2008 08:27 PM

Don't use that
Use this

HTML Code:

function onPlayerChats() {
  if (player.chat != "buy headbob") return false;
  if (player.rupees < 100) return false;
  if (player.findWeapon("headbob") != false) return false;
  player.addWeapon("headbob");
  player.rupees -= 100;
}


Kristi 09-10-2008 09:49 PM

Quote:

Originally Posted by [email protected] (Post 1422055)
Don't use that
Use this

HTML Code:

function onPlayerChats() {
  if (player.chat != "buy headbob") return false;
  if (player.rupees < 100) return false;
  if (player.findWeapon("headbob") != false) return false;
  player.addWeapon("headbob");
  player.rupees -= 100;
}


Your code assumes his shopkeeper will only be selling that one item (which will most likely be false)

[email protected] 09-10-2008 09:52 PM

Quote:

Originally Posted by Kristi (Post 1422102)
Your code assumes his shopkeeper will only be selling that one item (which will most likely be false)

you've not seen his server. it will, trust me :D

GULTHEX 09-11-2008 01:29 AM

Nope im selling 3 items lolz
and i scripted them myself
*note they just play ganis well thats good for me *
IM LEARNING HOW TO SCRIPT YAY YAY YAY

Frankie 09-11-2008 02:32 AM

I was really bored so I made this. It supports multiple items sold. I stopped testing it once I got to the rupee and weapon check, but the command works fine.

Up for grabs, wasn't really making it specifically for Gulthex, I was just really bored and thought I would try it.

PHP Code:

function onPlayerChats()
{
  if (
player.chat.starts("buy"))
  {
    
this.saleItems = {
      {
"headbob"100"Event/Headbob"},
      {
"anotheritem"250"Event/Item"},
      {
"dance item"50"Event/Dance"}
    };

    for (
temp.ithis.saleItems)
    {
      if (
player.chat.substring(4) == temp.i[0])
      {
        
this.buyItem(temp.i[0], temp.i[1], temp.i[2]);
        break;
      }
    }
  }
}

function 
buyItem(itemNameitemPriceitemWeapon)
{
  if (
player.findWeapon(temp.itemWeapon) != false)
  {
    return;
  }
  if (
player.rupees temp.itemPrice)
  {
    
player.chat "You don't have enough money!";
    return;
  }
  
  
player.rupees -= temp.itemPrice;
  
player.addWeapon(temp.itemWeapon;
  
  
player.chat "You have bought" SPC temp.itemName SPC "for" SPC temp.itemPrice SPC "dollars!";



Inverness 09-11-2008 03:04 AM

Why are you tokenizing the array in buyItem()?

Also, since findweapon() is returning an object methinks you should compare it to null not false so its clear that it is not boolean.

Frankie 09-11-2008 03:05 AM

not sure. i'll change it

I also took the findweapon part from andy's script because I've never really done anything like that before :P

[email protected] 09-11-2008 08:59 AM

nice method at Frankie, would have made it a temp. flag and parsed the array as an array, not individual, but other than that it's cool ^^ ^^

Inverness 09-11-2008 09:27 AM

PHP Code:

function onCreated() {
  
this.saleitems = {
    {
"headbob"100"Event/Headbob"},
    {
"anotheritem"250"Event/Item"},
    {
"dance item"50"Event/Dance"}
  };
}
function 
onPlayerChats() {
  if (
player.chat.starts("buy ")) {
    for (
temp.ithis.saleitems) {
      if (
player.chat.substring(4) == temp.i[0]) {
        
this.buyitem(temp.i.link());
        break;
      }
    }
  }
}
function 
buyitem(item) {
  if (
player.findweapon(temp.item[2]) != null) {
    return 
false;
  }
  if (
player.rupees temp.item[1]) {
    
player.chat "You don't have enough money!";
    return 
false;
  }
  
player.rupees -= temp.item[1];
  
player.addweapon(temp.item[2]);
  
player.chat format("You have bought <percentsign>s for $<percentsign>s"temp.item[0], temp.item[1]);
  return 
true;


You would replace <percentsign> with an actual percent sign because the stupid forum has issues when you try to put it in a post.

Tigairius 09-11-2008 05:26 PM

Why are you giving him a bunch of confusing methods, the kid's trying to learn how to script, not asking the best way to script his system.
Try this, Gulthex:
PHP Code:

triggeraction(0.50.5"buy"null); 

Also, here you are mixing GS1 with GS2 again... do this:
PHP Code:

function onCreated() { 
  
setshape(13232); 


function 
onActionbuy() { 
  if (
player.rupees >= 100) { 
    
addweapon("Event/Headbob"); 
    
player.rupees -= 100
  } 



[email protected] 09-11-2008 06:51 PM

Quote:

Originally Posted by Tigairius (Post 1422343)
Why are you giving him a bunch of confusing methods, the kid's trying to learn how to script, not asking the best way to script his system.

That doesn't make sense, we were helping him by teaching him a better method.

Chompy 09-11-2008 06:52 PM

Quote:

Originally Posted by [email protected] (Post 1422371)
That doesn't make sense, we were helping him by teaching him a better method.

Wut?

Quote:

Originally Posted by [email protected] (Post 1422055)
Don't use that
Use this

HTML Code:

...

Very "teachy" :p

Chompy 09-11-2008 07:02 PM

Judging from what scripts he have provided and scripting questions asked, I can safetly say that he is new to gscript2.

Frankie 09-11-2008 07:34 PM

I made my code because I was bored hehe

Inverness 09-11-2008 08:26 PM

Quote:

Originally Posted by [email protected] (Post 1422371)
That doesn't make sense, we were helping him by teaching him a better method.

He needs to understand the basics first.


All times are GMT +2. The time now is 05:56 PM.

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