Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-31-2011, 09:07 PM
Equinox Equinox is offline
Registered User
Equinox's Avatar
Join Date: Jan 2011
Posts: 13
Equinox is on a distinguished road
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?
Reply With Quote
  #2  
Old 01-31-2011, 09:18 PM
MattKan MattKan is offline
the KattMan
Join Date: Aug 2010
Location: United States
Posts: 1,325
MattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to behold
Send a message via AIM to MattKan
Quote:
Originally Posted by Equinox View Post
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?
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
__________________
Quote:
Originally Posted by Satoru Iwata
On the other hand, free-to-play games, if unbalanced, could result in some consumers paying extremely large amounts of money, and we can certainly not expect to build a good relationship with our consumers in this fashion. In order to have a favorable long-term relationship, we would like to offer free-to-play games that are balanced and reasonable.
Quote:
Originally Posted by Unximad
Eurocenter Games remains attached to the values of indies game developer and to the service our playerbase community.

Last edited by Tigairius; 02-01-2011 at 12:36 AM.. Reason: Fixed error.
Reply With Quote
  #3  
Old 01-31-2011, 09:39 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
if your going to do a "system" for buying items, you could use a gui window instead

there's too muh player commands
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #4  
Old 01-31-2011, 09:48 PM
Equinox Equinox is offline
Registered User
Equinox's Avatar
Join Date: Jan 2011
Posts: 13
Equinox is on a distinguished road
ok thanks now it's working
Reply With Quote
  #5  
Old 01-31-2011, 10:14 PM
Equinox Equinox is offline
Registered User
Equinox's Avatar
Join Date: Jan 2011
Posts: 13
Equinox is on a distinguished road
ok now its working
Reply With Quote
  #6  
Old 01-31-2011, 11:21 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
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
__________________
Reply With Quote
  #7  
Old 02-01-2011, 12:44 AM
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
hmm
You shouldn't name functions with an on prefix. That implies that it is an event.
__________________
Reply With Quote
  #8  
Old 02-01-2011, 12:49 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by cbk1994 View Post
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #9  
Old 02-01-2011, 03:56 AM
Cloven Cloven is offline
Delteria
Cloven's Avatar
Join Date: Dec 2006
Location: Florida, United States
Posts: 542
Cloven has a spectacular aura about
Send a message via AIM to Cloven
Quote:
Originally Posted by Tigairius View Post
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... @ you.


Reply With Quote
  #10  
Old 02-01-2011, 12:42 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 Cloven View Post
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?
__________________
Reply With Quote
  #11  
Old 02-01-2011, 01:03 PM
Fulg0reSama Fulg0reSama is offline
Extrinsical Anomaly
Fulg0reSama's Avatar
Join Date: Sep 2009
Location: Ohio
Posts: 3,049
Fulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant future
Quote:
Originally Posted by cbk1994 View Post
How does "on" make a function more readable?
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.
__________________

Careful, thoughts and opinions here scare people.
Reply With Quote
  #12  
Old 02-01-2011, 03:50 PM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
Quote:
Originally Posted by cbk1994 View Post
How does "on" make a function more readable?
cause then you can capitalize the letter after! :P

onSomeFunction()

-or-

someFunction()

pointless, I know. xP
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #13  
Old 02-04-2011, 11:18 PM
MattKan MattKan is offline
the KattMan
Join Date: Aug 2010
Location: United States
Posts: 1,325
MattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to behold
Send a message via AIM to MattKan
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.
Attached Files
File Type: txt BombPurchasing.txt (2.3 KB, 181 views)
__________________
Quote:
Originally Posted by Satoru Iwata
On the other hand, free-to-play games, if unbalanced, could result in some consumers paying extremely large amounts of money, and we can certainly not expect to build a good relationship with our consumers in this fashion. In order to have a favorable long-term relationship, we would like to offer free-to-play games that are balanced and reasonable.
Quote:
Originally Posted by Unximad
Eurocenter Games remains attached to the values of indies game developer and to the service our playerbase community.
Reply With Quote
  #14  
Old 02-04-2011, 11:21 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Should check to see how many rupees is decreased serverside instead of clientside.
Reply With Quote
  #15  
Old 02-04-2011, 11:23 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Cubical View Post
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
Reply


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 04:09 PM.


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