Attribute value help

Basicly, an npc needs time to make something for player (object already made just invisible untill player makes 3 interactions of thier leisure.) So far i have the following italics

Vendor: "Quality takes time, come back later."
set object ITEM attribute progress value 1

Each time player interacts with an npc, the value is raised by 1 regardless of order.

I want the vendor to give player the item only when the value is at least 5
After that, the atribute will be useless.

How whould i set that up?


Something like this?

npc.value = 0
player.money = 5
if (npc.value >= 5) {
  if (player.money >= 5) {
    msg ("You bought a sandwhich.")
    player.money = player.money - 5
    AddToInventory (Sandwhich)
    npc.value = npc.value + 1
  }
}
else {
  msg ("You don't have enough of a bond to buy a sandwhich.")
  npc.value = npc.value + 1
}

No money involved. Vender will just give it to player.
Atribute value affected by n0c interactions.


The script when you interact on the NPC would be something like:

if (GetBoolean (frob, "visible")) {
  msg (CapFirst(this, "has") + " already made a {object:frob} for you.")
}
else if (not HasInt (this, "progress")) {
  msg ("You ask " + GetDisplayName(this) + " to make you a frob, and " + WriteVerb(this, "start") + " work.")
  this.progress = 1
}
else if (this.progress >= 5) {
  msg ("“Ah, I just finished!” " + WriteVerb(this, "say") + " with a smile, and hands you a {object:frob}.")
  frob.visible = true
}
else {
  msg ("“I'm still working on it. Good work takes time.”")
  this.progress = this.progress + 1
}

Boolean? HasInt? ve never tried thosebefore, so i was hoping to use atribute, but i could try that...


Boolean? HasInt? ve never tried thosebefore, so i was hoping to use atribute, but i could try that...

A boolean is an attribute that's set to true or false.

I used GetBoolean to check if the object is already visible; you might not need to do that.

HasInt checks if an attribute exists and contains a number. This is often a quick way to check if a process has started.

I also used WriteVerb a few times, which isn't really necessary but makes the code look a little neater (it comes up with strings like "he says" or "they say" as appropriate, so you don't need to change the script if you use it for a different NPC. It's a good habit to get into)


So HasInt... can i use that tk run a script it the value is </>a given number?


So HasInt... can i use that tk run a script it the value is </>a given number?

No, HasInt checks that an integer attribute exists.

It's a good idea to check if the attribute exists before you check its value. Good habit to get into, because it makes sure you won't get an error message for an attribute that hasn't been created yet. You use HasInt to check if the attribute is there, and then use > or < to check what its value is.


Alright, one last attempt.
Create a command, call it whatever you like.
Here's the code:

if (Got(Sandwhich)) {
  msg ("You have the sandwhich already!")
}
else {
  if (npc.value >= 5) {
    msg ("You bought a sandwhich.")
    npc.value = npc.value + 1
    AddToInventory (Sandwhich)
  }
  else {
    msg ("You don't have enough credit to buy a sandwhich.")
    npc.value = npc.value + 1
  }
}

(Object.AtributeName >= 5)

Causes internal error


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums