
01-14-2014, 04:25 AM
|
Registered User
|
Join Date: Jul 2006
Posts: 31
|
|
Tim's method would work, but it still isn't ideal. In fact, I'd go so far as to say it's downright bad. Putnpc2's tend not to destroy 100% responsibly, so you'd need to code in redundant garbage collecting for them. That's also a lot of unnecessary nonsense.
Stefan/fp4 are right on the money here. The way you would do it is as follows:
(in weapon)
(on serverside):
onplayerenters -> recognize shop level -> get NPC list from SQL DB -> triggerclient that info to the weapon
(on clientside):
onactionclientside -> the item list is a param -> use that item list to set up what NPCs the shop should be selling in the GUI or for the "laid out" npcs (more on that later)
You could optionally remove it as a weapon NPC entirely and just make it a level NPC or DB NPC as follows:
(serverside):
onplayerenters -> retrieve what NPCs that player should have from an SQL DB -> save the list of those npcs to the player (eg, player.client.npcs)
(clientside, in same level npc):
onplayerenters -> timeout until the player.client.npcs flag is set -> once set, take that list of NPCs as the list of NPCs the player can buy -> you can stop timeout'ing now. The timeout should only occur 0-2 times, just long enough for the info to reach you from the server. -> clear the client. flag now, otherwise the flag will conflict next time you enter the level.
Note: While using client. flag is obviously insecure, that shouldn't matter because purchasing the NPC will send a trigger to serverside, which, for security purposes, needs to verify (again) that the player is authorized to purchase that NPC, anyway.
You said you want to lay out the items in the level itself, rather than using a GUI. That's a bit harder but still not impossible. For example:
1. Have ~10 generic "shop item" NPCs that haven't had their this.item defined yet (and they're invisible) in the level. I say "10" but you can use whatever you feel is the "limit" for NPCs. If it's going to sell 30 different NPCs, you can put 30. It doesn't matter.
2. Use the methods I discussed before (either or) to get your "list" (ie, string array) of NPC names. You can optionally pass icons as well, or the icons can be included in the clientside ahead of time, corresponding with names of course.
3. Do something like: "for (temp.npc: npcs) { if (npc.isItem && npc.itemName == nil) {" -- that will find NPCs that are those "invisible items" I told you about (as long as they have this.isItem = true; in their script) and will only define them to be an NPC if they haven't already been defined (assuming definition of this.itemName).
An even slightly more efficient way of doing that would be for the "item" NPCs to load themselves into a level. array on created (in clientside), and then the #3 step can loop among something like "for (temp.npc: level.items) {" rather than looping over ALL level NPCs.
Any of those methods would be greatly superior to using putnpc2. |
|
|