Hey there!
This is me and my friend's first attempt at GS2. This is what we've got so far. We're just wondering; are we on the right track here? We have encountered some problem with triggeraction when trying to trigger serverside from clientside, in a level NPC.
Any ideas or suggestions on what to improve or totally change?
In case the aweful script does not tell; we're trying to create a shop system..or something closely remote to one...
Help is very much appreciated, thanks!
Class:
PHP Code:
function onActionBuyItem()
{
player.rupees = 0;
}
function onCreated() {
this.setShape(1, 32, 32);
this.dontblock();
}
//#CLIENTSIDE
function onPlayerTouchsMe()
{
new GuiBitmapBorderCtrl("Shop_Window")
{
this.profile = GuiBitmapBorderProfile;
this.width = screenwidth / 2;
this.height = screenheight / 2;
this.x = screenwidth / 2 - this.width / 2;
this.y = screenheight / 2 - this.height / 2;
this.canmove = false;
this.canresize = false;
this.makefirstresponder(true);
new GuiButtonCtrl("Shop_Button")
{
width = 100;
height = 40;
x = Shop_Window.width / 2 - this.width / 2;
y = Shop_Window.height - this.height - 10;
text = "Buy";
}
new GuiShowImgCtrl("Shop_Item_Fireball")
{
x = 20;
y = 20;
width = 60;
height = 60;
this.imageselected = "split_fireball_selected.png";
this.imagenotselected = "split_fireball.png";
this.image = this.imageselected;
this.price = 20;
}
new GuiShowImgCtrl("Shop_Item_Sword")
{
x = Shop_Item_FireBall.x + Shop_Item_Fireball.width + 20;
y = 20;
width = 60;
height = 60;
this.imageselected = "split_sword_selected.png";
this.imagenotselected = "split_sword.png";
this.image = this.imagenotselected;
this.price = 30;
}
}
this.listofitems = {Shop_Item_Fireball, Shop_Item_Sword};
this.itemselected = this.listofitems[0];
}
function onMouseDown()
{
if(!((mousescreenx in |Shop_Window.x, Shop_Window.x + Shop_Window.width|)
&&(mousescreeny in |Shop_Window.y, Shop_Window.y + Shop_Window.height|)))
{
Shop_Window.destroy();
}
}
function Shop_Button.onMouseDown()
{
triggeraction(this.x + 0.5, this.y + 0.5, "ButItem", null);
}
function Shop_Button.onMouseUp()
{
Shop_Window.makefirstresponder(true);
}
function Shop_Item_Fireball.onMouseDown()
{
for(i = 0; i < this.listofitems.size(); i ++)
{
this.listofitems[i].image = this.listofitems[i].imagenotselected;
if(this.listofitems[i] == Shop_Item_Fireball)
this.itemselected = this.listofitems[i];
}
Shop_Item_Fireball.image = Shop_Item_Fireball.imageselected;
}
function Shop_Item_Sword.onMouseDown()
{
for(i = 0; i < this.listofitems.size(); i ++)
{
this.listofitems[i].image = this.listofitems[i].imagenotselected;
if(this.listofitems[i] == Shop_Item_Sword)
this.itemselected = this.listofitems[i];
}
Shop_Item_Sword.image = Shop_Item_Sword.imageselected;
}
NPC:
PHP Code:
this.join("shopkeeper");