![]() |
Problem using a level NPC that's joined to a class
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:
PHP Code:
|
Quote:
|
Quote:
Just wondering; what do you think about the structure of our shop system? Any thoughts or suggestions? |
Box formatting is the devil.
|
Quote:
With this type of loop where you're accessing 'i' it would take less script time to do: PHP Code:
|
You forgot temp.s on your is.
|
Quote:
Could you please expand or elaborate a bit on the meaning of Box formatting? :) I suppose our structure is not that good? And thanks for all the replies and comments so far! |
PHP Code:
|
Box formatting is the ugliest thing to read through ever, not to mention how it expands the code for no good reason. :rolleyes:
|
Hi!
This is what we've got so far. We have now updated the script so that our trigger action triggers onActionBuyItem. Although, we have a variable called this.itemselected, which will store information regarding the currently selected item. this.itemselected contains one of the two available gui controls: Shop_Item_Fireball or Shop_Item_Sword. The gui looks just fine when running the script. We can click on the different items and the currently selected item changes. Although, when we trigger the server via triggeraction, the gui control which is stored in this.itemselected disappears. We've noticed that this happens when we use this.itemselected as a parameter for triggeraction. If we use a string, for example "higuys" as parameter to the triggeraction everything works just fine. I get a feeling that we're not ready to build a shop system! PHP Code:
|
If I understand it correctly, this.itemselected is a GUI control, yeah? GUI controls are a clientsided object and thus can't be read on serverside.
|
Yepp. Since this.itemselected contains a gui control. But when I add one more parameter to the triggeraction it works just fine.
triggeraction(this.x + 0.5, this.y + 0.5, "BuyItem", this.itemselected, null); Any thoughts regarding that? |
You can cut down on your 'itemSelected' code with catchevent. I.e:
PHP Code:
It would also fix your problem where you're passing an object to the server-side instead of string. Objects behave weirdly (as you can see) resulting in their name getting passed or it passes null/0. |
Thank you very much!
I was a little bit concerned about how to solve that problem. I'm also a little bit concerned about where to put the raw data. I would like to create an array consisting of arrays to keep track of all the items: //{Gui name, name, price} this.shop_item_fireball = {"Shop_Item_Fireball", "Fireball", 30}; and then create an array called this.listofItems = {this.shop_item_fireball}; When this is done on the server side I would like to pass that information to the clientside so that the GUI can be built. Would that be inefficient? Or what do you think? |
Your best bet would be to do something like this:
PHP Code:
Then in your shopkeeper class just process the this.items array and create the list you need. Also on the server-side verify their purchase against the server-side items array. |
All times are GMT +2. The time now is 04:14 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.