I think I did this right:
randomdmg
var
randdmg
proc
rdmg()
randdmg=rand(1,10)
world << "[randdmg] damage!"
mob/var/randomdmg/rdmgtwo
mob/proc/randatk()
rdmgtwo.rdmg()
I am trying to make a verb based on that but nothing works. I just don't know what to do with this! How do I use this to make my coding simpler?
I have this for example:
proc
battleinput()
while(1) //while 1 is true which is always
if(src.loc==locate(12,6,1) | src.loc==locate(12,3,1) | src.loc==locate(11,9,1) && src.pturn) //if the location of myself and my 2 allies is true as well as if its my turn. pturn means player's turn.
for(var/mob/enemy/Prowler/o in locate(15,6,1)) //defining enemy 1: Prowler that already exists in location 15,6,1 of my map
for(var/mob/enemy/Bandit/i in locate(15,3,1))
world << "[src]'s turn" //who's turn
var/tmp/action=input("What would you like to do?") in list ("Attack", "Run") // input turn actions. variable is "action"
if(action=="Attack") //if that action is attack
var/tmp/attackwho=input("Attack who?") in list ("Enemy 1", "Enemy 2") // second input this time choosing to attack who. variable is "attackwho"
if(attackwho=="Enemy 1")//if chosen enemy 1
var/tmp/randomdmg = rand(1,10) // random damamge variable
o.hp-= randomdmg //"o" Prowler variable is damaged randomly
world << "[src] attacks [o] for [randomdmg] dmg" //outputs into the world what has happened. the player attacked prowler for that random damage
src.pturn=0 // player's turn becomes 0 so its not my turn anyore
cancel3rd4=1
cancel2nd4=1
if(attackwho=="Enemy 2") //same as above just enemy 2
var/tmp/randomdmg = rand(1,30)
i.hp-=randomdmg
world << "[src] attacks [i] for [randomdmg] dmg"
src.pturn=0
cancel3rd4=1
cancel2nd4=1
if(action=="Run") // if chose the action Run
if(prob(20)) // 20% probability to run away
src.loc=prevloc // returns to previous location as I defined it in the Move() proc
src.pturn=1 //returns player's turn to 0 if run away
else src.pturn=0 // if I don't run away then its no longer my turn
// global turn 2 making it Prowler's turn
sleep(10)
How can a Datum make this simpler and shorter?
So looking at this piece, the thing that was missed was to initialize a new instance of the rdmgtwo.
Then anytime you need this, you can call src.rdmgtwo.rdmg() where src is the mob that owns this.
You can also define it in the global scope (with just putting var/randomdmg/rdmgtwo = new()) as it does a function that may not be specific to just that one mob.
Now for the battle, to make the simpler my datum would look like this:
I only coded one of the items in it as it would be pretty long for a system like this, but it is much more flexible that what you have here.
Your system is built to ALWAYs have only 1 player and always be 2 enemies. Although you can shorten yours greatly, there is not really much going on.