mIRC Home    About    Download    Register    News    Help

Print Thread
Help with an roguelike alias #270105 01/04/22 06:30 PM
Joined: Apr 2022
Posts: 7
Z
Zenti Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Apr 2022
Posts: 7
Hello all of you, I've been writing a kind of Rogue Like Game Script for Mirc for a long time.
Here I come across a problem of the generation of the armor.
I have already written the alias for it but I do not know exactly how to determine the corresponding values?

Questions: How would you have the values determined? Should they be randomly determined by a value of $rand(v1,v2) or otherwise?
Here is the code:
Code
alias generate_armor {
  var %validequiplocations head.body.legs.feet.hands
  set %random.location $rand(1, $numtok(%validequiplocations,46))
  set %location-a $gettok(%validequiplocations, %random.location, 46)
  var %armorname %equipmentprefix
  var %hp $rand(1,900)
  var %tp $rand(1,100)
  var %Def $rand(1,5000)
  var %int $rand(1,5000)
  var %spd $rand(1,5000)
  var %str $rand(1,5000)
  var %augment %augments
  var %location %location-a
  var %cost 0
  var %Sellprice $rand(1,5000)
  var %Level $rand(1,21000)
  set %protection-a $rand(0,10) $+ . $+ $rand(0,9)
  write $lstfile(armor_ $+ %location-a $+ .lst) %armorname
  writeini $dbfile(Equipment.db) %equipmentprefix Name %armorname
  writeini $dbfile(Equipment.db) %equipmentprefix Hp %hp
  writeini $dbfile(Equipment.db) %equipmentprefix Tp %tp
  writeini $dbfile(Equipment.db) %equipmentprefix Str %str
  writeini $dbfile(Equipment.db) %equipmentprefix Def %def
  writeini $dbfile(Equipment.db) %equipmentprefix Int %int
  writeini $dbfile(Equipment.db) %equipmentprefix Spd %spd
  writeini $dbfile(Equipment.db) %equipmentprefix Augment %augments
  writeini $dbfile(Equipment.db) %equipmentprefix EquipLocation %location
  writeini $dbfile(Equipment.db) %equipmentprefix Cost 0
  writeini $dbfile(Equipment.db) %equipmentprefix SellPrice %Sellprice
  writeini $dbfile(Equipment.db) %equipmentprefix LevelRequirement %Level
  writeini $dbfile(Equipment.db) %equipmentprefix Protection %protection-a
}


Thanks for ideas....

Re: Help with an roguelike alias [Re: Zenti] #270107 02/04/22 01:28 PM
Joined: Jan 2004
Posts: 1,745
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,745
It depends on what kind of distribution you want for the results. Do you want an even distribution like how rand(1,10) allows each outcome to be as common as every other outcome? Or do you want it to be like throwing 2 dice, where out of 36 outcomes 6 of them will be total 7, while only 1 of 36 times will the total be 12.

https://mircscripts.net/j6hi0

Here's an example of using uneven distribution. Notice how you can get some unusual outcomes by having the v1 and v2 themselves be randoms. For your function wanting a random number to 1 decimal, an other way that's easier for you to read later on is to do something like:

set %protection-a $rand(0,109) / 10

I suspect you really intended your max to be 10.0 not 10.9

Re: Help with an roguelike alias [Re: maroon] #270112 02/04/22 09:06 PM
Joined: Apr 2022
Posts: 7
Z
Zenti Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Apr 2022
Posts: 7
I want the values to be adjusted based on the player level but not too high. To ensure a random choice as it is the case with a Rougue Like game there is also randomly chosen from a range but also not too high. Do you understand? First of all, thank you for the information.

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

To explain it better I come from Germany I apologize for my bad English. A player has example the level 10 which is determined in a varialble %level by means of $getlevel() from an alias and is saved. Now I want to use this variable to determine a kind of loot example of an armor. I'm just unsure how to implement this.... The New Armor or something like that is supposed to be a little better than the Old Armor he wears. But the values should still be randomly rolled out.. How should I proceed?


Last edited by Zenti; 02/04/22 10:39 PM.
Re: Help with an roguelike alias [Re: Zenti] #270113 03/04/22 03:09 AM
Joined: Apr 2022
Posts: 7
Z
Zenti Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Apr 2022
Posts: 7
Currently, the code of the armor generation is as follows:
I'm not quite at peace with the distribution of values yet, he's still rolling too high for me.
Another problem what I have if the player rises a level how do I increase the values? the level is put out with $get.level($nick). So I have it At the moment there are now 3 queries: Vllt you have suggestions for improvement to code optimization etc.

Code
on 1:text:!!aug*:#: { 

  ;; check if $2 is a player in the game or not, if not do nothing
  if ($isfile($char($2)) != $true) { msg # sorry $2 is not a player in this game }

  ;;;;;;;define the augments that stored in a file.
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  var %aug1 $lines($lstfile(augments.lst))
  set %augline $rand(1,%aug1)  
  while (%aug1 >= 1) {
    %augs = $addtok(%augs, $read($lstfile(augments.lst), %aug1), 46)
    dec %aug1
    ;echo Zufälliges Augment %augs
  }

  ;;;;select 3 Random Augments and set it
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  set %current.aug $numtok(%augs,46)
  var %x 3
  while (%x >= 1) {
    %augments = $addtok(%augments,$gettok(%augs,$rand(1,%current.aug), 46), 46)
    dec %x
  }

  ;;;;;;;;;;;;;generate an itemname
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  $set_item_names

  ;;;;;;;;;;;;;;;;;;;;check if the item exists if not write the data to the file
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  if (%equipmentprefix isin $read($lstfile(armor_body.lst), w, * $+ %equipmentprefix $+ *)) || (%equipmentprefix isin $read($lstfile(armor_head.lst), w, * $+ %equipmentprefix $+ *)) || (%equipmentprefix isin $read($lstfile(armor_feet.lst), w, * $+ %equipmentprefix $+ *)) || (%equipmentprefix isin $read($lstfile(armor_legs.lst), w, * $+ %equipmentprefix $+ *)) || (%equipmentprefix isin $read($lstfile(armor_hands.lst), w, * $+ %equipmentprefix $+ *)) && ($readini($dbfile(equipment.db), %equipmentprefix, Name) != $null) { 

    msg $chan rüstung existiert bereits kann nicht erstellt werden.
  }
  if (%equipmentprefix !isin $read($lstfile(armor_body.lst), w, * $+ %equipmentprefix $+ *)) || (%equipmentprefix !isin $read($lstfile(armor_head.lst), w, * $+ %equipmentprefix $+ *)) || (%equipmentprefix !isin $read($lstfile(armor_feet.lst), w, * $+ %equipmentprefix $+ *)) || (%equipmentprefix !isin $read($lstfile(armor_legs.lst), w, * $+ %equipmentprefix $+ *)) || (%equipmentprefix !isin $read($lstfile(armor_hands.lst), w, * $+ %equipmentprefix $+ *)) && ($readini($dbfile(equipment.db), %equipmentprefix, Name) == $null) { 

    msg $chan %equipmentprefix does not exist and can be created
    $generate_armor($2)
    msg $chan Armor %equipmentprefix was successfully generated.
  }
}

alias generate_armor {
  var %validequiplocations head.body.legs.feet.hands
  set %random.location $rand(1, $numtok(%validequiplocations,46))
  set %location-a $gettok(%validequiplocations, %random.location, 46)
  var %armorname %equipmentprefix
  set %ahp $randnow2(1,450, 1,900, 60)
  set %atp $randnow2(1,50, 1,200, 60)
  set %aDef $randnow2(1,$rand(1,2500), 1,$rand(1,5000), 60)
  set %aint $randnow2(1,$rand(1,2500), 1,$rand(1,5000), 60)
  set %aspd $randnow2(1,$rand(1,2500), 1,$rand(1,5000), 60)
  set %astr $randnow2(1,$rand(1,2500), 1,$rand(1,5000), 60)
  $get.mid.vert($1)
  var %augment %augments
  var %location %location-a
  var %cost 0
  set %aSellprice $randnow2(1,2500, 1, 5000, 60)
  set %aLevel $randnow2(1,10500, 1, 21000, 60)
  ;set %aLevel $calc($get.level($nick) + 1)
  set %protection-a $calc($rand(1,10) / 10)
  set %mid.vert.new.eq $round($calc(%ahp + %atp + %astr + %int + %adef + %aspd / 6),0)
  if (%mid.vert.current.eq < %mid.vert.new.eq) {
    ;write $lstfile(armor_ $+ %location-a $+ .lst) %armorname
    ;writeini $dbfile(Equipment.db) %equipmentprefix Name %armorname
    ;writeini $dbfile(Equipment.db) %equipmentprefix Hp %ahp
    ;writeini $dbfile(Equipment.db) %equipmentprefix Tp %atp
    ;writeini $dbfile(Equipment.db) %equipmentprefix Str %astr
    ;writeini $dbfile(Equipment.db) %equipmentprefix Def %adef
    ;writeini $dbfile(Equipment.db) %equipmentprefix Int %aint
    ;writeini $dbfile(Equipment.db) %equipmentprefix Spd %aspd
    ;writeini $dbfile(Equipment.db) %equipmentprefix Augment %augments
    ;writeini $dbfile(Equipment.db) %equipmentprefix EquipLocation %location
    ;writeini $dbfile(Equipment.db) %equipmentprefix Cost 0
    ;writeini $dbfile(Equipment.db) %equipmentprefix SellPrice %aSellprice
    ;writeini $dbfile(Equipment.db) %equipmentprefix LevelRequirement %aLevel
    ;writeini $dbfile(Equipment.db) %equipmentprefix Protection %protection-a
    msg $chan $1 Gets the following armor: %equipmentprefix $+ . with this Attributes HP: %ahp TP: %atp STR: %astr DEF: %adef INT: %aint SPD: %aspd Level: %alevel -> Location: %location -> Augments: %augments
    unset %augments | unset %augs | unset %location-a | unset %random.location | unset %protection-a | unset %equipmentprefix
  }
}

alias get.mid.vert {
  set %current.equipped $readini($char($1), equipment, %location-a)
  set %eq-hp $readini($dbfile(equipment.db), %current.equipped, hp)
  set %eq-tp $readini($dbfile(equipment.db), %current.equipped, tp)
  set %eq-str $readini($dbfile(equipment.db), %current.equipped, str)
  set %eq-def $readini($dbfile(equipment.db), %current.equipped, def)
  set %eq-int $readini($dbfile(equipment.db), %current.equipped, int)
  set %eq-spd $readini($dbfile(equipment.db), %current.equipped, spd)
  set %mid.vert.current.eq $round($calc(%eq-hp + %eq-tp + %eq-str + %eq-def + %eq-int + %eq-spd / 6),0)
  msg #AiroRPG The Mid value of $1 Armor is: %mid.vert.current.eq
  return %mid.vert.current.eq
}

alias set_item_names {
  var %prefixline $lines(prefix.txt)
  var %suffixline $lines(suffix.txt)
  set %equipmentprefix $replace($read(suffix.txt, $rand(1,%suffixline)),$chr(32),_) $+ _ $+ $replace($read(prefix.txt, $rand(1,%prefixline)),$chr(32),_)
  var %equipmentprefix
}

Re: Help with an roguelike alias [Re: Zenti] #270114 03/04/22 05:27 AM
Joined: Jan 2004
Posts: 1,745
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,745
It sounds like you're asking for advice on how high to make the settings for various features. This is something that would need testing under game conditions to see whether the offense or defense is too strong.

It's something that role playing games do often, where they have levels for armor, attack,shields, rate of restoration, energy creation, energy usage, etc

What they sometimes do is have a base number, and then and then each level increases the exponent by maybe 0.1

So if a weapon has a base of 1000, and they're level 0, then it has a strength of $calc( 1000 * (1 + 0/10)), which is 1000. If they're level 5, then the formula is $calc( 1000 * (1 + 5/10)) = 1500. Likewise, the defense can get a similar boost to shields and/or armor. To avoid the interaction being completely predictable, the 1000 and 1500 can be maximums, and you can have it be a random between 90-100%. Or, you can use the method shown in the prior post's link to make the outcome be irregular instead of having every outcome be equally possible.

You can probably find websites describing the minutia of online games like E2 or Evony which describe the math behind how the attack and defense works. Do you have a picture in mind of how you want the distribution of outcomes to be? like a bell curve with a bump in the middle? Once you know how often each outcome should happen, including the max and min, it should be easy to come up with formula to mimic that

Re: Help with an roguelike alias [Re: maroon] #270117 03/04/22 03:26 PM
Joined: Apr 2022
Posts: 7
Z
Zenti Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Apr 2022
Posts: 7
Yes, you are probably right so that the right formula for throwing out the values is found, I probably have to do several test runs. In any case, I thank you first of all for the detailed description smile this helps me a bit...

My other question was more about the code optimization whether this is so good or if I could have written it better.
If you understand if a code is not processed fast enough by the main script, it can also lead to errors or incorrect results.

Last edited by Zenti; 03/04/22 03:41 PM. Reason: new reason
Re: Help with an roguelike alias [Re: Zenti] #270127 06/04/22 09:56 AM
Joined: Apr 2022
Posts: 7
Z
Zenti Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Apr 2022
Posts: 7
So you have no ideas to update the the code ? O.o

Re: Help with an roguelike alias [Re: Zenti] #270129 06/04/22 12:41 PM
Joined: Apr 2022
Posts: 7
Z
Zenti Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Apr 2022
Posts: 7
My focus in the whole thing is usually always the formula determination for generating the values.

An example A player has a Level 1 armor and then receives a Level 2 armor.
This can give the player to 50% chance max +3 HP Permanent, to 25% exists that this +15HP and to 12.6% max +40HP Permanent.
Now a formula must be generated from it that applies to each level up. so that an LVL 3 armor just gives 3 times etc...

What should be the formula for each level? can you help me? Please!

Re: Help with an roguelike alias [Re: Zenti] #270133 07/04/22 09:21 AM
Joined: Jan 2004
Posts: 1,745
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,745
I'm afraid I'm more confused than when I started out. I had no idea what 'rogue like' meant until googling it. I don't even understand the terms how something can be the maximum while also being a partial chance at the same time.

A lot of these questions depend on the strengths of the adversary. Are you competing against other players who are also acquiring better weapons and defense, or is this so you can advance to stronger computer opponents? etc

Re: Help with an roguelike alias [Re: maroon] #270139 09/04/22 04:43 AM
Joined: Apr 2022
Posts: 7
Z
Zenti Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Apr 2022
Posts: 7
With my game script so the main script there will be a PvP or PvE mode that heist player against player or player against environment so the monsters. Of course, these also have a defense value etc... By defeating the monsters you get money to upgrade your character with skill attributes etc. Now I want to include a kind of item generation for armor parts.

So i need help for the formel of the armor generation part.