Battle?

  • #10, by scotthMonday, 28. April 2014, 18:28 8 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


  • #11, by afrlmeMonday, 28. April 2014, 19:40 8 years ago
    I think you are over complicating your thinking. First things first... I would do a bit of research on exactly how hit chance is done in an RPG game. There's probably some documentation somewhere, here, or there.

    Then I would base your script on that.


    -- set as definition script
    local hero = game:getLink(VGameCurrentCharacter) -- get current character
    local hSpd = hero:getObject(".CharacterValues[speed]") -- get value speed of current character
    local hLvl = hero:getObject(".CharacterValues[level]") -- get value level of current character
    local hHit = hero:getObject(".CharacterValues[hit]") -- get value hit of current character
    local t = {}
    t["_temporary_"] = ""
    
    function hit_chance(e)
     t["enemy"] = getObject("Characters[" .. e .. "]") -- store linked enemy
     t["spd"] = t["enemy"]:getObject(".CharacterConditions[speed]"):getInt(VValueInt)
     t["lvl"] = t["enemy"]:getObject(".CharacterValues[level]"):getInt(VValueInt)
     t["evasion"] = t["enemy"]:getObject(".CharacterValues[evasion]"):getInt(VValueInt)
     -- * --
     t["hTotal"] = hLvl + hSpd + math.random(hHit, 100) -- level + speed + random hit value (current character)
     t["eTotal"] = t["lvl"] + t["spd"] + math.random(t["evasion"], 100) -- level + speed + random evasion value (linked enemy)
     -- * --
     if t["hTotal"] >= t["eTotal"] then return true else return false end
    end
    

    to use...
    -- execute a script
    hit_chance("add enemy name here") -- case sensitive
    

    This is just a quick example of return true or false for hit or miss based on difference between current character & the linked enemies speed, level & hit/evasion values. It returns true or false... if it returns true then you would sort out the damage dealt part of the script.

    Quick explanation of my math formula (I hate math)...
    Say my main character level is currently 22 & my character speed is 13 & my hit % is 75 then what we get is: 22 + 13 + random number between 75 & 100. Then same again for enemy but instead of checking enemy hit % we check their evasion % & if our total is greater than theirs then we return true (hit).

    math.random(val, 100) seems a little counterproductive, but you had the right idea in mind as the higher the hit/evasion value to 100 the more chance that you will return a higher value than a lower value. Say the enemy evasion value is 15, which means that the random value could be anything from 15 to 100, which means they have more chance of returning a lower number than a character with a hit value of say 75.

    Imperator

    7121 Posts

  • #12, by scotthTuesday, 29. April 2014, 08:11 8 years ago
    Funny, didn't even think of an evasion rating as the counter to a tohit rating.
    Good stuff. But I still cannot figure out how to write a value back to one of the Character/Values
    This isn't just about calculating hit chance, this could be used to do a lot of things.
    Is this even close? sum would be the variable whose value you want to write back to AppleToHitChance.

    sum:setValue("Values[AppleToHitChance]")

    This just seems to make sense seeing as how you access the value in a very similar way.
    It could be, I suppose, that I am wanting to do something that just doesn't work. Seems like it should though... (If not using the phrasing above then in some manner)

    Thanks again for you help and patience.

    Newbie

    13 Posts

  • #13, by scotthTuesday, 29. April 2014, 18:31 8 years ago
    So with some more research and digging I may be getting closer to an answer...
    Values are saved in the ved-file and the savegame.
    Value / ValueInt (integers) / t_int is scriptable meaning it can be written.
    found two different things related:
    values you change must use a field constant to change which is V followed by field name (but this may not be for single values).
    and setValue() is to edit the value of the linked object (all data types).

    so interesting information.
    will dig more and see what I can come up with. may also have to ask this specific question on the general forum...

    Newbie

    13 Posts

  • #14, by afrlmeTuesday, 29. April 2014, 21:51 8 years ago
    to set value you have to link to value like so...
    getObject("Values[value_name]"):setValue(VValueInt, variable or number)
    

    or...
    var = getObject("Values[value_name]")
    var:setValue(VValueInt, variable or number)
    

    etc.

    Imperator

    7121 Posts

  • #15, by scotthWednesday, 30. April 2014, 04:43 8 years ago
    Hey AFRLme, thanks! Both examples worked, though the second was iffy at first. Had it stuck in my head that I had to get the original value name back in on line 2. Took me a while to realize that the variable set in line one ultimately takes the place of (not just equals) the original value.

    Greatly appreciated!

    Newbie

    13 Posts

  • #16, by afrlmeWednesday, 30. April 2014, 13:03 8 years ago
    No problem... Like I said, you were just over-complicating things a wee bit! wink

    Did you check the link (further up the thread somewhere) that I provided for getObject wiki article with examples?

    Imperator

    7121 Posts