ID:154593
 
I am trying to add a verb that will allow you to click on /mob/merchant and have it throw up a stat panel containing the contents of that merchant so you can see what is available for purchase. Any help would be appreciated, please.
On 12/9/00 3:31 pm Kidknee wrote:
I am trying to add a verb that will allow you to click on /mob/merchant and have it throw up a stat panel containing the contents of that merchant so you can see what is available for purchase. Any help would be appreciated, please.

I don't think you can do that, actually. Maybe someone else could help you out, though...
On 12/9/00 3:31 pm Kidknee wrote:
I am trying to add a verb that will allow you to click on /mob/merchant and have it throw up a stat panel containing the contents of that merchant so you can see what is available for purchase. Any help would be appreciated, please.

Offhand, this is one way I can think of to do it:

mob/var/viewing

client/Stat()
if (viewing) statpanel("For sale",viewing.contents)

mob/merchant/Click()
usr.viewing = src
usr.client.statpanel = "For sale"

When you want the panel to go away again, just make usr.viewing = null.

Z

In response to Spuzzum
On 12/9/00 3:46 pm Spuzzum wrote:
On 12/9/00 3:31 pm Kidknee wrote:
I am trying to add a verb that will allow you to click on /mob/merchant and have it throw up a stat panel containing the contents of that merchant so you can see what is available for purchase. Any help would be appreciated, please.

I don't think you can do that, actually. Maybe someone else could help you out, though...


Shame on you Spuzz! Of course you can!

Some statpanel behavior is a bit like magic, in that you don't explicitly call an AddStatPanel function or anything. Instead, just testing for the existance of a statpanel will create that panel. Here is an example stat() function from one of my games:

Stat()
if (statpanel("Status"))
stat("Money", money)
stat("Health", health_meter)
stat("Weapon", weapon)


if (statpanel("Inventory"))
stat(contents)

This code causes Status and Inventory panels to be created, and fills them only if a player is looking at them.

If you use that code, players will only be able to see their own stats. To let a player see someone else's stats, you set that player's client.statobj to the desired mob. Here is a quick untested example of what you want:

Somewhere in your code (when the player uses the verb or targets the merchant or something) you need to put in this:

// This player is targetting someone, so set the statobj to the targetted mob.
var/mob/target = // However your game decides this
client.statobj = target

mob
Stat()
// This goes to anyone whose client.statobj is set to me.
if (statpanel("Inventory"))
stat(contents)

This should give you what you want, as long as you have some way of knowing what the targetted mob is.
In response to Zilal
On 12/9/00 3:54 pm Zilal wrote:
On 12/9/00 3:31 pm Kidknee wrote:
I am trying to add a verb that will allow you to click on /mob/merchant and have it throw up a stat panel containing the contents of that merchant so you can see what is available for purchase. Any help would be appreciated, please.

Offhand, this is one way I can think of to do it:

mob/var/viewing

client/Stat()
if (viewing) statpanel("For sale",viewing.contents)

mob/merchant/Click()
usr.viewing = src
usr.client.statpanel = "For sale"

When you want the panel to go away again, just make usr.viewing = null.

Z


We posted solutions at the same time...Z's solution works too, and might be more flexible because it avoids the hassle of switching client.statobj around and lets you still see your own stats too if you want.
In response to Deadron
Shame on you Spuzz! Of course you can!

Some statpanel behavior is a bit like magic, in that you don't explicitly call an AddStatPanel function or anything. Instead, just testing for the existance of a statpanel will create that panel. Here is an example stat() function from one of my games:

Yeah, but what I meant was that it isn't possible to simply add a panel. You have to define the panel at compile-time that appears at run-time. Personally speaking, though, Zilal's method is best. Changing the statobj changes the stat panels entirely, while checking for the existence of an object and then creating a panel if it does is a lot more fluid (though a little less object-oriented).

Zilal's code did have an error... here's the fixed version:

mob/var/mob/merchant/viewing

client/Stat()
if (viewing) statpanel("For sale",viewing.contents)

mob/merchant/Click()
usr.viewing = src
usr.client.statpanel = "For sale"


The error was that she had mob/var/viewing as typeless (var/viewing) instead of as a mob var (var/mob/merchant/viewing). Otherwise you would've had to use a ':' instead of a '.' for the viewing.contents, which would make it highly un-object-oriented.
In response to Spuzzum
On 12/9/00 8:01 pm Spuzzum wrote:
Zilal's code did have an error...
The error was that she had mob/var/viewing as typeless (var/viewing) instead of as a mob var (var/mob/merchant/viewing). Otherwise you would've had to use a ':' instead of a '.' for the viewing.contents, which would make it highly un-object-oriented.

Well, I did it that way on purpose, but I was thinking of my own code, where I might want to view the contents of any mob or object. Uh, that means in my case the error was that the . should have been a :. But your way is, of course, safer.

Deadron wrote:
if (statpanel("Inventory"))
stat(contents)

This code causes Status and Inventory panels to be created, and fills them only if a player is looking at them.

Does the "if (statpanel("Inventory"))" make it so that they're only filled if a player is looking at them? Does that save CPU?

Z
In response to Zilal
On 12/9/00 9:23 pm Zilal wrote:
This code causes Status and Inventory panels to be created, and fills them only if a player is looking at them.

Does the "if (statpanel("Inventory"))" make it so that they're only filled if a player is looking at them? Does that save CPU?

Yup, and it saves quite a lot of CPU. If you have any degree of richness to your stat panels, filling all of them every .8 seconds for every player is expensive.