Check for equipped weapon

Avantar
I hope this is not too a stupid question but I have started with my combat system and first off decided on how I would equip and unequip weapons...lol
So I am struggling once more. I have made the decision of being able to equip a weapon either in my left hand or right hand. Thus I made an Object Type called weapon, verbs for equipl and equipr as well as attributes for weapon type with the same names on which I run scripts. Having a look at the Wiki, I managed that fine as well as adding 'EquipL and EquipR' to the weapon in question and displaying what you have in your left or right hand or both.
Problem is - If I have a particular weapon already equipped, I do not want to be able to equip the same weapon in the other hand. Anyway: I have messed up the code so good that it probably isn't code anymore and I will understand some chuckles. I guess the problem is, I have no idea how to check if I do have the weapon that I want to equip already equipped. This is what I have for attribute equipl:
if (this.parent = game.pov) {
if (not game.pov.equipped = null and not this.alias=game.pov.equipped) {
msg ("You put away your " + game.pov.equipped.alias + " and draw your " + this.alias + ".")
game.pov.equipped.inventoryverbs = Split ("Look at;Drop;Equip(LHand)", ";")
}
else {
msg ("You draw your " + this.alias + ".")
}
game.pov.equipped = this
this.inventoryverbs = Split ("Look at;Drop;Unequip(LHand)", ";")
game.pov.equippedstatusl = "Wielding(LHand): " + this.alias
}
else if (this.alias=game.pov.equipped) {
msg ("Already equipped")
}
else {
msg ("You don't have it.")
}


A little nudge in the right direction would help greatly. :?
PS: equipr attribute script is pretty much the same. I have two status attributes - one for the left hand and one for the right.
I have looked at some combat systems from Pertex - the library file is a bit beyond me

HegemonKhan
See if you can work with (make sense of ~ understand ~ learn) Pixie's and~or Chase's Libraries:

Chase's Wearables Library:

viewtopic.php?f=18&t=2901

(he~she makes equipment scripting look so easy, argh! hehe)

Pixie's Libraries and~or Guides:

viewtopic.php?f=18&t=2567

http://quest5.net/wiki/Simple_Combat_System_(Advanced)

http://quest5.net/wiki/Using_Types_and_Tabs_(Advanced)
(see the very bottom for the spell library files ~ they could help you with coding ideas, functionality, and logic with equipment)

and Pertex' Combat Library:

(like you already mentioned using)

ya, it is a beast, took me a long time to understand his combat coding ~ I still don't quite follow~get how his equipment and etc works though, lol.

if interested, you can see my learning of quest coding progress, including on the last few pages, my struggle (and big triumph) with understanding Pertex' Combat Library and creating my own combat code based on his combat coding structure:

viewtopic.php?f=10&t=3348&hilit=hk+noob+help+me+thread

may be good for a laugh, at least, hehe :D

------------

I too am trying to build~create my own equipment (as part of my work on a very ambitious combat system, lol) scripting, so if you're interested, I'd love to share ideas+coding and work together, hehe.

HegemonKhan
basically, how Chase does it (and a few of my own ideas added in), CONCEPTUALLY, is this way:

<equipment_slots type="simplestringlist"></equipment_slots>
<equipment_layer type="int"></equipment_layer>

equipment~body "slots":

headwear (hat, helmet), facewear (glasses, mask), earwear (jewelry: earrings), neckwear (jewelry: necklaces, or tie, bowtie), shoulderwear (pauldrons), armwear (vambraces, gauntlets), handwear (gloves, gauntlets), fingerwear (jewelry: rings), left_handwear (shield or secondary weapon), right_handwear (primary weapon), chestwear (body armor: mail, or shirt), backwear (cape, cloak, backpack, arrow quiver~case), waistwear (fraulds, tassets, shorts), legwear (grieves, tassets), footwear (clothing: boots, shoes, or armor: boots)

(or you can further break up the slots that you are able to, into left and right sides and~or upper and lower too: shoulders, arms, legs, ears, and feet)

create the "gear_name (equipped)" alias status for quest to check if you're "wearing" the gear or not.

lastly, to compare your inventory objectlist's "equipment_slots" to your equipped object's "equipment_slots", if they have~use the same "equipment_slot" (such as headwear), then you (can further) check their "equipment_layers" too, to see if you allow the object to be equipped or not (and~or tell why not). The "equipment_layer" check method prevents you from equipping more than one object (to that layer ~ ie integer setting), though what you want requires a bit more work, but it shouldn't be too hard to construct or figure out, once you understand this stuff: ie you'd just have to specifically check by comparing your two "equipment_slots" of "left_handwear" and "right_handwear".

This is a bit complicated and difficult to understand the methodology, as it took me quite a while myself to get it. The main aspect is comprehending that you compare the inventory object list with the specific object (or comparing one object's "equipment_slot" with another object's "equipment_slot") that you're trying to act upon (wear~equip) or to prevent from acting upon.

jaynabonne
Avantar, you have a fundamental problem, in that you have only have "game.pov.equipped", which is just a single attribute and can reference only a single object. So you will not be able to have weapons (or items) equipped in both hands, as you can't track them.

What you want is two "equipped" attributes, one for the left hand and one for the right hand (e.g. equippedl and equippedr, following the pattern you've set up). Then to see if an item is equipped in the left hand, check if "this = game.pov.equippedl" and similarly for the right (equippedr).

HegemonKhan
stringlists are a great way to reduce the amount of attributes and~or object types:

instead of "left_hand_equipped=false" and "right_hand_equipped=false" attributes, I can do:

<equipment_slots type="simplestringlist">left_hand</equipment_slots>
<equipment_slots type="simplestringlist">right_hand</equipment_slots>
<equipment_slots type="simplestringlist">left_hand;right_hand;left_arm;right_arm</equipment_slots>

and then "list add" or "list remove" too (though this is more code scripting lengthy, meh ~ more attributes vs more code length ~ you choose the trade off that's best for you).

and for object types, instead of:

<type name="sword_type">
</type>

<type name="axe_type">
</type>

<type name="throwing_type">
</type>

I can do:

<weapon_type type="simplestringlist">sword_type</weapon_type>
<weapon_type type="simplestringlist">axe_type</weapon_type>
<weapon_type type="simplestringlist">axe_type;throwing_type</weapon_type>
<weapon_type type="simplestringlist">sword_type;throwing_type</weapon_type>
<weapon_type type="simplestringlist">sword_type;axe_type;throwing_type</weapon_type>

though I'd still have to deal with the main purpose of Object Types (providing a grouping of attributes or ie providing multiple attributes).

---------------

an extremely useful use (sorry! lol) for string dictionaries is "conversion ~ converting", it took me awhile to comprehend this use through studying Pixie's Spell Library ~ it's not easy to comprehend at first, at least it wasn't for me.

stringdictionary:

string_1=string_2

which works great for elementals with magic (or any other "opposites" usage):

fire=water, water=fire

think of the "converting" as "returning" a value:

(conceptually)
if ("fire"), then return "water"
if ("water"), then return "fire"

which is exactly how Pixie uses it.

(conceptually)
Fire Dragon monster example
if (monster.elemental="fire"), then return: return_value="water"
if (player_casted_spell.elemental = return_value), do x2 damage
if (player_casted_spell.elemental = monster.elemental), do x0.5 damage
else, do x1 damage

jaynabonne
While an interesting subject, HK, I'm wondering: does that have anything to do with this question? :)

HegemonKhan
nope, but it is related to "equipment" coding, which is indirectly part of his questioning, so this stuff may be of interest~use to~for him~her, hehe :D

just a few "tricks~techniques" with coding that I've been slowly comprehending myself, that I'm sharing in case it'll be useful for him~her, lol.

-----------

err, actually the "equipment_slots" concept~model is related to the question, as it's how Chase checks for equipped weapon in his~her code structure for equipment scripting.

Avantar
Wow..thanks for all the replies.
It does seem that learning dictionaries and lists might be the way to go; since I am already know there will have to be an armor type, magic type and wondering if a shield should be weapon type or armor type. (I know logically it should be armor type)
Anyway, back to the subject:
For my first game I really want to keep it simple and one example I can follow is "EDITED v5.4 Pertex testing combat cleanup"
That does not include equiping weapons and I am only going to have Combat Skill and Hitpoints for my character. What I will firstly try is what Jaynabonne suggested:

What you want is two "equipped" attributes, one for the left hand and one for the right hand (e.g. equippedl and equippedr, following the pattern you've set up). Then to see if an item is equipped in the left hand, check if "this = game.pov.equippedl" and similarly for the right (equippedr).



I did try with game.pov.equippedl and r respectively as well - must have messed up somewhere else as well.
If this "simple method" of doing things does not pan out for me - I will do my best learning about those lists and libraries, HK!

Thank you guys...will let you know how it goes.

HegemonKhan
here's an easier to follow~read coding (it might have some errors ~ I haven't tested it out), it is done as a Library File, but you can copy and paste code into your own game file from this Library File of mine. The main thing is that I hopefully cleaned up the code to be easier to understand and especially no more of my short-hand abbreviations of the stat attributes and etc.

<library>

<!-- New Game Code -->

<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>bbc85c01-6e80-4a71-8abf-c1e870fb5b42</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
</asl>

<!-- Game Code -->

<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>bbc85c01-6e80-4a71-8abf-c1e870fb5b42</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<inherit name="character_object_type" />
<strength type="int">100</strength>
<endurance type="int">100</endurance>
<dexterity type="int">100</dexterity>
<agility type="int">100</agility>
<speed type="int">100</speed>
<intelligence type="int">100</intelligence>
<spirituality type="int">100</spirituality>
<mentality type="int">100</mentality>
<piety type="int">100</piety>
<luck type="int">100</luck>
<current_hit_points type="int">999</current_hit_points>
<maximum_hit_points type="int">999</maximum_hit_points>
<current_mana_points type="int">99</current_mana_points>
<maximum_mana_points type="int">99</maximum_mana_points>
</object>
<object name="orc_1">
<inherit name="editor_object" />
<inherit name="character_object_type" />
<alias>orc</alias>
<strength type="int">25</strength>
<endurance type="int">25</endurance>
<dexterity type="int">25</dexterity>
<agility type="int">25</agility>
<speed type="int">25</speed>
<intelligence type="int">25</intelligence>
<spirituality type="int">25</spirituality>
<mentality type="int">25</mentality>
<piety type="int">25</piety>
<luck type="int">25</luck>
<current_hit_points type="int">500</current_hit_points>
<maximum_hit_points type="int">500</maximum_hit_points>
<current_mana_points type="int">50</current_mana_points>
<maximum_mana_points type="int">50</maximum_mana_points>
<experience_points type="int">100</experience_points>
<cash type="int">100</cash>
</object>
</object>
</asl>

<!-- Object Types -->

<type name="character_object_type">

<strength type="int">0</strength>
<endurance type="int">0</endurance>
<dexterity type="int">0</dexterity>
<agility type="int">0</agility>
<speed type="int">0</speed>
<intelligence type="int">0</intelligence>
<spirituality type="int">0</spirituality>
<mentality type="int">0</mentality>
<piety type="int">0</piety>
<luck type="int">0</luck>

<dead type="boolean">false</dead>

<undead type="boolean">false</undead>

<defending type="boolean">false</defending>
<casting type="boolean">false</casting>

<experience_points type="int">0</experience_points>
<cash type="int">0</cash>
<level type="int">0</level>

<hit_points type="string">0/0</hit_points>
<mana_points type="string">0/0</mana_points>

<current_hit_points type="int">0</current_hit_points>
<maximum_hit_points type="int">0</maximum_hit_points>

<current_mana_points type="int">0</current_mana_points>
<maximum_mana_points type="int">0</maximum_mana_points>

</type>

<!-- Turnscripts -->

<turnscript name="global_events_turnscript">
status_attributes_function
leveling_function
game.turns = game.turns + 1
</turnscript>

<!-- Commands -->

<command name="fight_command">
<pattern>fight #text#</pattern>
<script>
fight_function (game.pov,text)
</script>
</command>

<!-- Functions -->

<function name="fight_function" parameters="self,text">
enemy=GetObject(text)
if (enemy=null) {
foreach (object_x,AllObjects()) {
if (object_x.alias=text) {
enemy=object_x
}
}
}
on ready {
if (enemy=null) {
msg ("There seemingly is no " + text + " here.")
} else if (not check_reachable_function (enemy) = true) {
msg ("There seemingly is no " + enemy.alias + " here.")
} else if (not DoesInherit (enemy,"character_object_type")) {
msg (enemy.alias + "is seemingly not something that you can battle.")
} else if (GetBoolean (enemy,"hostile") = false) {
msg (enemy.alias + " is seemingly not something that you can battle.")
} else if (GetBoolean (enemy,"dead") = true) {
msg (enemy.alias + " is already dead.")
} else {
battle_sequence_function (self,enemy)
}
}
</function>

<function name="battle_sequence_function" parameters="self,enemy"><![CDATA[
if (enemy.dead=false or self.escaped=false) {
you_go_first=false
if (GetInt (self,"speed") > GetInt (enemy,"speed") {
you_go_first=true
} else if (GetInt (self,"speed") = GetInt (enemy,"speed") and RandomChance (50)=true) {
you_go_first=true
}
if (you_go_first=true) {
msg ("You get to go first for this round")
self_battle_turn_function (self,enemy)
on ready {
if (not enemy.dead=true or not self.escaped=true){
enemy_battle_turn_function (self,enemy)
}
}
} else {
msg (enemy.alias + " gets to go first for this round.")
enemy_battle_turn_function (self,enemy)
on ready {
if (not enemy.dead=true or not self.escaped=true){
msg ("It is now your turn.")
self_battle_turn_function (self,enemy)
}
}
}
on ready {
msg ("The round has ended.")
battle_sequence_function (self,enemy)
}
} else {
msg ("The battle is over.")
}
]]></function>

<function name="self_battle_turn_function" parameters="self,enemy"><![CDATA[
msg (self.alias + " has " + self.current_hit_points + " HP left.")
msg (enemy.alias + " has " + enemy.current_hit_points + " HP left.")
wait {
show menu ("What is your battle choice?", split ("Attack;Defend;Cast;Item;Run", ";"), false) {
switch (result) {
case ("Attack") {
self_attack_failed = false
if (RandomChance (GetInt (enemy,"agility") - GetInt (self,"speed")) = true) {
msg (enemy.alias + "evaded your attack!")
self_attack_failed = true
self.defending = false
} else if (RandomChance (GetInt (enemy,"dexterity") - GetInt (self,"agility")) = true) {
msg (enemy.alias + "parried your attack!")
self_attack_failed = true
self.defending = false
} else if (RandomChance (GetInt (enemy,"agility") - GetInt (self,"dexterity")) = true) {
msg (enemy.alias + "blocked your attack!")
self_attack_failed = true
self.defending = false
} else if (RandomChance (GetInt (self,"dexterity") - GetInt (enemy,"speed")) = false) {
msg ("Your attack missed " + enemy.alias +"!")
self_attack_failed = true
self.defending = false
} else if (RandomChance (GetInt (enemy,"armor_class") - GetInt (self,"attack_rating")) = true) {
msg ("Your attack failed to penetrate " + enemy.alias +"!")
self_attack_failed = true
self.defending = false
}
on ready {
if (self_attack_failed = false) {
if (self.defending = true and enemy.defending = true) {
enemy.current_hit_points = enemy.current_hit_points - (critical_hit_function (self) * 2 * GetInt (self,"physical_damage") / 2 + GetInt (self,"physical_damage") * (GetInt (self,"strength") - GetInt (enemy,"endurance")) / 100)
msg (enemy.alias + " has " + enemy.current_hit_points + " HP left.")
self.defending = false
} else if (self.defending = true and enemy.defending = false) {
enemy.current_hit_points = enemy.current_hit_points - (critical_hit_function (self) * 2 * GetInt (self,"physical_damage") + GetInt (self,"physical_damage") * (GetInt (self,"strength") - GetInt (enemy,"endurance")) / 100)
msg (enemy.alias + " has " + enemy.current_hit_points + " HP left.")
self.defending = false
} else if (self.defending = false and enemy.defending = true) {
enemy.current_hit_points = enemy.current_hit_points - (critical_hit_function (self) * GetInt (self,"physical_damage") / 2 + GetInt (self,"physical_damage") * (GetInt (self,"strength") - GetInt (enemy,"endurance")) / 100)
msg (enemy.alias + " has " + enemy.current_hit_points + " HP left.")
} else if (self.defending = false and enemy.defending = false) {
enemy.current_hit_points = enemy.current_hit_points - (critical_hit_function (self) * GetInt (self,"physical_damage") + GetInt (self,"physical_damage") * (GetInt (self,"strength") - GetInt (enemy,"endurance")) / 100)
msg (enemy.alias + " has " + enemy.current_hit_points + " HP left.")
}
}
}
}
case ("Defend") {
if (self.defending = true) {
msg ("You continue to defend yourself against " + enemy.alias)
} else if (self.defending = false) {
msg ("You defend yourself against " + enemy.alias)
self.defending = true
}
}
case ("Cast") {
self.defending = false
}
case ("Item") {
self.defending = false
}
case ("Run") {
self.defending = false
self.escaping = true
}
}
on ready {
if (GetInt (enemy,"current_hit_points") > 0) {
if (RandomChance (GetInt (self,"speed") - GetInt (enemy,"speed"))= true) {
msg ("You get an extra battle turn!")
self_battle_turn (self,enemy)
} else {
msg ("Your battle turn is over.")
}
} else if (GetInt (enemy,"current_hit_points") <= 0) {
msg (enemy.alias + " is dead.")
msg ("You have won the battle!")
self.defending = false
self.escaping = false
enemy.defending = false
enemy.dead = true
}
}
}
}
]]></function>

<function name="enemy_battle_turn_function" parameters="self,enemy"><![CDATA[
msg (self.alias + " has " + self.current_hit_points + " HP left.")
msg (enemy.alias + " has " + enemy.current_hit_points + " HP left.")
result = GetRandomInt (1,3)
switch (result) {
case (1) {
enemy_attack_failed = false
if (RandomChance (GetInt (self,"agility") - GetInt (enemy,"speed")) = true) {
msg ("You have evaded the attack!")
enemy_attack_failed = true
enemy.defending = false
} else if (RandomChance (GetInt (self,"dexterity") - GetInt (enemy,"agility")) = true) {
msg ("You have parried the attack!")
enemy_attack_failed = true
enemy.defending = false
} else if (RandomChance (GetInt (self,"agility") - GetInt (enemy,"dexterity")) = true) {
msg ("You have blocked the attack!")
enemy_attack_failed = true
enemy.defending = false
} else if (RandomChance (GetInt (enemy,"dexterity") - GetInt (self,"speed")) = false) {
msg (enemy.alias +"'s attack missed!")
enemy_attack_failed = true
enemy.defending = false
} else if (RandomChance (GetInt (self,"armor_class") - GetInt (enemy,"attack_rating")) = true) {
msg ("You weren't penetrated by the attack!")
enemy_attack_failed = true
enemy.defending = false
}
on ready {
if (enemy_attack_failed = false) {
if (enemy.defending = true and self.defending = true) {
self.current_hit_points = self.current_hit_points - (critical_hit_function (enemy) * 2 * GetInt (enemy,"physical_damage") / 2 + GetInt (enemy,"physical_damage") * (GetInt (enemy,"strength") - GetInt (self,"endurance")) / 100)
msg (self.alias + " has " + self.current_hit_points + " HP left.")
enemy.defending = false
} else if (enemy.defending = true and self.defending = false) {
self.current_hit_points = self.current_hit_points - (critical_hit_function (enemy) * 2 * GetInt (enemy,"physical_damage") + GetInt (enemy,"physical_damage") * (GetInt (enemy,"strength") - GetInt (self,"endurance")) / 100)
msg (self.alias + " has " + self.current_hit_points + " HP left.")
enemy.defending = false
} else if (enemy.defending = false and self.defending = true) {
self.current_hit_points = self.current_hit_points - (critical_hit_function (enemy) * GetInt (enemy,"physical_damage") / 2 + GetInt (enemy,"physical_damage") * (GetInt (enemy,"strength") - GetInt (self,"endurance")) / 100)
msg (self.alias + " has " + self.current_hit_points + " HP left.")
} else if (enemy.defending = false and self.defending = false) {
self.current_hit_points = self.current_hit_points - (critical_hit_function (enemy) * GetInt (enemy,"physical_damage") + GetInt (enemy,"physical_damage") * (GetInt (enemy,"strength") - GetInt (self,"endurance")) / 100)
msg (self.alias + " has " + self.current_hit_points + " HP left.")
}
}
}
}
case (2) {
if (enemy.defending = true) {
msg (enemy.alias + " is still defending itself.")
} else if (enemy.defending = false) {
msg (enemy.alias + " has choosen to defend itself.")
enemy.defending = true
}
}
case (3) {
enemy.defending = false
msg ("Cast")
}
}
on ready {
if (GetInt (self,"current_hit_points") > 0) {
if (RandomChance (GetInt (enemy,"speed") - GetInt (self,"speed")) = true) {
msg (enemy.alias + " gets an extra battle turn!")
on ready {
wait {
enemy_battle_turn (self,enemy)
}
}
} else {
msg (enemy.alias + " 's battle turn is over.")
}
} else if (GetInt (self,"current_hit_points") <= 0) {
msg (self.alias + " has died.")
msg ("GAME OVER")
finish
}
}
]]></function>

<function name="check_reachable_function" parameters="enemy" type="boolean">
foreach (object_x,ScopeReachableNotHeld ()) {
if (object_x=enemy) {
value = true
} else {
value = false
}
}
return (value)
</function>

<function name="critical_hit_function" parameters="object_x" type="int">
if (RandomChance (GetInt (object_x,"luck")) = true) {
value = 2
} else {
value = 1
}
return (value)
</function>

<function name="leveling_function"><![CDATA[
if (game.pov.experience_points >= game.pov.level * 100 + 100) {
game.pov.experience_points = game.pov.experience_points - (game.pov.level * 100 + 100)
game.pov.level = game.pov.level + 1
leveling_function
}
]]></function>

<function name="status_attributes_function">
game.pov.hit_points = game.pov.current_hit_points + "/" + game.pov.maximum_hit_points
game.pov.mana_points = game.pov.current_mana_points + "/" + game.pov.maximum_mana_points
</function>

</library>

jaynabonne
Avantar, if you choose to expand and generalize your equip code (beyond using an off-the-shelf lib as HK proposed), then you'll probably want to focus on the object variants of lists and dictionaries, as you'll be dealing with objects exclusively in your equipping fun. It's more more tricky to try to use the string ones in such a case (but not impossible, since objects have names - but let's keep it simple).

HegemonKhan
for the attribute method Jayna provided, you'd do something like this:

equipped attributes:

equipped_left_hand_boolean=false
equipped_left_hand_boolean=true

equipped_right_hand_boolean=false
equipped_right_hand_boolean=true

to check if equipped:

if (equipped_left_hand_boolean=true) {
}

if (equipped_right_hand_boolean=true) {
}

if (equipped_left_hand_boolean=true and equipped_right_hand_boolean=true) {
}

if (equipped_left_hand_boolean=true or equipped_right_hand_boolean=true) {
}

then to compare the two of them, to see if you can equip or not:

equipped_right_hand_string="wooden_sword"

"equip" Verb for another "wooden_sword" in your inventory:

if (equipped_right_hand_string="wooden_sword") {
-> msg ("You're already equipped with a wooden sword, silly!")
} else {
-> msg ("You equip the wooden sword")
-> equipped_right_hand_string="wooden_sword"
}

though this gets a bit more messy or complicated if you want to do more stuff this way ~ I'd have to think hard to figure it out.

HegemonKhan
err, ya as Jayna said, switch out the "string" types with "object" types, as it's easier, use objectlists (you probably won't need to use dictionaries ~ they're for more advance~complex stuff) and~or actual objects and not string attributes.

Sometimes though, you have to use both string attributes and actual objects, and~or use both lists (string and~or object) and dictionaries (string and~or object and~or script). But, don't worry about this, as it's for a bit more advanced coding techniques.

-----------

if you want to do a more simple combat coding, than use Pixie's Combat Library (linked in one of my previous posts) coding, as my combat coding is based on Pertex' and~or using Pertex' own Combat Library, both of which are quite advanced and complex combat codings, lol.

Pertex' Combat Coding (and thus mine too) is a "turn-based" combat coding (which is complex code wise), whereas Pixie's is not "turn-based" and thus easier to create and understand, as it doesn't involve complex and big, and multiple and connected, script blocks of coding.

jaynabonne
There's no need for the Booleans. That's overkill. You just have slots (attributes) that you assign objects to. And you don't need to use strings either. Basically, to left equip an object (e.g. object called "sword"):

game.pov.equippedl = sword

To unequip the left hand:

game.pov.equippedl = null

To see if something is left equipped:

if (HasAttribute(game.pov, "equippedl"))

To see if an object is left equipped:

if (o = GetAttribute(game.pov, "equippedl"))

Booleans are overrated (and can lead to messy code)! :)

If you wanted to use object dictionaries, then you'd have the same basic steps (objects and dictionaries are very similar in their overall semantics; it's just the syntax that differs). The drawback to dictionaries is that you have the pain of having to remove any previous entry before adding a new one. With an object, you just reassign.

HegemonKhan
argh, I'm overthinking the coding, laughs. And thanks for the tips, I either totally forgot and~or didn't realize that you can use an "ambigious" attribute as a "slot holder", hehe. And also, your other coding insight in your post as well, I appreciate too.

ya, booleans are messy and overkill, now.. I just need to learn how to code with less of them, lol. I still got a lot to learn, sighs.

Avantar
Thank you for all the replies guys!

I have been a bit busy at work this week - should get a change to look at all the suggestions on Friday and report back.
t is really appreaciated. :D

Avantar
Couldn't wait till Friday :)

I have used this script (not perfect yet) and it worked once :(

if (this.parent = game.pov) {
if (game.pov.equippedl = this) {
msg ("You already have this weapon equipped")
} else if (game.pov.equippedr = this) {
msg ("You already have this weapon equipped in your left hand")
} else if (game.pov.equippedl = null) {
msg ("You draw your " + this.alias + ".")
this.inventoryverbs = Split ("Look at;Drop;Unequip'(LHand)'", ";")
game.pov.equippedstatusl = "Wielding'(LHand)': " + this.alias
game.pov.equippedl.inventoryverbs = Split ("Look at;Drop;Equip'(LHand)'", ";")
} else {
msg ("You put away your " + game.pov.equippedl.alias + " and draw your " + this.alias + ".")
game.pov.equippedl = this
this.inventoryverbs = Split ("Look at;Drop;Unequip'(LHand)'", ";")
game.pov.equippedstatusl = "Wielding'(LHand)': " + this.alias
game.pov.equippedl.inventoryverbs = Split ("Look at;Drop;Equip'(LHand)'", ";")
}
} else {
msg ("You don't have it.")
}



Now I'm left with this error: Error running script: Error compiling expression 'game.pov.equippedl': RootExpressionElement: Cannot convert type 'Object' to expression result of 'Element'

Jaynabonne: Just to check if I do understand:
I need to create equippedl and equippedr as attributes on the player? If so...what type should it be? String does surely not work and Null does not write anything in. Weirdly, it did work beautifully somehow in one test.

Should I rather use if (o = GetAttribute(game.pov, "equippedl")) instead of if (game.pov.equippedl = this) ?
in 'o=GetAttribute(game.pov, "equippedl"))' I assume the 'o' is for object and it can be replaced by this?

Wow, HK! Imagine how I will struggle with the libraries - this is only 19 lines of code...lol But I am looking at it....

jaynabonne
Yes. If you reference the attribute directly and it's non-existent, you'll get an error. But if you use GetAttribute, then it returns null to you if it doesn't exist. That's the safe way to do it.

And no, don't create the attributes. You have no value to assign to them initially. :)

Avantar
Many, many thanks!!

I conclude then that this is my script for the left hand (right hand will be pretty much the same) and it works perfectly - everytime :D

if (this.parent = game.pov) {
if (this = GetAttribute(game.pov, "equippedl")) {
msg ("You already have this weapon equipped in your left hand.")
}
else if (this = GetAttribute(game.pov, "equippedr")) {
msg ("You already have this weapon equipped in your right hand")
}
else if (null = GetAttribute(game.pov, "equippedl")) {
msg ("You draw your " + this.alias + ".")
game.pov.equippedl = this
this.inventoryverbs = Split ("Look at;Drop;Unequipl", ";")
game.pov.equippedstatusl = "Wielding'(LHand)': " + this.alias

}
else {
msg ("You put away your " + game.pov.equippedl + " and draw your " + this.alias + ".")
game.pov.equippedl.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";")
game.pov.equippedl = this
this.inventoryverbs = Split ("Look at;Drop;Unequipl", ";")
game.pov.equippedstatusl = "Wielding'(LHand)': " + this.alias

}
}
else {
msg ("You don't have it.")
}


HegemonKhan
I just learned that OS'es (Operating Systems: like win xp, win 7, MacOS, and etc) and software, can easily have millions of code lines (lines, not character count)... yeesh! people need to make programs, to program for you, lol.

the annoying paradox of computers~coding~programming~scripting, it takes more work than normal, even the most simplistic action takes a few code lines, so the more stuff and~or more advanced actions that you want, the more your coding~scripting grows exponetially (or quadratically ~ whatever the math aspect it is known as, meh~lol).

jaynabonne
I'm glad it's working. :)

Since you seem open to ideas, I'd like to run a change by you which might simplify your life at some point. One thing I'm always on the lookout for in my code is duplicate code, as it just tends to cause problems trying to catch all the cases. That wouldn't matter so much in this case, as it's all close together, but it's an aesthetic nonetheless.

So here is a slight modification which doesn't change anything functionally, but merges the equip cases together:


if (this.parent = game.pov) {
if (this = GetAttribute(game.pov, "equippedl")) {
msg ("You already have this weapon equipped in your left hand.")
}
else if (this = GetAttribute(game.pov, "equippedr")) {
msg ("You already have this weapon equipped in your right hand")
}
else {
if (null = GetAttribute(game.pov, "equippedl")) {
msg ("You draw your " + this.alias + ".")
} else {
msg ("You put away your " + game.pov.equippedl + " and draw your " + this.alias + ".")
}
game.pov.equippedl = this
this.inventoryverbs = Split ("Look at;Drop;Unequipl", ";")
game.pov.equippedstatusl = "Wielding'(LHand)': " + this.alias
}
}
else {
msg ("You don't have it.")
}


You could easily combine the left and right hand cases by making a function that takes params for the variants above (or maybe even just a single param that is "l" or "r"). But that's another step. :) I'll offer some code if you're interested.

cole
I don't know how you want your weapons to function, meaning, how they are supposed to do damage, but here's a little suggestion:

With the ideas suggested above (setting the attributes "equippedr" or "equippedl" to a weapon object) it might be a good idea to call the strength or damage of the weapon from the weapon object itself. Meaning, instead of the sword adding strength to a player's "Strength" attribute if it gets equipped you can call the attribute "Strength" of the sword itself.

If you hit an enemy you can subtract the "Strength" attribute of the sword from the enemy's health directly. That way if the weapon gets equipped, unequipped, breaks, gets forced out of your hand, is dropped, is put somewhere, etc. you don't have to add or subtract it's "Strength" attribute from the player's "Strength" attribute.

Avantar
To jaynabonne:

Thank you for the mod and yes, I would love to see the combined script!
There will need to be more to the script and I will think about it, but I would need two handed weapons too. So I think the need to have string attributes on the weapons for single or two-handed will need to happen.
Thanks once again for the help.

To cole:

That is a good tipp and I have thought of it before. It will be convenient for me to do, but I was also thinking of the player that might want to physically see the changes that happen to equipping and unequipping his/her weapons/armor. I am starting off slowly and for now there will only be two stats: Skill and HP - so there won't be a whole lot of stats like charisma, strength, dexterity and so forth.

HegemonKhan
Besides learning the coding... there's also the annoyance in trying to construct a good equation~formula~alogorithm for your game mechanics (once you add in more stat attributes), lol. Game Making is not easy at all !!!!

(I think I spent like at least 5 hours in contructing each of these formulas, lol ~ ARGH !!!!!!)
(It makes me really appreciate games more now, with how well their game mechanics usually work)

here's one for leveling+experience:

(you can replace "game.pov" with "player" instead for it to make more sense to you)

<function name="leveling_function"><![CDATA[
-> if (game.pov.experience_points >= game.pov.level * 100 + 100) {
->-> game.pov.experience_points = game.pov.experience_points - (game.pov.level * 100 + 100)
->-> game.pov.level = game.pov.level + 1
->-> leveling_function
-> }
]]></function>

and here's my (physical~weapon) damage one:

(you'll need to write it out, so that you can see it properly, as it's really hard to see it on a single line, lol)

defending = double's your defense, and on the next turn, you do double the damage, and it applies to the monster~enemy too if they choose to defend a round and then attack the next round (a really cool feature from 7th Saga game, it makes the "defend" action a much more tactical decision, now you got to think whether it's better to just attack every round, or to defend the 1st round and then attack the next round)

if (self.defending = true and enemy.defending = true) {
-> enemy.current_hit_points = enemy.current_hit_points - (critical_hit_function (self) * 2 * GetInt (self,"physical_damage") / 2 + GetInt (self,"physical_damage") * (GetInt (self,"strength") - GetInt (enemy,"endurance")) / 100)
-> msg (enemy.alias + " has " + enemy.current_hit_points + " HP left.")
}

and the critical hit function (doubles the damage as well if it succeeds, lol) that is used in the above damage scripting:

<function name="critical_hit_function" parameters="object_x" type="int">
-> if (RandomChance (GetInt (object_x,"luck")) = true) {
->-> value = 2
-> } else {
->-> value = 1
-> }
-> return (value)
</function>

-------------------------

see if you can understand or figure out what my leveling and damage equations do, for a challenge, hehe.

Avantar
Thank you HK!

This will sure come in handy. I will have experience for my character and I guess that:
game.pov.experience_points = game.pov.experience_points - (game.pov.level * 100 + 100)
formula is carrying over experience gained if it is more than needed for leveling up?

What I have so far:
equipl and equipr (Equipping something to the left hand or right hand):
This will basically be used for single handed items and replace the buttons under the item accordingly to 'unequipl' if you have something equipeed in the left hand and 'equipl' and 'equipr' if that weapon is not equiped. Also when you swap it out for another weapon, it should change these buttons for the weapon being swapped out.
If you try to equip a two handed weapon it will display a message that you should use the command 'equip'. Reason being that it will be stupid having buttons under a two handed weapon saying equipl and equipr. Therefore I have -

equip:
This will be dealing with equipping two handed weapons. So the left hand - and right hand status will show that the same weapon is being equipped.
(This will allow me to have a shield in one hand and weapon in one hand or having two single handed weapons equipped or a two handed weapon - I could also give penalties for having something in the left hand while u are right handed - just a thought)
Then I've got unequipl, unequipr and unequip....

I will only have 2 stats: (make it 4)
Skill and HP (max Skill and max HP)
A bit lame, but armor will increase your hp while worn. (the idea that you can take more hits with armor on)
Weapons will increase your skill - fighting without any weapon will leave you with low skill points

Damage from a weapon will work like this:
each weapon will have a damage value like: 1d6, 1d8 and so forth; since Quest 5.4 has got DiceRoll - I will try to implement that.

Combat will work like this:
There will be a 1d10 die roll for hero and enemy - their skill points should be added to this value. The one with the highest value scores a hit and the value deducted from the victim will be the damage factor of the weapon (1d8, 1d4, 2d6...ect)
If the two values for hero and foe is the same results in a parry.
A critical hit will be if one of them have 6 or more points more than the victim. - (calculating it based on what...I do not know yet; since I won't have luck-could just be an extra 1d6 roll)

Experience:
Well, the same as everybody does it I guess.

The only other variable I will have is 'Gold'

Would this system be ideal? Most likely not. But this will be the simplest combat system I can think of and would make for a good starting point for beginners like me.

So hopefully, with all you good samaritans help, I could post this complete simple 'system' for those who might be interested. :D
I appreciate all you guys help immensely - I am not good with this coding thing. I haven't stipulated what my idea was before and thought I put it out there so that everybody understands where I am going with this. If time permits, I will finish what I have and post that so long.
Soon I will have to deal with experience gained and I will certainly appreciate your help HK. :D

I also want to implement abilities - already bracing myself...lol

HegemonKhan
yep, you got it right! (good job!), and it also means that you're in effect starting from 0 experience (+ the extra experience) for the next level

let's see if I can explain this clearly again (it took me hours to do the explanation right in some long lost post of mine ~ I wish I could find it!, lol):

level 0 = 0-99 experience range (0-99 total experience)
level 1 = 100 experience required (100 total experience required: 0 + 100)
extra experience is used towards level 2, but you start from 0 experience, so it's:
0 + extra experience = experience towards~for level 2
level 2 = 200 experience required (300 total experience required: 100 + 200)
extra experience is used towards level 3, but you start from 0 experience, so it's:
0 + extra experience = experience towards~for level 3
level 3 = 300 experience required (600 total experience required: 300 + 300)
extra experience is used towards level 4, but you start from 0 experience, so it's:
0 + extra experience = experience towards~for level 4
level 4 = 400 experience required (1,000 total experience required: 600 + 400)
extra experience is used towards level 5, but you start from 0 experience, so it's:
0 + extra experience = experience towards~for level 5
level 5 = 500 experience required (1,500 total experience required: 1,000 + 500)
etc etc etc

not quite as concise as I did it in my other post, somewhere on this site, lol, but meh... good enough (hopefully).

I wanted it this way, you may not like it like this and thus will have to craft~construct your own formula for what you want
(I can try to help, but this is hard for me, figuring out a desired math formula, lol)

----------

a real quick question, to see if you fully understand my leveling formula (just for fun, hehe):

let's say you have 0 experience, at level 0 (you're just starting the game), and you kill a monster that gives you 300 experience.

What will now be your displayed:

Level = ?
Experience = ?

how about if you have 0 experience, at level 0 (you're just starting the game), and you kill a monster that gives you 200 experience.

What will now be your displayed:

Level = ?
Experience = ?

how about if you have 0 experience, at level 0 (you're just starting the game), and you kill a monster that gives you 500 experience.

What will now be your displayed:

Level = ?
Experience = ?

HegemonKhan
here is a game file that you can test~play out (and examine~study too):

(the download'able game file is at bottom of post, click on it)

(or you can just copy and paste the code below into a new game file of your own, if you don't know how to do this I can help)

(I added in gaining stats into the leveling function, if you want those out of there, I can help you in removing them if you need help doing so)

<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>cd102f9d-370a-4bda-b6ea-ca42288f619c</gameid>
<version>1.0</version>
<start type="script">
msg ("What is your name?")
get input {
msg ("- " + result)
player.alias = result
show menu ("What is your gender?", split ("male;female" , ";"), false) {
player.gender_x = result
show menu ("What is your race?", split ("human;elf;dwarf" , ";"), false) {
player.race = result
show menu ("What is your class?", split ("warrior;cleric;mage;thief" , ";"), false) {
player.class = result
msg (player.alias + " is a " + " " + player.gender_x + " " + player.race + " " + player.class + ".")
}
}
}
}
</start>
<turns type="int">0</turns>
<statusattributes type="simplestringdictionary">turns = </statusattributes>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_player" />
<inherit name="editor_object" />
<gender_x type="string"></gender_x>
<strength type="int">0</strength>
<intelligence type="int">0</intelligence>
<agility type="int">0</agility>
<statusattributes type="simplestringdictionary">alias = Name: !;gender_x = Gender: !;strength = ;intelligence = ;agility = ;level = ;experience = ;cash = </statusattributes>
<level type="int">0</level>
<experience type="int">0</experience>
<cash type="int">0</cash>
</object>
<object name="potion100">
<inherit name="editor_object" />
<alias>potexp100</alias>
<take />
<displayverbs type="simplestringlist">Look at; Take; Drink</displayverbs>
<inventoryverbs type="simplestringlist">Look at; Use; Drop; Drink</inventoryverbs>
<drink type="script">
msg ("You drink the exp potion, receiving 100 experience.")
player.experience = player.experience + 100
</drink>
</object>
<object name="potion300">
<inherit name="editor_object" />
<alias>potexp300</alias>
<take />
<displayverbs type="simplestringlist">Look at; Take; Drink</displayverbs>
<inventoryverbs type="simplestringlist">Look at; Use; Drop; Drink</inventoryverbs>
<drink type="script">
msg ("You drink the exp potion, receiving 300 experience.")
player.experience = player.experience + 300
</drink>
</object>
</object>
<turnscript name="global_events_turnscript">
<enabled />
<script>
leveling_function
game.turns = game.turns + 1
</script>
</turnscript>
<function name="leveling_function"><![CDATA[
if (player.experience >= player.level * 100 + 100) {
player.experience = player.experience - (player.level * 100 + 100)
player.level = player.level + 1
switch (player.gender_x) {
case ("male") {
player.strength = player.strength + 1
}
case ("female") {
player.agility = player.agility + 1
}
}
switch (player.race) {
case ("dwarf") {
player.strength = player.strength + 2
}
case ("elf") {
player.agility = player.intelligence + 2
}
case ("human") {
player.strength = player.strength + 1
player.agility = player.agility + 1
}
}
switch (player.class) {
case ("warrior") {
player.strength = player.strength + 2
}
case ("cleric") {
player.intelligence = player.intelligence + 1
player.agility = player.agility + 1
}
case ("mage") {
player.intelligence = player.intelligence + 2
}
case ("thief") {
player.strength = player.strength + 1
player.agility = player.agility + 1
}
}
leveling_function
}
]]></function>
</asl>


-----------------------------

HK Edit:

err... I forgot to display your race and class on the right side, if you want me to correct this, I can do so (and will post up the new game file in a new post). Otherwise, hopefully there's nothing else wrong with it ~ I hadn't fully tested it, but it seems to at least work okay.

HegemonKhan
Also, it's faster for us (me especially anyways) to explain or do~show stuff in code, but lots of people new to quest and~or to coding in general, needs things to be explained in~through the GUI~Editor, which I can do, but it takes a lot more work and time as it's slower to do~show and~or explain it via the GUI~Editor.

So, if you ever want~need stuff explained with the GUI~Editor, let me know, and I'll get it posted up for you (though it may take me a few days or not until the weekend ~ as I'm busy with school work during the week).

-----------

if~when you want me to help with more complex damage (or whatever) game mechanics, let me know, and I'll try to help you (I'm still trying to learn creating all the aspects of a combat system, equipment system, magic system, and etc RPG elements, myself, but if I can't help you either, we've got some good coders here, the moderators of the site are very helpful and coding knowledgeable, as well as some of the normal members~users too).

-------------

(Math) Operators:

Addition: +
Subtraction: -
Multiplication: *
Division: /
Equals: =
Greater Than: >
Lesser Than: <
Greater Than and Equal To: >=
Lesser Than and Equal To: <=
Not Equal: <> // if you do this in Code, then you need to have it within this: <![CDATA[ {within here: the scripts} ]]>

Conditionals:

if ~ else if ~ else
foreach (use it with~for objectlists and~or objectdictionaries)
for (use it with~for objectlists and~or objectdictionaries)
firsttime ~ otherwise
not (not or not equal ~ depends how you're using it ~ what your code line is saying~doing~is)

----------

some damage ideas:

attack vs defense (Object_1.attack - Object_2.defense) integer attributes
weapon~physical damage + fire damage + etc elemental damages

(weapon damage) + (weapon damage * some percent amount)

some percent amount (could be created as~like this):

(Object_1.strength_or_attack - Object_2.endurance_or_defense)
............................... 100 ......................................

or how it would look on one line: (Object_1.strength_or_attack - Object_2.endurance_or_defense) / 100

this is (some of) what I'm doing in my damage equation~formula, by the way.

---------------

game mechanic design is limitless, be creative (and hope you can than get a math equation that works and does what you want it to do), and if you need help with putting it into Code or with the GUI~Editor, than please ask, and I'll try to help, and if not, someone else can~will help you out too.

HegemonKhan
for experience and gold~cash

(I'm using my "cash" as the label for my currency attribute, lol. just change "cash" for your "gold" label for your currency attribute. I don't use "gold" because eventually if I ever have a game made, I'll be using "gold" for something else, "cash" is a good neutral word for currency for me as an American anyways. I plan on using "gold" as a metal resource, such as for a weapon's or armor's material grade~quality: wooden < copper < iron < steel < silver < gold < diamond < adamantium or mithril, lol. Or, maybe I'll use~have a "gold coin" Object):

an example of how to do it (some as GUI~Editor, some as Code)

the "ACTION" (the scripting ~ ie the Verb)

"dragon" (Object) -> Verb (Tab) -> Add ->

Name: fight
Script: (see below)

if (dragon.dead=true) {
-> msg ("the dragon is already dead, silly")
} else if (dragon.dead=false) {
-> if (dragon_slayer_sword.parent=player) { // if the dragon slayer sword is in your (the "player's") inventory (if you're holding it)
->-> msg ("you kill the dragon with the dragon slayer sword")
->-> player.experience = player.experience + dragon.experience
->-> player.cash = player.cash + dragon.cash
->-> dragon.dead=true // this sets "flags" the dragon as being "dead".
-> } else {
->-> msg ("the dragon kills you")
->-> msg ("GAME OVER")
->-> finish // this command~script stops~ends the game
-> }
}

NOW, we ALSO have to do the "CREATION" of the attributes too (you can't do an "ACTION" with attributes when those attributes don't exist ~aren't "CREATED"~ yet, lol):

"dragon" (Object) -> Attributes (Tab) -> Attributes -> Add ->

Name: dead
Type: boolean
Value: false // we want our dragon to start off alive (so that we can then fight and kill it), lol

Name: experience
Type: int (integer)
Value: (let's say) 1,000,000,000 (lol, hey, it's a dragon after all, lol)

Name: cash
Type: int
Value: 1,000,000 (dragons sleep on~in mounds of gold coins, lol)

in Scripting this looks like:

dragon.dead=false
dragon.experience=1000000000
dragon.cash=1000000

in Code this looks like:

<object name="dragon">
-> <inherit name="editor_object" />
-> <dead type="boolean">false</dead>
-> <experience type="int">1000000000</experience>
-> <cash type="int">1000000</cash>
-> <fight type="script">
->-> if (dragon.dead=true) {
->->-> msg ("the dragon is already dead, silly")
->-> } else if (dragon.dead=false) {
->->-> if (dragon_slayer_sword.parent=player) { // if the dragon slayer sword is in your (the "player's") inventory (if you're holding it)
->->->-> msg ("you kill the dragon with the dragon slayer sword")
->->->-> player.experience = player.experience + dragon.experience
->->->-> player.cash = player.cash + dragon.cash
->->->-> dragon.dead=true // this sets "flags" the dragon as being "dead".
->->-> } else {
->->->-> msg ("the dragon kills you")
->->->-> msg ("GAME OVER")
->->->-> finish // this command~script stops~ends the game
->->-> }
->-> }
-> </fight>
-> <displayverbs type="simplestringlist">Look at; Fight</displayverbs>
</object>

"player" (Object) -> Attributes (Tab) -> Attributes -> Add ->

Name: experience
Type: int
Value: 0

Name: cash
Type: int
Value: 0

in Scripting this looks like:

player.experience=0
player.cash=0

in Code this looks like:

<object name="player">
-> <inherit name="editor_object" />
-> <inherit name="editor_player" />
-> <experience type="int">0</experience>
-> <cash type="int">0</cash>
-> <inventory type="objectlist">dragon_slayer_sword</inventory> // I think this is how it looks, but maybe not. Obviously, you'd have to get the dragon slayer sword somewhere in the game and take it, for you to have it in your inventory.
</object>

----

<object name="dragon_slayer_sword">
-> <inherit name="editor_object" />
</object>

HegemonKhan
to do any transaction, we "fake it" with~by changing our attributes' values (you don't want to actually move around "currency" objects like "gold coins" ~ the more you can do with attributes the better ~ though some things are better done with objects, as well):

(this is in extremely simple design as an example, obviously we'd need to add more coding~features to "buying" and "selling")

shop_owner (Object) -> Verbs (Tab) -> Add ->

"buy" (and repeat: add another verb called) "sell"

------------------------------------

BUYING

player.cash = 500
shop_owner.cash = 1000
katana.parent=shop_owner

"player" buying a "katana" that costs 100 "cash" from a "shop_owner"

player.cash = player.cash - 100
shop_owner.cash = shop_owner.cash + 100
katana.parent=player

player.cash = 500 - 100 = 400
shop_owner.cash = 1000 + 100 = 1100
katana.parent=player

---------------------------------------------------------

SELLING

player.cash = 500
shop_owner.cash = 1000
katana.parent=player

"player" selling a "katana" that is worth 100 "cash" to a "shop_owner"

player.cash = player.cash + 100
shop_owner.cash = shop_owner.cash - 100
katana.parent=shop_owner

player.cash = 500 + 100 = 600
shop_owner.cash = 1000 - 100 = 900
katana.parent=shop_owner

Avantar
Well, this is how I understand it:

let's say you have 0 experience, at level 0 (you're just starting the game), and you kill a monster that gives you 300 experience.

What will now be your displayed:

Level = 2
Experience = 0

how about if you have 0 experience, at level 0 (you're just starting the game), and you kill a monster that gives you 200 experience.

What will now be your displayed:

Level = 1
Experience = 100

how about if you have 0 experience, at level 0 (you're just starting the game), and you kill a monster that gives you 500 experience.

What will now be your displayed:

Level = 2
Experience = 200

Hopefully it is right?

Avantar
For those that might have followed - here are the steps for equipping and unequipping weapons. (Credits goes to Jaynabonne and HK)

I am using verbs and have followed the wiki for this: http://quest5.net/wiki/Simple_Combat_System_%28Advanced%29
The verbs I have is equipl (to equip something in the left hand)
equipr (to equip something in the right hand)
equip (to equip a two-handed weapon)
unequip (to unequip individual items)

Next, I have added some attributes to my player:
You can add attributes for HP, Armor, Defense or whatever you want to have show on the right panel under the Status bar.
I am just sticking to weapon equipping for now, so I have added the following:
equippedstatusl as a string with the text: Wielding(LHand): nothing
equippedstatusr as a string with text: Wielding(RHand): nothing
statusattributes as a string dictionary with key equippedstatusl and value !, another key of equippedstatusr and value !

This will show what I have in my hands on the in the Status panel on the right of the game. Initially it will show like:Wielding(LHand): nothing and Wielding(RHand): nothing

Now I create a new object type called 'weapon' (In the left section of the game, you will see 'Advanced'>expand that and you will see 'Object Types')
On the new weapon type we need to create attributes and name them the same as the verbs we created for equipping and unequipping them.
So my first attribute would be equipl and I set its type to script. Paste the following script in there:
if (this.parent = game.pov) {
if (this.location="dhand") {
msg ("Please use the command 'equip' for two handed weapons.")
}
else if (HasAttribute(game.pov, "equippedt")) {
msg ("You put away your " + game.pov.equippedt.alias + " and draw your " + this.alias + ".")
game.pov.equippedt.inventoryverbs = Split ("Look at;Drop;Equip", ";")
game.pov.equippedl = this
game.pov.equippedt = null
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusl = "Wielding'(LHand)': " + this.alias
game.pov.equippedstatusr = "Wielding'(RHand)': nothing"
}
else if (this = GetAttribute(game.pov, "equippedl")) {
msg ("You already have this weapon equipped in your left hand.")
}
else if (this = GetAttribute(game.pov, "equippedr")) {
msg ("You already have this weapon equipped in your right hand")
}
else if (null = GetAttribute(game.pov, "equippedl")) {
msg ("You draw your " + this.alias + ".")
game.pov.equippedl = this
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusl = "Wielding'(LHand)': " + this.alias
}
else {
msg ("You put away your " + game.pov.equippedl.alias + " and draw your " + this.alias + ".")
game.pov.equippedl.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";")
game.pov.equippedl = this
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusl = "Wielding'(LHand)': " + this.alias
}
}
else {
msg ("You don't have it.")
}

The first line just checks if the weapon is in the players inventory. game.pov=player and can also be player.pov instead. If you have more than one player and want the scripts to work on all of them, rather use game.pov
inventoryverbs is the buttons under an object when you click on them.
You will see (as example near) the end of the script in the else statement the following line:
game.pov.equippedl.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";") - This line is important. The weapon that you had equipped, but swapped out for the weapon you currently equip will go back to your inventory and if that line is not present, it will only have the 'Unequip' option.
The second one in the else statement:
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";") - this will be the options available for the weapon that you have just equipped.
If you try to use the command equipl on a two handed weapon, it will give the message: Please use the command 'equip' for two handed weapons.

So here is the script for equipr:
if (this.parent = game.pov) {
if (this.location="dhand") {
msg ("Please use the command 'equip' for two handed weapons.")
}
else if (HasAttribute(game.pov, "equippedt")) {
msg ("You put away your " + game.pov.equippedt.alias + " and draw your " + this.alias + ".")
game.pov.equippedt.inventoryverbs = Split ("Look at;Drop;Equip", ";")
game.pov.equippedr = this
game.pov.equippedt = null
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusr = "Wielding'(LHand)': " + this.alias
game.pov.equippedstatusl = "Wielding'(RHand)': nothing"
}
else if (this = GetAttribute(game.pov, "equippedl")) {
msg ("You already have this weapon equipped in your left hand.")
}
else if (this = GetAttribute(game.pov, "equippedr")) {
msg ("You already have this weapon equipped in your right hand")
}
else if (null = GetAttribute(game.pov, "equippedr")) {
msg ("You draw your " + this.alias + ".")
game.pov.equippedr = this
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusr = "Wielding'(RHand)': " + this.alias
}
else {
msg ("You put away your " + game.pov.equippedr.alias + " and draw your " + this.alias + ".")
game.pov.equippedr.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";")
game.pov.equippedr = this
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusr = "Wielding'(RHand)': " + this.alias
}
}
else {
msg ("You don't have it.")
}


For unequipping the weapons and not just swap to another weapon, create the attribute unequip, set it as a script and paste the following code in:
if (this.parent = game.pov) {
if (this.location="single" and this = GetAttribute(game.pov, "equippedl")) {
msg ("You put away your " + game.pov.equippedl.alias + ".")
game.pov.equippedl = null
this.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";")
game.pov.equippedstatusl = "Wielding(LHand): nothing"
}
else if (this.location="single" and this = GetAttribute(game.pov, "equippedr")) {
msg ("You put away your " + game.pov.equippedr.alias + ".")
game.pov.equippedr = null
this.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";")
game.pov.equippedstatusr = "Wielding(RHand): nothing"
}
else if (this.location="dhand") {
msg ("You put away your " + game.pov.equippedt.alias + ".")
game.pov.equippedr = null
game.pov.equippedl = null
game.pov.equippedt = null
this.inventoryverbs = Split ("Look at;Drop;Equip", ";")
game.pov.equippedstatusl = "Wielding(LHand): nothing"
game.pov.equippedstatusr = "Wielding(RHand): nothing"
}
}
else {
msg ("You don't have it.")
}


Also for equipping two handed weapons, create the attribute: equip , set it to script and paste in the following:
if (this.parent = game.pov) {
if (this.location="single") {
msg ("Use the command 'equipl' or 'equipr' for single handed weapons or shields.")
}
else if (this = GetAttribute(game.pov, "equippedt") and this.location="dhand") {
msg ("You already have this weapon equipped.")
}
else if (HasAttribute(game.pov, "equippedr") and HasAttribute(game.pov, "equippedl")) {
msg ("You put away your " + game.pov.equippedr.alias + " and " + game.pov.equippedl.alias + " and draw your " + this.alias + ".")
game.pov.equippedl.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";")
game.pov.equippedr.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";")
game.pov.equippedt = this
game.pov.equippedr = null
game.pov.equippedl = null
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusl = "Wielding(LHand): " + this.alias
game.pov.equippedstatusr = "Wielding(RHand): " + this.alias
}
else if (null = GetAttribute(game.pov, "equippedl") and null = GetAttribute(game.pov, "equippedr")) {
msg ("You draw your " + this.alias + ".")
game.pov.equippedt = this
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusl = "Wielding(LHand): " + this.alias
game.pov.equippedstatusr = "Wielding(RHand): " + this.alias
}
else if (HasAttribute(game.pov, "equippedl")) {
msg ("You put away your " + game.pov.equippedl.alias + " and draw your " + this.alias + ".")
game.pov.equippedl.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";")
game.pov.equippedt = this
game.pov.equippedl = null
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusl = "Wielding(LHand): " + this.alias
game.pov.equippedstatusr = "Wielding(RHand): " + this.alias
}
else if (HasAttribute(game.pov, "equippedr")) {
msg ("You put away your " + game.pov.equippedr.alias + " and draw your " + this.alias + ".")
game.pov.equippedr.inventoryverbs = Split ("Look at;Drop;Equipl;Equipr", ";")
game.pov.equippedt = this
game.pov.equippedr = null
this.inventoryverbs = Split ("Look at;Drop;Unequip", ";")
game.pov.equippedstatusl = "Wielding(LHand): " + this.alias
game.pov.equippedstatusr = "Wielding(RHand): " + this.alias
}
}
else {
msg ("You don't have it.")
}


Now when you create a weapon object in your room, add an attribute to it called: location - set the type to string. In the text box type: dhand or single. dhand is for a two-handed weapon and single for a one-handed.
Under 'Inherited Types'>press the plus button and press your keyboard up/down arrrow keys to find our object type: weapon and select it.
Forgot to mention: You should also go to your weapon object's 'Object' tab and change the Invntory verbs to include Euipl and Equipr for single handed weapons or Equip for two-handed weapons.

Now you should be able to equip and unequipp weapons in your left or right hand or in your left and right hand or wielding two-handed weapons. Maybe swap one hand out for a shield!

Hope this helps - I certainly struggled!

Avantar
Hey HK...I was so busy typing the previous post that I haven't noticed all the other scripts you posted - thanks a bunch. I fogot about shops...lol

I had a look at your experience formula - works a treat. I see the function is being called from a turn script.
For now, I am going to try and construct my combat system.(I will include your experience formula...thx) After that, I am going to do equipping armor and magic items like rings and amulets. You'll be happy to know that I am busy with a library :) But just for adding tabs for types I am going to have. (Weapons, armor, magic, Enemy) I am sure it will save a bunch of time setting the attributes on objects.

Thanx again

HegemonKhan
you got my leveling equation understood perfectly, you're picking up this stuff fast!

(trouble-shooting to get your code to work is fun... when it's just a small stupid mistake, it's a "love-hate" emotion... you feel great+relieved that you understood the coding correctly, but you hate how much time it took to find that #$%@*& small stupid mistake or typo or missing character... lol. Now if your code is totally wrong and that's why it's not working, than you got a big problem as you got to still learn the coding, though the cause of the errors is quickly obvious, if that's any comfort, lol)

------------

since you seem to be fine with working with the code, if you don't already know, this (free) software is very helpful for writing, reading, and fixing code:

http://notepad-plus-plus.org/

once got the program up, all you got to do is at the top, on the bar menu, drop down the "language" choice, and choose "XML".

-------------------------

your work is coming along well, it looks good!

at some point, you might want to look at Chase's Wearables Library, as it's a much more clean design for people doing a more complex equipment~equipping system (though it uses a bit more complicated coding to understand). Instead of using 3 Verbs, Chase instead uses Commands+Functions+Parameters, and a stringlist on his "equipment" Object Type:

<equipment_slots type="simplestringlist"></equipment_slots>

as this enables you to define what "slots it uses up":

one_handed_sword: <equipment_slots type="simplestringlist">right_hand</equipment_slots>
shield: <equipment_slots type="simplestringlist">left_hand</equipment_slots>
two_handed_axe: <equipment_slots type="simplestringlist">right_hand;left_hand</equipment_slots>

you can then do~use the "if" conditionals to determine whether you can equip an equipment item or not.

and Chase offers even further features, with the use of: <equipment_layer type="int"></equipment_layer> , as you can't equip clothes if you're equipped with armor (you got to remove your armor before you can equip your clothes, and then you can equip your armor back on, now having equipped both your clothes and armor to the same "slot" location. the same is true for unequiping, you can't remove your clothes if still have your armor on over them. this is done by the "layer" number amount, and through "greater~lesser than and~or equal to comparison of the layer number amounts of the two pieces of equipment items".

--------

Pixie's Simple Combat Library (posted as a wiki page that you used), was made for those who want a bit more of a simplified (ie a NON-turn-based) combat system (you're moving into a more advanced combat system, as you can probably see, you used a lot of code to do what you wanted. I too used a lot of code to make my combat coding... and then Pertex' "fixes~cleans" it up for me, and it's like half the size of mine and easier to understand... my mouth dropped... lol. Just getting the code to work is awesome for a noob at coding like me, but it's really messy and poor coding work... making your coding really professional probably takes years of practice~experience~knowledge of coding, sighs. I'm trying though... to learn, slowly, hehe). Most code~libraries~guides you find on this site are Pixie's doing, a lot of thanks goes to him~her just for the sheer amount of good code that he~she has made available for us. Though, Pixie's not the only one, there's lots of people helping out, though Pixie, does have the most content up ~ at least as I've noticed~perceived anyways. Pixie can code really well, doing advanced coding and~or simplified coding for whatever we may want~need.

Pertex' equipment system, I tried to understand it but wasn't able to at the time (maybe now I can understand it), and I was more interested in getting a combat system working, I could learn equipment later on, like I'm doing now... lol. Soon as I find time, I'm going to tackle understanding Pertex' equipment system and learn it!

HegemonKhan
Functions, Commands, Verbs, and Scripts are activated by something (ie they're NOT "always running"). Whereas...

Turnscripts, Timers, and special Verbs~Scripts: <changedAttribute type "script"></changedAttribute>, ARE "always running".

So, they're very useful !!! (such as: updating the display, ie status attributes, of your altered "stat" attributes, or when you implement "game turns" itself and want "stuff" to happen, and in what order, on each~every such "game turn", and probably many more uses too).

here's the wiki for the "changed" Verb~Script:

http://quest5.net/wiki/Running_a_script ... te_changes

if you need help understanding it, ask Jaynabonnie, he can explain it well.

I can explain and help you with the Turnscripts, but I'm still a little shaky on the "changed" Verb-Scripts, but I can try to help you if you need it.

Avantar
Yeah...that is probably the fist thing I looked at was wearables from Chase. I am still looking :shock:
It would suite my needs for equipping stuff better. (Armor is in the pipeline for me now)
I have implemented a few commands to call scripts, just for testing.

I guess that I still need a bit clarity on parameters. One day soon I hope.

Oh...and I am using notepad ++ :D

HegemonKhan
parameters is merely a method to transfer stuff from one function to another function (and thus be able to use it in~for this next function). Though it is a bit complicated at first to understand, and it's range of uses is vast, but it's actually is not as difficult as it'll seem at first. Think of parameters as a video~computer game's "save" and "load" slots, lol. You "save" the data you want in function_1 and then "load" that data in function_2 for use in function_2.

here's an example (using concatenation, which is a bit confusing... at least still for me anyways, but it shows some of how parameters work):

http://quest5.net/wiki/Function_element

------

for this example, I'm just using an integer amount for my parameters, but you can use "text" (Strings), and even Objects too (and maybe other stuff as well). I'm not that knowledgeable on parameters myself, so, this here is my limited knowledge of them, lol.

Function_or_Command_or_Verb_or_Turnscript_1:

get input (you type in 1)
A = result
get input (you type in 2)
B = result
Function_2 (A, B)

A (=1) -> red (=1)
B (=2) -> blue (=2)

Function_2 (red, blue):

C = 3 = red (=1) + blue (=2)
D = 2 = red (=1) * blue (=2)
Function_3 (C, D)

C (=3) -> up (=3)
D (=2) -> down (=2)

Function_3 (up, down)

E = 1 = up (=3) - down (=2)
msg (E)

the game player then sees on his~her screen: 1

~OR~

Function_or_Command_or_Verb_or_Turnscript_1:

get input (you type in 1)
A = result
get input (you type in 2)
B = result
Function_2 (A, B)

A (=1) -> A (=1)
B (=2) -> B (=2)

Function_2 (A, B):

a = 3 = A (=1) + B (=2)
b = 2 = A (=1) * B (=2)
Function_3 (a, b)

a (=3) -> A (=3)
b (=2) -> B (=2)

Function_3 (A, B)

C = 1 = A (=3) - B (=2)
msg (C)

the game player then sees on his~her screen: 1

-----------

so hopefully, you can see that in each "next" function, you can rename your "parameter_to_variable" for use in that "next" function or you can keep the same name too (NOT renaming them).

Avantar
Thanks for the explanation HK :)

So here is what I have decided to do for my first game while I learn the rest...
I am going to use these equip scripts discussed here for my weapons, the Experience formula you added here HK, the wearables library from Chase, Journal library from Pixie as well as his/her shop library.

The wearables library is precisely what I need for my armor, amulets, rings and so forth so why reinvent? - thx Chase!
I have already changed our equip script here for adding the bonuses from the various weapons available to me. My combat system is a bit shaky and not yet polished (very messy), but simple.

While I'm testing and implementing all of these libraries and some of my own, I am already thinking of how I will handle learning abillities/choose some abilities - for this I will start a new thread should I struggle. I figure that it should be similar to learning spells in the wiki.
I also have to go through grouping of rooms; since it might answer my question - Can you have multiple exits to the East - like having a hallway with lots of rooms to the one side?
Apart from that, it is crazy at work - so sorry for only posting back now.

This will surely be a challenge; since English is not my first language, but I would like to take this opportunity in thanking everyone for their help. (HK and Jaynabonne in particular)

HegemonKhan
I'm still not that knowledgeable about the EXITS myself, in how they work and~or what you can (and can't do) with them. I think you can set up multiple exits in the same direction (as I think the "compass directions" are arbitrary ~ as the "compass directions" are merely OBJECT TYPES, which you can see by doing in the GUI~Editor: left side of the screen ~ the "tree of stuff": Filter -> Show Library Elements -> find the stuff on it ~ left side of screen ~ "the tree of stuff" ~ light grey text).

You can, also not even use EXITS at all, you can move to any room you want via direct scripting, no need for the Exits at all.

here is a game file (as attachment at bottom) that you can test, or you can copy and paste this code below, into a new game file of your own:

Type in: help
Type in: explore
Type in: travel

<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>eef801a1-4e6b-4b0a-bdbf-8f3ecfa8389c</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
<turns type="int">0</turns>
<statusattributes type="simplestringdictionary">turns=</statusattributes>
</game>
<object name="homeland">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<object name="grassland">
<inherit name="editor_room" />
</object>
<object name="plains">
<inherit name="editor_room" />
</object>
<object name="desert">
<inherit name="editor_room" />
</object>
<object name="tundra">
<inherit name="editor_room" />
</object>
<object name="swampland">
<inherit name="editor_room" />
</object>
<object name="mountains">
<inherit name="editor_room" />
</object>
<object name="forest">
<inherit name="editor_room" />
</object>
<object name="wasteland">
<inherit name="editor_room" />
</object>
<object name="coastland">
<inherit name="editor_room" />
</object>
<object name="hills">
<inherit name="editor_room" />
</object>
<command name="help_command">
<pattern>help</pattern>
<script>
help_function
</script>
</command>
<command name="explore_command">
<pattern>explore</pattern>
<script>
explore_function
</script>
</command>
<command name="travel_command">
<pattern>travel</pattern>
<script>
travel_function
</script>
</command>
<object name="data_object">
<inherit name="editor_object" />
<travel_string_list type="simplestringlist">homeland</travel_string_list>
<homeland_events_string_list type="simplestringlist">grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery</homeland_events_string_list>
<homeland_events_script_dictionary type="scriptdictionary">
<item key="grassland_discovery">
list add (data_object.travel_string_list, "grassland")
msg ("You've discovered the grassland! Now, you can travel to the grassland and explore it!")
</item>
<item key="plains_discovery">
list add (data_object.travel_string_list, "plains")
msg ("You've discovered the plains! Now, you can travel to the plains and explore it!")
</item>
<item key="desert_discovery">
list add (data_object.travel_string_list, "desert")
msg ("You've discovered the desert! Now, you can travel to the desert and explore it!")
</item>
<item key="tundra_discovery">
list add (data_object.travel_string_list, "tundra")
msg ("You've discovered the tundra! Now, you can travel to the tundra and explore it!")
</item>
<item key="swampland_discovery">
list add (data_object.travel_string_list, "swampland")
msg ("You've discovered the swampland! Now, you can travel to the swampland and explore it!")
</item>
<item key="forest_discovery">
list add (data_object.travel_string_list, "forest")
msg ("You've discovered the forest! Now, you can travel to the forest and explore it!")
</item>
<item key="mountains_discovery">
list add (data_object.travel_string_list, "mountains")
msg ("You've discovered the mountains! Now, you can travel to the mountains and explore it!")
</item>
<item key="hills_discovery">
list add (data_object.travel_string_list, "hills")
msg ("You've discovered the hills! Now, you can travel to the hills and explore it!")
</item>
<item key="wasteland_discovery">
list add (data_object.travel_string_list, "wasteland")
msg ("You've discovered the wasteland! Now, you can travel to the wasteland and explore it!")
</item>
<item key="coastland_discovery">
list add (data_object.travel_string_list, "coastland")
msg ("You've discovered the coastland! Now, you can travel to the coastland and explore it!")
</item>
</homeland_events_script_dictionary>
</object>
<turnscript name="global_turnscript">
<enabled />
<script>
game.turns = game.turns + 1
</script>
</turnscript>
<function name="help_function">
msg ("Type 'explore' to explore your area.")
msg ("Type 'travel' to travel to different areas.")
</function>
<function name="explore_function"><![CDATA[
switch (game.pov.parent) {
case (homeland) {
result_1 = ListCount (data_object.homeland_events_string_list) - 1
if (result_1 >= 0) {
result_2 = StringListItem (data_object.homeland_events_string_list,GetRandomInt(0,result_1))
invoke (ScriptDictionaryItem (data_object.homeland_events_script_dictionary,result_2))
on ready {
foreach (item_x, split ("grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery",";")) {
if (result_2 = item_x) {
list remove (data_object.homeland_events_string_list, result_2)
}
}
}
} else {
msg ("There seemingly is nothing left to explore in this area.")
}
}
}
]]></function>
<function name="travel_function">
show menu ("Where do you wish to travel?",data_object.travel_string_list,false) {
if (not game.pov.parent = GetObject (result)) {
game.pov.parent = GetObject (result)
} else {
msg ("You are already at this area.")
ask ("Try again?") {
if (result=true) {
travel_function
} else {
msg ("You realize that you need to discover a new area to travel to first, before you can travel to that place.")
}
}
}
}
</function>
</asl>


------------------------

also, if you're interested, Jayne created a 3D random map~room generator!, I think it should be in the "libraries and free code" forum board, if you can't find it, let me know, and I'll find it's location for you. If you want something that isn't random, Jayne could probably help you with designing map~room design, how and what can be done with Exits, or with scripting.

-----------------------

Avantar
Aah, yes! That answers my question perfectly. Thank you.

Not that I want to change the topic or abuse your kindness - but I have spotted in a previous post about restoring health - it was one of your replies HK, so I thought I will ask...

I can make a potion that restore health and just add a script: player.health = player.health + 20 for example - but I will need restrictions. Fine...I can make a function that looks like this:
if (player.health = player.max_health) {
msg ("You are already at maximum health!")
}
else if (player.health < player.max_health) {
player.health = player.health + object.health
}
else {
player.health = player.max_health
}


But the thing is: How do I reference the health potion that I drank from; since object.health clearly won't work.

Thank you in advance again.

HegemonKhan
an example using a "drink" Verb for your "50_hit_point_potion" Object and a Command+Function too:

<command name="drink_command">
<pattern>drink #text#</pattern>
<script>
drink_function (player, text)
</script>
</command>

<function name="drink_function" parameters="self, text"><![CDATA[
item_x = GetObject (text)
if (item_x = null) {
foreach (object_x, ScopeInventory ()) {
if (object_x.alias = text or object_x.alt = text)
item_x = object_x
}
}
}
if (item_x = null) {
msg ("you don't have that item in your inventory")
} else if (GetString (item_x, "item_type") = hit_points_potion) {
invoke (item_x.drink)
// or:
// if (self.current_hit_points = self.maximum_hit_points) {
// msg ("you already have full hit_points")
// } else {
// self.current_hit_points = self.current_hit_points + item_x.hit_points
// msg ("you drink " + item_x.alias + ", restoring your hit_points by " + item_x.hit_points)
// if (self.current_hit_points > self.maximum_hit_points) {
// self.current_hit_points = self.maximum_hit_points
// }
// }
} // else if...
// blah scripts
} else {
msg ("you can't drink this item")
}
]]></function>

<object name="50_hit_point_potion">
<inherit name="editor_object" />
<take />
<alias>50_hp_pot</alias>
<alt type="simplestringlist">pot;hppot;pothp;50hppot;pot50hp;pothp50;hp;50hp;hp50</alt> // or whatever is it's correct syntax, meh
<hit_points type="int">50</hit_points>
<item_type type="string">hit_points_potion</item_type>
<drink type="script"><![CDATA[
if (player.current_hit_points=player.maximum_hit_points) {
msg ("you already have full hit_points")
} else {
player.current_hit_points = player.current_hit_points + 50_hit_point_potion.hit_points
msg ("you restore your hit_points by 50")
if (player.current_hit_points > player.maximum_hit_points) {
player.current_hit_points = player.maximum_hit_points
}
}
]]></drink>
<displayverbs type="simplestringlist">Take</displayverbs>
<inventoryverbs type="simplestringlist">Drop;Drink</inventoryverbs>
</object>

<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<current_hit_points type="int">500</current_hit_points>
<maximum_hit_points type="int">999</maximum_hit_points>
<hit_points type="string">0/0</hit_points>
<turns type="int">0</turns>
<statusattributes type="simplestringdictionary">hit_points =!;turns =</statusattributes>
</object>

<turnscript name="global_events_turnscript">
<enabled />
<script>
player.hit_points = "HP: " + player.current_hit_points + "/" + player.maximum_hit_points
player.turns = player.turns + 1
</script>
</turnscript>

Avantar
Many thanx! Got it working.

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

Support

Forums