Need help creating some custom commands in an RPG

MikeOmega
09 Aug 2012, 16:37
Hello everyone!
I've been tinkering around with Quest 5 for a few days now and I am attempting to create a RPG with some custom commands. I'm afraid that I am not very good with code-writing, so this has been quite a challenge for me. I have a command I have titled "combine" which I would like to take two items in the player's inventory and use them to create an entirely new item with attributes from both the originals. In this example, the player has three status attributes, health, armor and strength, each with an integer value. At the start of the test game, the player already has two items in his inventory, a helmet and a sword. The helmet has its own unique attribute of "armor" which has a integer value of 10, and the sword has its own unique attribute of "power" with an integer value of 10. My first stumbling block was having the command check for both the separate objects in the player's inventory. The player command is "Combine #object# and #object# . I attempted an If-Then script which would check if the player has two different objects by their name stated in the command. I have a temporary fix by creating my own expression "If Got(object) and Got(object)" and the "then" statement I chose from the dropdown was to create an object I called "strangematter". How do I set the new object "strangematter" to have the attributes of both the objects the uses in the commands, the power and armor integer values? And how do I set this created object's name or alias to that which combines the names of the objects specified in the command?

Another command I am having trouble with is an equip command, which allows for a player to equip an item in his inventory, which then adds the value of certain attributes of the item to player status attributes. Such as, if a player were to equip a helmet mentioned earlier, the integer value of the helmet's armor attribute would be added to the player's armor status attribute. Now the problem is, you can use the equip command multiple times and it just keeps stacking the values regardless of whether or not an object is already equipped. Is there a way to make the equip command only work if the object is not already equipped?

The final command I can't seem to grasp is an attack command that, like the others, works generally for multiple objects. I have a monster simply called "monster" and when the player uses the command "attack #object#" I would like for damage to be done to the object specified in user's command via subtracting the player's strength (player.strength) from the object's health (object.health). This seems to work, but then I want the attack command to check if the object attacked has health less than or equal to zero and if so, to display a message saying that the creature is dead. If there is more than one item in the room, the script seems to have trouble recognizing which object I want the command to reference. How do I fix this?

I have uploaded the test game with the commands available. Any help you all could offer would be greatly appreciated!

UPDATE

Now I'm just trying to figure out a command script for enemy attacks. I want enemies to attack on a timer, but I don't want to code 1000 different timers for every enemy in every room. I was hoping to find a single script that can be called for every enemy of a certain type or possessing attribute and triggered when a player enters any room, but I'm having trouble getting the generic code to refer to a specific monster object or room. Is there any way I can do that? (I do hope I have worded that properly)

sgreig
09 Aug 2012, 19:24
MikeOmega wrote:At the start of the test game, the player already has two items in his inventory, a helmet and a sword. The helmet has its own unique attribute of "armor" which has a integer value of 10, and the sword has its own unique attribute of "power" with an integer value of 10. My first stumbling block was having the command check for both the separate objects in the player's inventory. The player command is "Combine #object# and #object# . I attempted an If-Then script which would check if the player has two different objects by their name stated in the command. I have a temporary fix by creating my own expression "If Got(object) and Got(object)" and the "then" statement I chose from the dropdown was to create an object I called "strangematter". How do I set the new object "strangematter" to have the attributes of both the objects the uses in the commands, the power and armor integer values? And how do I set this created object's name or alias to that which combines the names of the objects specified in the command?


Maybe I'm missing something here, but why would the player be combining the helmet and sword? And I'm a little fuzzy on what you're actually trying to accomplish here. If you could give some more detail it would be helpful.

MikeOmega wrote:Another command I am having trouble with is an equip command, which allows for a player to equip an item in his inventory, which then adds the value of certain attributes of the item to player status attributes. Such as, if a player were to equip a helmet mentioned earlier, the integer value of the helmet's armor attribute would be added to the player's armor status attribute. Now the problem is, you can use the equip command multiple times and it just keeps stacking the values regardless of whether or not an object is already equipped. Is there a way to make the equip command only work if the object is not already equipped?


This one's actually fairly easy, and you've pretty much got it right, you're just overlooking something simple. All you need to do is add an attribute to the object, let's call it "equipped". Then, you just need to change your code to alter the attribute when the item is equipped/unequipped. So, if the player types "equip helmet" it will change the value of helmet.equipped to "1". The other change you need to make to the equip command is to have it check the "equipped" value of the object. If the value is "1" or "true" or whatever you set it to, have it display a message saying the item is already equipped. Don't forget to change the value back to "0" or "false" when the item is unequipped as well.

Using something similar to this, you could also pretty easily make a check to ensure the player can't equip mutliple types of the same item, like multiple helmets, for example.

MikeOmega wrote:The final command I can't seem to grasp is an attack command that, like the others, works generally for multiple objects. I have a monster simply called "monster" and when the player uses the command "attack #object#" I would like for damage to be done to the object specified in user's command via subtracting the player's strength (player.strength) from the object's health (object.health). This seems to work, but then I want the attack command to check if the object attacked has health less than or equal to zero and if so, to display a message saying that the creature is dead. If there is more than one item in the room, the script seems to have trouble recognizing which object I want the command to reference. How do I fix this?

I have uploaded the test game with the commands available. Any help you all could offer would be greatly appreciated!


This is probably got something to do with how you've got the object referenced in the command. I'll download your test file now and have a look and see if I can figure out what's wrong.

EDIT:
I took a look at your file and made some small changes. Firstly, I changed the equip/unequip code with the changes I mentioned above. Looks like you were even closer to the right solution than you indicated, because you already had an equipped attribute set on the objects.

Secondly, I altered the attack command slightly. First of all, I used a new variable. It's not a great idea to leave the variable as just "object" because that can lead to problems, so I called it "object_monster". Important thing to remember is that the variable always has to start with what kind of thing it's referencing, so if it's an object, it has to start with "object" or it won't work. I also edited the damage check to "if (object_monster.health = 0)" to "if (object_monster.health <= 0)". Otherwise the command won't work properly unless the monster's health is exactly 0. This way it will work if it slips into the negatives as well.

Thirdly, I altered the variable names for the combine command. As I stated before, it's a good programming practice to not do that because it can cause problems, so I altered it to "object_1" and "object_2". And that could explain the problems you were having getting it to work from before.

I haven't tested any of this so it's possible it might not work, but it should.

MikeOmega
09 Aug 2012, 19:54
sgreig wrote:Maybe I'm missing something here, but why would the player be combining the helmet and sword? And I'm a little fuzzy on what you're actually trying to accomplish here. If you could give some more detail it would be helpful.


There is no actual reason why someone would combine a sword and a helmet, it's just so that if they wanted to, they could. The two items there are just examples. Say if you wanted to combine peanut butter which has the attribute "peanut", and chocolate which has the attribute "chocolate" to make a Reese's penut butter thing with both the attributes "peanut" and "chocolate" pulled from the objects used to create it.. Or anything. I want to be able to combine any object with any other object to create something with both attributes. I've always liked the thought of having a customizable inventory in such a way, just for its absurdity. I find the concept rather amusing, and I thought it might be possible.

As for the equipping object, thanks a lot! I don't know how I overlooked that!

sgreig wrote:This is probably got something to do with how you've got the object referenced in the command. I'll download your test file now and have a look and see if I can figure out what's wrong.


I believe I have the command to attack reference the object simply as object. I wanted a general term to apply to all objects so that they all can be attacked, and only them. And I may have already resolved that error, but checking in any case would be appreciated.

Thank you very much for the help thus far

MikeOmega
09 Aug 2012, 19:56
You responded to that quite quickly, I had just finished my other reply. Thank you again, sgreig, I'm going to check the files now!

UPDATE

Ah! Perfect! Now all commands seem to be working fine! I didn't realize you could specify what object in the command line with "object_1, object_2" etc. Thank you so much! This has really, really opened my eyes!

MikeOmega
09 Aug 2012, 20:26
Alright, now I am having a bit of trouble. How does one go about creating a battle script to make an enemy attack the player on a timer? Would I have to make some sort of script for every single enemy object in a given room, or could I somehow make a single script that would run for every enemy object in every room in the entire game?

sgreig
09 Aug 2012, 21:14
I imagine you could probably just write the one timer script and attach it to a type, and then make any objects in the game that need that time part of that type. I don't know if you've learned about Types yet, but they function very similarly to objects in Object Oriented Programming. The Type has certain characteristics shared by different types of objects, and any object of that type inherits the qualities of the type. So you could make a monster type with all the necessary status attributes, and possible with the timer script, and then just make the monsters part of that type.

MikeOmega
09 Aug 2012, 21:38
sgreig wrote:I imagine you could probably just write the one timer script and attach it to a type, and then make any objects in the game that need that time part of that type. I don't know if you've learned about Types yet, but they function very similarly to objects in Object Oriented Programming. The Type has certain characteristics shared by different types of objects, and any object of that type inherits the qualities of the type. So you could make a monster type with all the necessary status attributes, and possible with the timer script, and then just make the monsters part of that type.


Ah, alright, I understand what you are telling me, but I am not exactly sure how to set that up in Quest. I have created the object type, but how do I make the timer script recognize the type? I can't tell which script would refer to that... Can you provide an example of how I might do that?

sgreig
09 Aug 2012, 22:23
I'd have to look into it, as I've never actually done it... I was more theorizing that if it could be done, that would be the way to do it. Someone like Pertex might be slightly better suited to answering this question, but I'll take a gander and see if I can figure it out in the meantime.

MikeOmega
09 Aug 2012, 22:55
sgreig wrote:I'd have to look into it, as I've never actually done it... I was more theorizing that if it could be done, that would be the way to do it. Someone like Pertex might be slightly better suited to answering this question, but I'll take a gander and see if I can figure it out in the meantime.


I see... Well, I am having some considerable trouble with it now that I am trying. I greatly appreciate you taking a look.

Pertex
10 Aug 2012, 06:22
MikeOmega wrote:Alright, now I am having a bit of trouble. How does one go about creating a battle script to make an enemy attack the player on a timer?

What does this mean? Should the player attacked after some time automatically?

Perhaps you find some ideas here: viewtopic.php?f=10&t=2660

MikeOmega
10 Aug 2012, 13:30
Pertex wrote:What does this mean? Should the player attacked after some time automatically?

Perhaps you find some ideas here: viewtopic.php?f=10&t=2660


Yes, precisely. I would like it to be set if the player and the enemy are in the room, then the enemy attacks at a set interval until it is dead. But I need the script to be somewhat general, so it applies to all enemies with a certain type and attribute. But thank you for the link!

Pertex
10 Aug 2012, 15:50
Hmmm, my first solution would be a turnscript that checks every turn if there is a monster in the players room. If so it starts a timer. When this timer fires it calls an attack function using the monster object as a parameter. This function calculates the attack with the monsters attributes. The problem is the correct handling of the timer and turn script.

MikeOmega
10 Aug 2012, 16:27
Pertex wrote:Hmmm, my first solution would be a turnscript that checks every turn if there is a monster in the players room. If so it starts a timer. When this timer fires it calls an attack function using the monster object as a parameter. This function calculates the attack with the monsters attributes. The problem is the correct handling of the timer and turn script.


Ok, but is there a way I can get the script to check for a type or attribute on all objects to see if they are monsters? I don't want it to check for a specific monster object. So this one script could apply to any object in the game with the type or attribute "monster"? I'm afraid I', still very new at this. When I ask the script to check for "object.monster" It gives me an error telling me that "object" is an unknown variable or object.

Pertex
10 Aug 2012, 20:03
Here is an example how to do it. If you enter the second room, you will find a monster. The orc has the type "monster" which is checked in the turnscript "checkmonster". Then the function attack is called.

MikeOmega
10 Aug 2012, 20:17
Pertex, thank you so much! Looking at this in the editor, I can now understand. I am very grateful!