Battle?

  • #1, by scotthThursday, 17. April 2014, 06:07 10 years ago
    Is there a good way to get a battle into a scene? Any tutorials?
    I've searched but I'm not having any luck finding anything. The battle could be action oriented, based on stats and the roll of some dice, I'm pretty open. But I do need some way to resolve combat situations. Any help would be great,
    thanks!

    Newbie

    13 Posts


  • #2, by dos4gwThursday, 17. April 2014, 08:09 10 years ago
    Yes, I think it's quite possible to make something turn based, or even real time, though that would be trickier. You'll likely be working with values. You can assign those to characters, as you may be aware. Just a disclaimer: I haven't actually done something like this before, I'm just giving you what I think would work.

    Say your player character is labeled "Hero." Create a value "HeroHealth" under its value tab. Set the current value to 100, the minimum to 0 and the maximum to 100.

    You could also have one called "HeroChanceToHit," "HeroDefense," "HeroStrength." These you could set between 1 and 10, just to make things simple. Also create the value "HeroSwing." You don't need to bother setting a number for this.

    Create a character "Troll," and create values for it like you have for "Hero."

    So, let's say you want to have the player try to hit the troll with his sword. For simplicities' sake, that will just be a left click on the troll. Create an action under the Troll's action tab, and set the Execution type to "Left Click" under "Execute Immediately."

    So let's see if the hero successfully hits the troll. Back to the Troll's action tab and the left click option. Use the action part "Set random value," designate "HeroSwing" and set the min and max to 0-5.

    Next, use the "Set value" action part. In the first box, pick "HeroSwing," set operator to +, then the other value "HeroChanceToHit." Say you set "HeroChanceToHit" to 5 earlier, and the "HeroSwing" was set to 4 by "Set random value." So "HeroSwing" is now 9 based on hit skill and a random element.

    Now use the "If value." First box is "HeroSwing," make the operator ">" and set the final box as "TrollDefense" which let's say you chose to be 8 earlier. "HeroSwing" is greater than "TrollDefense," so the hit connects.

    Let's use "HeroSwing" again to determine how much damage is dealt to the troll. Set a random number to it again, let's say 1-20 this time, then add "HeroStrength" to it. Use "set value" again: "TrollHealth" - (minus) "HeroSwing." And the troll takes this amount of damage. End the "if" section with an "end if," obviously.

    So use your own numbers, maths, and stat systems, but this is how I'd set this up at a basic level. If you're doing something real time, you can include response actions to attacks such as dodging or parrying, which would possibly increase "HeroDefense" for a certain amount of time. Something that uses timed events like that will likely require some scripting, though.

    Anyway, I hope this was more or less what you were looking for, and good luck on your game. smile

    Newbie

    69 Posts

  • #3, by scotthThursday, 17. April 2014, 16:35 10 years ago
    Thanks dos4gw. Before going any further in my game creation, I will try to implement a battle scene based off of what you suggested. I just couldn't wrap my head around how to get started for some reason.
    Will be back with results or more questions. grin

    Newbie

    13 Posts

  • #4, by scotthFriday, 18. April 2014, 05:52 10 years ago
    Put together a very quick mini-game based on dos4gw's advice. (Sorry, slapped together quick so no animations). The logic flow is very crude yet but it works (though the enemy only attacks if he's hit). I'm very excited about the possibilities. Check it out and feel free to critique, give advice, etc.

    Newbie

    13 Posts

  • #5, by dos4gwFriday, 18. April 2014, 10:34 10 years ago
    Glad I could help. I definitely think this shows promise. smile

    Couple things:
    -Every attack seems to hit. Played it out multiple times and I don't believe I've seen a miss yet.
    -I noticed that you had a value defined for minimum or max health. Seems easier to me to just check the health value against zero instead.

    Also, I'm wondering if setting a value a a random number in the values tab creates a random number once, or if it generates a new one whenever it's called. Not sure on thi one.

    Newbie

    69 Posts

  • #6, by scotthFriday, 18. April 2014, 17:17 10 years ago
    I think it is setting the random value a single time.
    I did one quick play where I tried to hit the pear 20+ times and never struck.
    Lots to work out but this is a great place to start. Thanks again.
    I'm almost wondering if the battle should take place in a different scene (the background art could stay the same so there is no real transition) and then you could set a bunch of values that are scene specific, not just character specific. I will play with this a bit throughout the weekend. Will update with progress. My ultimate goal is something like this very crude mockup. Where the player and AI each have specific actions they can take (almost card game like) but with some of the actions where possible being that they can interact with the environment. An example would be the apple (player) could spit seeds at the hornet nest to drop the nest on the pear.

    Newbie

    13 Posts

  • #7, by afrlmeFriday, 18. April 2014, 17:49 10 years ago
    I think this would actually be easier to create using a bit of Lua script.

    For instance take the hit percentage... say my current hit percentage was 77 out of 100. I would do something like:
    if math.random(100) <= 77 then
     startAction("Actions[hit]")
    else
     startAction("Actions[miss]")
    end
    

    it would make it 77 chances out of 100 to return hit.

    The health, magic, stamina bars etc would be possible to do in 2 different ways.
    1. you could create multiple images which are shown/hidden based on condition assigned to them. or 2 you could create an interface for each & set the interface areas around the bars themselves so that only parts of images/animations inside of the interface section will be shown. You could shift the animation assigned to each bar left/or right to show more or hide. Or you could use Lua to position it based on percentage (a lot harder to do).

    * Here is something I created ages ago which showed a bar filling up based on how many times you managed to press the "x" button of the keyboard in so many seconds. It uses the second method I mentioned (above) about the health, magic, stamina bars. Ideally I would like it if Alex or one of the other devs could add an entry to the data structure for controlling the percentage (integer) of displayed image/animation & from which direction it should be displayed from (from: top, bottom, left, or right).

    Imperator

    7278 Posts

  • #8, by dos4gwFriday, 18. April 2014, 19:21 10 years ago
    Looks quite interesting, scotth. Looking forward to seeing what you come up with. smile

    Newbie

    69 Posts

  • #9, by scotthMonday, 28. April 2014, 05:22 10 years ago
    Having trouble getting scripts to communicate with values set in character "Values" tab.

    This simple script is just a random number generator which then adds in bonuses based on numbers from the Values tab.
    And ultimately should change the value of AppleToHitChance.

    This was placed as an "Execute script" action triggered by a mouse click. I know the mouse click works because there are other things listed after this such as display narration text which works.

    Obviously I'm not understanding how to create a bridge between the Visionaire values and scripted values...
    I found something about adding a v in front of the variables like vAppleStamina rather than just AppleStamina but couldn't figure out the rest. Any help would be greatly appreciated.


    -- This is the random number generator that can be called.
    function chance()
      counter = 0
      while counter < 20 do
        counter=counter+1
        random_number=math.random(80,100)
      end
    end
    -- 
    --
    
    -- 
    --
    math.randomseed(os.time())
    
    chance()
    sum = random_number + AppleStamina + AppleReflexes - AppleFatigue
    -- The last three variables are set in the character's Values tab.
    
    over_possible = sum
    if sum > 100 then
      sum = 100
    end
    
    -- I need to be able to send the new value of AppleToHitChance back to the game.
    -- Basically it needs to replace the value that was set in the character's Values tab.
    
    AppleToHitChance = sum
    
    

    Newbie

    13 Posts

  • #10, by afrlmeMonday, 28. April 2014, 12:33 10 years ago
    could you add it to code block instead of spoiler block please?

    ok to get value you have to do something like this...
    aplStamina = getObject("Values[AppleStamina]")
    
    aplStamina:getInt(VValueInt) -- would return integer value of aplStamina
    aplStamina:setValue(VValueInt, 80) -- or add variable in place of number
    

    I'm not understanding what the while loop & count of 20 is for. Nor why you are creating a random numbering between 80 & 100. Also quick note: you are creating global variables inside of a function which is not really a good idea, as they could potentially cause issues with other scripts.

    Seeing as you are creating temporary returns, I would instead set up a temporary table.

    Anyway here is a wiki page I wrote on getting objects from the data structure. I have not yet written up the getInt or setValue pages yet but you can find out some information on them here.

    The V thing you mentioned is for use with data structure fields. for example:
    game:getLink(VGameCurrentCharacter) -- gets currently active character
    getObject("Characters[protagonist]"):getLinks(VCharacterActions) -- returns all actions of the linked character
    -- etc...
    

    If you give me a detailed explanation of eaxactly what you are wanting to do, then maybe I can help point you in the right direction.

    Imperator

    7278 Posts

  • #11, by scotthMonday, 28. April 2014, 18:28 10 years ago
    Sorry, too much non-important 'scott just playin' around' stuff in the first example.
    So I have no specific thing I'm trying to do at the moment other than learn some stuff.

    What I need to do for my plans, however, is take values set in the character's values tab, do some math, and come back with new values.

    -- These three lines should get me info from the character values tab, yes?
    --  If AppleStamina is set at 2, then astamina in this script is now also 2.
    astamina = getObject("Values[AppleStamina]")    
    areflex = getObject("Values[AppleReflexes]")    
    afat = getObject("Values[AppleFatigue]")           
    
    -- some extra number for the sake of example.  this could be all manner of complex math...
    random_number = math.random(1,10)  
    
    -- adding all of my various numbers together just doing some basic math
    sum = random_number + astamina + areflex - afat  
    
    
    -- I need to be able to send the new value of AppleToHitChance back to the game.
    -- Basically it needs to replace the value that was set in the character's Values tab.
    -- This number will grow as the character gains experience.
    -- Also, the above three values (AppleStamina, etc.) will grow as well and will need to change.
    
    -- AppleToHitChance = sum
    -- This is the part I really can't figure out...  maybe too early in the morning & need more coffee.
    -- are any of these close?  do I need the character's name somewhere?
    
    sum:setValue("Values[AppleToHitChance]")
    sum:setValue(vAppleToHitChance)
    sum:setValue(VAppleToHitChance)
    
    AppleToHitChance:setValue(VValueInt, sum)
    
    


    Thanks AFRLme for your help, it is greatly appreciated!

    Newbie

    13 Posts