Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Arrow buying (https://forums.graalonline.com/forums/showthread.php?t=134261911)

Equinox 01-31-2011 09:07 PM

Arrow buying
 
I'm not very good at scripting so...
im trying to make a npc in a shop that takes gralats from you when you say Buy arrows. the script is like this:

if (player.chat=Buyarrows);
(playerdarts += 30);
(tokenize 10);
say2 here you go.;

It gives me the arrows but it does not deduct it from my gralats.
Help please?:confused:

MattKan 01-31-2011 09:18 PM

Quote:

Originally Posted by Equinox (Post 1626967)
I'm not very good at scripting so...
im trying to make a npc in a shop that takes gralats from you when you say Buy arrows. the script is like this:

if (player.chat=Buyarrows);
(playerdarts += 30);
(tokenize 10);
say2 here you go.;

It gives me the arrows but it does not deduct it from my gralats.
Help please?:confused:

This should work:

PHP Code:

function onPlayerChats()
{
 if (
player.chat == "Buyarrows")
  {
   
player.darts += 30;
   
player.rupees -= 30;
   
say2("Here you go!");
  }


However, that raises another issue. Players will be able to buy darts even if they have no gralats. So you have to add an if statement to check for that.

New Script:

PHP Code:

function onPlayerChats()
{
 if (
player.chat == "Buyarrows")
  {
   if (
player.rupees >= 30)
    {
     
player.darts += 30;
     
player.rupees -= 30;
     
say2("Here you go!");
    }
   else
    {
     
say2("You do not have enough gralats.");
    }
  }


That ought to stop players from buying arrows when they have no money.

Oh, and that is GS2, not GS1 which you used in your post. GS2 works better, so I suggest you learn that instead. There are some guides for GS2 scripting here: http://wiki.graal.net/index.php/Creation/Dev/GScript

Deas_Voice 01-31-2011 09:39 PM

if your going to do a "system" for buying items, you could use a gui window instead :)

there's too muh player commands :(

Equinox 01-31-2011 09:48 PM

ok thanks now it's working

Equinox 01-31-2011 10:14 PM

ok now its working

xAndrewx 01-31-2011 11:21 PM

hmm

HTML Code:

function onPlayerChats() {
  if (player.chat != "buy arrows") return;
 
  player.chat = this.onBuyArrows();
}
function onBuyArrows() {
  if (player.rupees < 30) return "You don't have enough money! You need 30 gralats";
 
  player.darts += 30;
  player.rupees -= 30;

  return "Yaaaay!! Thanks tuff guy";
}

quite funky

cbk1994 02-01-2011 12:44 AM

Quote:

Originally Posted by xAndrewx (Post 1626985)
hmm

You shouldn't name functions with an on prefix. That implies that it is an event.

Tigairius 02-01-2011 12:49 AM

Quote:

Originally Posted by cbk1994 (Post 1627002)
You shouldn't name functions with an on prefix. That implies that it is an event.

I agree here, usually events only start with "onMyFunction." If it's simply a method to purchase an item you should be using "function purchaseItem" instead of "function onPurchaseItem" unless you trigger the event from trigger() or a scheduleevent(). Naming a function with the prefix of "on" basically is saying you don't expect a return value.

Cloven 02-01-2011 03:56 AM

Quote:

Originally Posted by Tigairius (Post 1627004)
I agree here, usually events only start with "onMyFunction." If it's simply a method to purchase an item you should be using "function purchaseItem" instead of "function onPurchaseItem" unless you trigger the event from trigger() or a scheduleevent(). Naming a function with the prefix of "on" basically is saying you don't expect a return value.

I generally agree, though I don't think it's a big deal really...

Some people prefix their functions in that fashion for added readability. This is largely because many jerks create unintuitive names for functions, or their code is haphazardly styled. In those cases the 'Find' feature can be rendered almost useless. As such, scanning for the 'on' prefix can be of use in those cases.

For people who practice poor function and/or variable naming... !pissed! @ you.


:D

cbk1994 02-01-2011 12:42 PM

Quote:

Originally Posted by Cloven (Post 1627029)
I generally agree, though I don't think it's a big deal really...

Some people prefix their functions in that fashion for added readability. This is largely because many jerks create unintuitive names for functions, or their code is haphazardly styled. In those cases the 'Find' feature can be rendered almost useless. As such, scanning for the 'on' prefix can be of use in those cases.

How does "on" make a function more readable? :oo:

Fulg0reSama 02-01-2011 01:03 PM

Quote:

Originally Posted by cbk1994 (Post 1627122)
How does "on" make a function more readable? :oo:

I think he means if it looks the same as the rest people will recognize it as to what it is.
Also makes narrowing down for functions easier.

MrOmega 02-01-2011 03:50 PM

Quote:

Originally Posted by cbk1994 (Post 1627122)
How does "on" make a function more readable? :oo:

cause then you can capitalize the letter after! :P

onSomeFunction()

-or-

someFunction()

pointless, I know. xP

MattKan 02-04-2011 11:18 PM

1 Attachment(s)
I decided to help further by making you a GUI shopping system in which you can purchase bombs and arrows:

PHP Code:

function onActionServerSide(action) {
  switch (
action) {
    case 
"DecRup":
      
player.rupees -= params[1];
    break;
  }
}

//#CLIENTSIDE
function onCreated() {
 new 
GuiWindowCtrl("Bomb_Window") {
   
clientextent "300,200";
   
profile GuiBlueWindowProfile;
   
screenwidth/2-150;
   
screenheight/2-100;
   
visible true;

   
text "Get your bombs and arrows!";
   
canmove true;
   
canresize false;
   
canmaximize false;
 
   new 
GuiShowImgCtrl("Bomb_Img") {
     
55;
     
80;
     
width 32;
     
height 32;
     
this.image "bomb.png";
    }
   new 
GuiShowImgCtrl("Bomb_Img2") {
     
210;
     
80;
     
width 32;
     
height 32;
     
this.image "arrow.png";
    }
 
   new 
GuiMLTextCtrl("Bomb_Text") {
     
profile GuiBlueMLTextProfile;
     
30;
     
35;
     
width 430;     
     
height 50;
     
text "<font size=28><font color=white><b>Bombs:</b></font></font>";
    }
   new 
GuiMLTextCtrl("Bomb_Text2") {
     
profile GuiBlueMLTextProfile;
     
10;
     
130;
     
width 430;
     
height 50;
     
text "<font size=13.5><font color=white><b>10 Bombs for 10 Gralats.</b></font></font>";
    }
   new 
GuiMLTextCtrl("Bomb_Text3") {
     
profile GuiBlueMLTextProfile;
     
170;
     
35;
     
width 430;
     
height 50;
     
text "<font size=28><font color=white><b>Arrows:</b></font></font>";
    }
   new 
GuiMLTextCtrl("Bomb_Text4") {
     
profile GuiBlueMLTextProfile;
     
160;
     
130;
     
width 430;
     
height 50;
     
text "<font size=13.5><font color=white><b>20 Arrows for 10 Gralats.</b></font></font>";
    }
   new 
GuiButtonCtrl("Bomb_Button1") {
     
profile GuiBlueButtonProfile;
     
20;
     
155;
     
width 100;
     
height 30;
     
text "Purchase";
    }
   new 
GuiButtonCtrl("Bomb_Button2") {
     
profile GuiBlueButtonProfile;
     
170;
     
155;
     
width 100;
     
height 30;
     
text "Purchase";
    }
  }
}

function 
Bomb_Button1.onAction() {
  
//Button "Purchase"
 
if (player.rupees >= 9) {
   
triggerserver("gui",this.name,"DecRup",10);
   
player.bombs += 10;
  }else
    
player.chat "Insufficient Funds";
}

function 
Bomb_Button2.onAction() {
  
//Button "Purchase"
 
if (player.rupees >= 9) {
   
triggerserver("gui",this.name,"DecRup",10);
   
player.darts += 20;
  }else
    
player.chat "Insufficient Funds";


I've also included a .txt file.

Cubical 02-04-2011 11:21 PM

Should check to see how many rupees is decreased serverside instead of clientside.

Tigairius 02-04-2011 11:23 PM

Quote:

Originally Posted by Cubical (Post 1627939)
Should check to see how many rupees is decreased serverside instead of clientside.

I would check both clientside and serverside. That way if they aren't hacking, it won't send a needless trigger to the server.


All times are GMT +2. The time now is 11:40 AM.

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