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 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, 185 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
  #2  
Old 02-04-2011, 11:30 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 MattKan View Post
PHP Code:
function onActionServerSide(action) {
  switch (
action) {
    case 
"DecRup":
      
player.rupees -= params[1];
    break; 
This in itself ruins the script. Not only does this allow you to set your own price via Cheat Engine or the like, but you could even set the price to a negative value in order to spawn money.

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

Always do checks like this on serverside. A player could change the amount of darts to gain, the number of rupees to pay, or even negate the trigger entirely. The proper way to do it would be to send a trigger with a parameter "item" (which is either "bomb" or "arrow"), and only add the bombs/arrows on serverside. This ensures that nothing can be tampered with. As a general rule, assume that any script you write on clientside can be changed by a hacker.

An example of how it should be done:
PHP Code:
function onActionServerSide(actionitem) { 
  if (
action == "purchase") {
    if (! (
item in {"bombs""darts"})) {
      return; 
// player sent a non-existing item
    
}
    
    if (
player.rupees 10) {
      return 
player.chat "You need at least 10 rupees!";
    }
    
    
player.rupees -= 10;
    
    if (
item == "bombs") {
      
player.bombs += 10;
    } else if (
item == "darts") {
      
player.darts += 20;
    }
  }


//#CLIENTSIDE 
// all of the GUI stuff here

function Bomb_Button1.onAction() { 
  
triggerServer("gui"this.name"purchase""darts");


function 
Bomb_Button2.onAction() { 
  
triggerServer("gui"this.name"purchase""bombs");

edit: Tig and Cubical beat me to it, but this should help as well
__________________
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 08:25 PM.


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