ID:814852
 
I am trying to make a final fantasy-like battle system and I have succeeded doing that for one player but not for 2. I can't see to make it so that the enemy targets and attacks only one client and I can't think of a way to make the second player take a turn. How should I deal with this? Help would be appreciated.
Show the code u already have ?
mob/var/f=1
mob/var/e=0

mob/player/proc/battleinput()
while(1)
if(src.loc==locate(/turf/rocks))
for(var/mob/b in oview())
if(usr.f==1)
var/tmp/a=input("What would you like to do?") in list ("Attack", "Run")
if(a=="Attack")
b.hp-=10
usr.f=0
if(a=="Run")
usr.f=0
if(prob(20))
src.loc=prevloc
playerturn=0

sleep(10)


mob/enemy/p/proc/enemyinput()
while(1)
var/tmp/mob/enemy/v=locate(/mob/enemy/p)
if(v.loc==locate(15,6,1))
for(var/mob/player/b in oview())
if(usr.f==0)
var/tmp/r=rand(0,1)
if(r==0)
b.hp-=10
world << "Attack"
usr.f=2
if(r==1)
src.hp-=30
world << "Super Attack"
playerturn=2
sleep(10)

mob/enemy/c/proc/enemyinput()
while(1)
var/tmp/mob/enemy/v=locate(/mob/enemy/c)
if(v.loc==locate(15,3,1))
for(var/mob/player/b in oview())
if(usr.f==2)
var/tmp/r=rand(0,1)
if(r==0)
b.hp-=10
world << "Attack2"
usr.f=2
if(r==1)
src.hp-=30
world << "Super Attack2"
usr.f=2
sleep(10)
Anyone?
You waited 6 hours .. you aren't very patient are you..

We aren't paid to do this ya'know.

Also why aren't you using the ! operator for your if statements? I understand why for "usr.f" but you could use them for "r"

If I was you I would give the enemy a "target" var/target=pick("player1","player2")

Or is that what - var/tmp/r=rand(0,1) is doing?
In response to A.T.H.K
A.T.H.K wrote:
You waited 6 hours .. you aren't very patient are you..

We aren't paid to do this ya'know.

You're right.

Also why aren't you using the ! operator for your if statements? I understand why for "usr.f" but you could use them for "r"

If I was you I would give the enemy a "target" var/target=pick("player1","player2")

Or is that what - var/tmp/r=rand(0,1) is doing?

Man I forgot what I was thinking while I made this code. Let me remember. I think I should've made f a global variable. f is for who's turn it is. r is for a random attack. But how do I make that global variable named "target" for different clients? I need a different variable or a different value for each client in order for the enemies to target them.
No you give the enemy the variable and the enemy will then pick the target and attack.
how will that variable be linked to a player? so a variable called target will be equivalent to a variable called player 1 or player 2. How will that variable link to different clients each?
You'd make the value of 'Target' equal to an actual mob, such that attacks are directed against it. Each monster would store a target independent of the other monsters.
Okay. How do I make the value of target equal to different mobs? If I do var/target=client, target will always equal to all clients.
You have to make it equal to an actual mob, not just 'client.' Client is an object that determines which mob the player is connected to.
The easiest way to do this that I can think of right now is probably to get the names of the mobs the monster is in battle with, and assign a target based on this.
How do I do that? Examples would be appreciated.
Something like;

FOR the players - I suggest defining all mobs that players can 'occupy' under mob/Player to make things like this easier - in the battle area, add them to a list of targets. ( Be sure to initialise the list! )

Then, PICK one of the possible targets to be your target.
Wow. After over 6 hours of programming this one feature I did it. I made it so you can have parties and they enter battle together. So far I made it for 1-2 people but with a few more hours of work I can make it up to 3 people.
In response to TheDarkChakra
TheDarkChakra wrote:
So far I made it for 1-2 people but with a few more hours of work I can make it up to 3 people.

Use a list, then you won't have to recode it to add support for more people (except maybe to make space for them on the screen)

Also, you should be using a Battle datum of some sort that tracks the participants and the turn order.
Yeah I have a problem with that. I don't get lists. I read about them and don't understand them.

What is a battle datum?
The main problem people have with lists is that they forget to initialise them. You have to do var/list/ListName = new, to actually make the list 'exist,' before you can add stuff to it.

Then it's just a matter of doing ListName.Add(Value)

A datum is an object that doesn't actually exist anywhere in the world, and is just used to store data. It's sort of like a template.
People ask about them, or talk about them, fairly often, so browsing the forums to look for information would probably be informative.