Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Can someone give me some pointers on my RPG battle system,please?

Author
Message
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 28th May 2005 08:40
I have included the source code, I am having major problems finishing off the turn aspect based on a timer. If anyone could possibly help me I would be most grateful.
Killonyas Slayer
19
Years of Service
User Offline
Joined: 13th Apr 2005
Location: Mozerok,Eartreg
Posted: 28th May 2005 12:33
well, unless your pretty experienced with this kind of stuff, i wouldn't use timers...
1. they go up, not down.
2. I am trying to (shown in "strange RPG problem") and it is driving me insane.
3.it can be a bit annoying to the player, while they have to wait for they don't know how long.

instead, I would sudegest making a turn variable

timer#=1
if timer#=1 then `your attack
if timer#=2 then `enemies attack

-Timesplitter-
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 28th May 2005 20:41 Edited at: 28th May 2005 20:43
Can you explain what you meant by going up not down Timesplitter? Is it the line: timer()+5000?
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 28th May 2005 22:08
Is there anyone who couyld suggest the next move I could make to improve the battle system(turn based), or anyway I could overhaul it to dramatically improve it.I don't wish to start on the media, I am trying to improve the engine at the moment.
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 29th May 2005 01:58 Edited at: 29th May 2005 01:59
I havent fully looked at your code so this may not be of any help but if you have a turn based battle system, its very simple to swap from yourself to the enemy:



If you cant use #CONSTANT then simply change WhoAttakcs to 1 for the Enemy and 0 for the Player
If you want a timer based system, once you have mastered the Timer() command, rather than using the WhoAttacks varaible, change it to:




As I said above I havent run your code but why not set up the screen to show your attributes as well as the enemys, then just below, have the Input commands and attack messages.

Try putting this all in a function, that way in your RPG all you have to do is something like
` runBattle()
When ever your player is going into a battle.

Im going to be gone for most of the weekend but if your still having trouble, ill produce some code next week if I get time.

James

Hello!
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 4th Jun 2005 07:31 Edited at: 4th Jun 2005 09:22
Thanks for your help James. Could you(or anyone else with this knowledge) show me where it is I am going wrong in my timer system, I have attempted to place it into one function as you had outlined, however I got the error "could not close nest at line 161"(Note: I am not aware how to close a function and if someone would be so kind as to tell me, I would be very grateful).
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 4th Jun 2005 09:25
Can anyone suggest a way of creating a timer based system, without using timer(), or perhaps just using it in a different way. Code or just concept would be great
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 5th Jun 2005 01:27
Does someone know how to fix this segment of code, I cannot seem to get the enemy to respond I cannot see why this could is not working. Does anyone know why?
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 5th Jun 2005 04:14 Edited at: 5th Jun 2005 04:15
With functions you HAVE to have them at the bottom of the code, nothing else other than functions can go below them. Unfortuanly this is the oppisite to a lot of more powerfull languages such as Delphi (I expect C++ is the same) where you have to have your functions at the top, before you ever call them.
First you need to open the function with the function command, set the name of the function followed by (). Inside the () is where you can set all the variables which you can send to the function:


You then need to write all the functions code, once finished you end the functions with ENDFUNCTION or ENDFUNCTION x, by adding a variable on the end of ENDFUNCTION allows you to send a value from the function to the place where you call it:

will return the value of d, although you dont always need a function to return a value.
Now, when you want to call this function, all you do is put the line
myfunction(a,b,c) or myfunction(1,2,3)
Note how although the function states a,b,c when you call it, all you have to do is give a variable, this when then get called a,b and c:


or



if you want to exit a function early, just use the command EXITFUNCTION

Hope this helps
About your other problem, ill get back to you later, im busy now =(

James

Hello!
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 5th Jun 2005 07:39
Ok. I took your advice(thanks for the detailed explanation) and it's now in a function.

My main problem now is that I cannot get the enemy to strike back.

Look at source code to see what I mean.

If you want the full code so far I can put it up if that would help.
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 7th Jun 2005 08:23
Can no one help me?
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 7th Jun 2005 08:25
I have another question
If I wanted the battle to say be rnd battles like ff how would I exit the battle and return to exactly where I was before I went into the battle. Anyone know?
ReneGade RG
19
Years of Service
User Offline
Joined: 13th May 2005
Location:
Posted: 7th Jun 2005 22:44
Use the gosub command to enter the battle and reurn to go back, save the data you need, like your upgraded experience and delete the enemy images and so on. Remember that the program has to remember where you were last. OK?

It's amazing you're reading this, surprise... you still are.
ReneGade RG
19
Years of Service
User Offline
Joined: 13th May 2005
Location:
Posted: 7th Jun 2005 22:51
Oh yeah, when your character moves, it's best to store your character coordinates. If this is in 2d, store the coordinate variables xpos and ypos for it and create four images showing the different directions your character can face.
In 3d, instead of using the popular but complicated newzvalue commands and so on, you can use basic move object player,20 and then...
xpos#=object position x(player)
ypos#=object position y(player)
zpos#=object position z(player)

It's amazing you're reading this, surprise... you still are.
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 8th Jun 2005 03:37
Thanks Rene,
Could I have it so they acted independately (the battle system and the world) almost as two seperate programs and I could cause the world to wait and be hidden while I displayed thte battle scene.
Killonyas Slayer
19
Years of Service
User Offline
Joined: 13th Apr 2005
Location: Mozerok,Eartreg
Posted: 8th Jun 2005 06:28
Not sure about your last question, but what I meant by the timer goes up, is that the timer is a set variable that is always changing, not just when you tell it to.
It's always moving up. If you want the enemy to attack when it goes down, well, it's never going to attack, unless you specifically tell the timer to go down.

-"I'm over twice as strong as I was when we last met"-
-"Good, Twice the fall, double the glory"-
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 11th Jun 2005 05:48
John, sorry that I have taken soo soo long to get back to you, I got me a cold last weekend and this is the first I have been on!

For your first problem, if the code is the same as before:

Then whats happening is the part after the Loop command will NEVER get called, reason being is the complier never looks there. The only way something below a Do Loop will be called is if you tell the complier to look, either through a Goto command or a function command.

With your second question. Yes. If you were to have one function, or a set of functions for the battle, the main one called for example runBattle() then during your world, in the main loop you would just need to call the runBattle() function. Once the battle is over you would return exactly where you were in the program, so if this is stil a text RPG, then you just run your code as so:

While writting this, im starting to think you meant in the actual game play not the code, in that case just do as I suggested above but you need to add several things in order to remember your position.
Below is code but it is in DBP, I cant remember what language your using, so if its no good ill give it another shot soon.


Also please note that not all of the above codes will work, where I have put something such as `World code here is where you would put the code for the world, there are some other sections where I have said what you do but not given the code such as in the last example player = the character object but hopefully thats self explanitary.

If I have confused you on any thing above, just yell ill see how I can help mate!

James

Hello!
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 13th Jun 2005 03:34
Thanks timesplitter, Rene and James that really helped my code, but as always I'm having some trouble. My problem at the moment is that enemy attack print only stays up for a split secound, I was wondering if there was any way it could be coded so it would stay up for say 3-5 sceounds before disappering. Also I think in the code it waits for the player to attack/heal before it allows the enemy to execute its attack. Any help would be great here's the source code thus far. I placed it in a label because I didn't know how to call a function correctly.
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 14th Jun 2005 06:34 Edited at: 14th Jun 2005 06:37
Looking at your code, there are several things wrong, but its a really good start!
This first snippet is your same code, just been indented, by indenting it makes it easier to read. Theres one basic rule to indenting, whenever you write a command that requires another command to close it requires all the code inbetween to be indented.
For example, IF, ENDIF and DO, LOOP


The reason for the quick flash of writting is because it will display it for one loop, but then when the computer reads the cls command, it will wipe it off the screen. As the computer loops through the code anywhere from 60frames per second to 900 frames per second you will be able to read it.
The quick solution would be to remove the CLS command, the problem with this is that by removing the CLS command, when you reprint the characters health, it prints below all the other printed text, causing a whole screen worth of confusing text.
So then, to correct your problem. By using the PRINT command, theres two ways to fix it, the best way would be by using the TIMER() command but the easiest way is by using the WAIT command.
The Wait command will pause the whole program for x amount of time. 1 second = 1000, so
WAIT 1000
will pause the program for 1 second.

Looking at your code, you have using the Timer() command incorrectly.
From the moment the computer begins, the timer will start to increment, like the WAIT command, the timer will increment 1000 times a second.
In your code, there is the command:
Playerwaittime=timer()+10
This means EVERY loop, Playerwaittime will be 10 more than the timer(), so it will NEVER be below which is why after one attack, you never get the option to attack again. How your code stands, what you need to do is change the following

to


It also seems like you have a problem with causing damge to the enemy, I will play around with your code a bit to fix the other bugs but hopefully this is a start!


James

EDIT:
One thing I have noticed is that you have commands such as:
SPEED#=speedquality#
speedquality#=level#/2
When it should be
speedquality#=level#/2
SPEED#=speedquality#
The reason for this is that the process will read your program line by line, so in the first loop:
Speed# = 0
This is as you have not told the computer what speedquality is, its only after the second loop that it will know, you have done this several time, it could iron out your program if you fix these, for now ill cary on poking around with your code.

Hello!
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 15th Jun 2005 05:16
James, you have done an amazing amount of work to help me and words cannot express how grateful I am. Would you mind if I asked a couple of questions as there are a couple of things I didn't understand in your answer. The first was, you told me that
my code would not work because of the line


and told me to change it to



Now the bit I am not sure of is this, You are still using the line

In both versions, still using input command and still using

Your version


My version


Is the difference that Dbpro reads things in a certain order and that is why your code works better.

The second thing (which was my fault for not being clear) is that the player does keep getting asked to make a decision about how to attack(with the original code). Mt problem was that the enemy would not attack even if his time was up until I made my move. So it was as though he waited for me.

About the damage problem I think I have fixed that The problem was I haden't set a value for Emove#=2 I had only set it for if Emove#=1

although only the problem now is it ditters on the screen between the print for emove#=1 and emove=2
I have changed that now and here is the new source code (see source)
I tried to change what you told me to and here are the results.

It runs much smoother now and seeing as I moved the code for the enemy attack up beside the character attcak it now prints on screen for the required amount of time.

I have a question though I was experimenting and I tried to tidy up my Nija attack code and tried to model it off the new character attack code here Is what I tired



and this is the unorganised code that works

Do you have any thoughts why?

Anyway thanks for all your great help once again.
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 16th Jun 2005 06:29 Edited at: 16th Jun 2005 06:38
I like helping and for some reason I like writting 1000 lines of code just for someone to point out a faster method at 300lines! On top of that the first thing I programmed was a RPG Text batttle system

I will get back to you on the rest, but for now Ill explain your first question.
Your original code was:


What this will do is check if playerwaittime is less than the timer(), if so then it will attack.
Then the program sets playerwaittime as timer()+10. This will happen regardless to the line above it. Meaning even if you dont attack, playerwaittime will still be set to above the timer.
This will result in you attacking for the first time but after that, timer+10 will NEVER be less than timer for obvious reasons.

By changing it to

Will check if playerwaittime is less than timer(). If and ONLY IF the value is lower than timer() will it allow you to attack and more importantly set playerwaittime to timer()+1000.
Then in the next loop, playerwaittime wont be changed. This is important as we dont want it to change, otherwise it wouldnt be a timer.
For example in your original code (using timer() as a real number that I have made up:
Loop 1 -
playerwaittime = 0 as it has not been set
playerwaittime < 1400 (timer) so we will attack
playerwaittime = 1410
Loop 2 -
playerwaittime = 1410
playerwaittime is not < 1401 so we will not attack
playerwaittime = 1411

This will continue, hence playerwaittime is never less than timer.
However, with the new code:
Loop 1 -
playerwaittime = 0 as it has not been set
playerwaittime < 1400 (timer) so we will attack
- as we have attacked playerwaittime = 1410
Loop 2-
playerwaittime = 1410
playerwaittime is not < 1401 so we will not attack or change playerwaittime
...
...
Loop 10 (lets say timer has now reached 1411)
playerwaittime = 1410
playerwaittime < 1411 so we will attack
- as we have attacked playerwaittime = 1421

And so on, hence we get to attack
Sorry if that hasnt explained it very well. Oh and finally, the reason why its +1000 and not +10 is because one second = 1000, this will give you a one second timer for the user, +10 wouldnt be at all noticable, but this preference is purly up to you.

Ill get back to you about the rest soon!

James

Hello!
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 20th Jun 2005 06:00
Have you had any thoughts on my problem(s) James?
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 21st Jun 2005 03:12
John, just to let you know I havent forgot (if anyone else can help tho it would be great!!) I had to head down to police station due to a VERY dangerous driver at the weekend and have been very busy, but I will have chance to look at it again a bit 2mo and wednesday, sorry im taking soo long...

In the mean time, try experimenting with differnt things. It may just be me, but I have a tendicy to constantly print amounts to the screen to see what certain values are (to make sure they are working). I havent experimented around yet but that last problem has something to do with Ninjawaittime#=<timer()+41 i think.

Anyway, ill post again soon.

Hello!
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 21st Jun 2005 03:21
No problem, I'm sorry if I was hassling you. I just was wondering I have a lot to do at the minute(working on terrian at the moment and a 3rd person sliding system). So there's is no hurry with the help, and there is no need to apologise as you are helping me not vice versa. Take as long as you need becausae I know your help will be worth waiting for. Anyway, thanks again for all your help so far.
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 24th Jun 2005 06:57
Wooh, that took several hours to write, any how I hope this helps.
I may not have answered everything, if so just contact me again on here or smileitsjimmy@aol.com (im not always avaliable tho...). Also if you have specific questions you cant ask or find on the forums, feel free to email me.



The reason it does not seem like you ever attack is due to the input being CASE sensitive, meaning the following
are not the same - a : A
The way to overcome this is by checking if Upper$(MOVE$)="A", what this will do is change every character in the
MOVE$ string to uppercase, so in essence a = A, b = B, C = C, 1 = 1.
That way, it is irrleavant if the user has the caps lock on.
Also as explaing previously, I modified the timer() section as this caused the player to NEVER attack after the
first loop.

For the enemy however, I have no problem with him attacking, but the amount will always been random due to the line
Enemymiattack#= Rnd(30)+120*Emattack/4
and the likes place all over the loop...

I have changed the EMOVE command slighty to introduce a timer() which acts the same as the player timer, this creates
a timer.
A random timer of up to 1.5seconds has also being introduced by adding +RND(1500) on the end of the timer value. I felt
this was better than allowing the enemy to attack every loop.
HOWEVER, you should change this to the speed variable's. I have not yet experimented with them


Note - HAHA, I didnt see your second source code and used your old one, dont worry tho, Ill do a revised post tonight or tommorow

Hello!
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 26th Jun 2005 23:47
Thanks James . The code runs very smoothly, and the comments reallly helped my understanding of it. I'm thinking about porting the engine to a graphical version soon for my small rpg. I have done a rough battle screen. Would the best way to port thid be to drop the input part for the player use sprites and say something like

if sprite 1(the cursor) collides with sprite 2(attack button) and mouseclick
then
MOVE$="A"


if sprite 1(the cursor) collides with sprite 3(attack button) and mouseclick
then
MOVE$="H"

pseudo code but I think something like that would work what are any of your thoughts.
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 27th Jun 2005 08:58 Edited at: 27th Jun 2005 08:59
Edit: Spelling error
I wrote some code for the "battle world" in 3D. It works and uses darkmatter 1 models at the moment. A problem I seem to be having is that when it use this code with the battle code it seems to ignore the battle code even though it is in the loop. The main probelm this causes is that I have set a sprite to the mouse cursor's position and was going to hide the sprite(so it could detect collision with other sprites) but now I cannot see the sprite at all even when not hiding it.

Anyone have any ideas?

James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 27th Jun 2005 09:02
It really depends on how complex you want it to look. Sprites are good for a 2D looking game, if you want it 3D then you would have to figure out some kind of collision.

Belive it or not, it may be harder to make it look graphically good if you keep it 2D, I say this because you would have to produce animated images for characters attacking where as in 3D you can just use free models of use a cube to make sure the actions work. Either way the code is going to be fairly similar for the actual battle so the choice is up to you.

You are correct though, if you are to use sprites then you would have to check for sprite collision, or if you want a old Final Fantasy style, then just check what attack you want.

Pseudo code:


You would remove the Print commands you currently have, add the sprites at the start of the loop and slighty modify what happens when you run the If move$ = "A"

To begin with though, once you have a TEXT battle system working. Open a new project and get the interface working (presuming you are going for the final fantasy style). Create options you can select using either the mouse or arrow keys, then when the user selects a command, this would be the same as when you said Input "...",Move$
Then add sprites, to begin with just use different colour squares - just to make sure it is working, dont worry about any animation.

Then add the battle system mathamatics (the stats and attacking/magic math)

Finally, if the interface works and the math/core of the battle system is working, add animation to the sprites, such as moving it towards the enemy when attack, turning it a different colour when dying (which can later be changed to an animation of you dying)

Anyway im rambaling so ill say one last thing then post.
Think through what you need doing, write it down if you have to before coding. You dont want to mix up different sections of code that can be made separate, if necesary, split each part into subroutines (gosubs) such as gosub Characters Turn, which in side it has subroutines for attack/magic

James

Hello!
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 27th Jun 2005 09:07 Edited at: 27th Jun 2005 09:45
My idea was to have a 2d sprite with a hollow center so like a border save it as a 26 bit png from photoshop so as to keep the transparency, so you have a menu and the 3D sceen can still be seen would that work with the battle engine?
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 29th Jun 2005 21:38
Just a quick question James. When you said

Quote: " level#=6
expn#=400
exp#=0

As the above code is not inside any conditional commands such as IF, WHILE or FOR it gets called EVERY loop, resulting
in level# ALWAYS equalling 6, expn# = 400 and exp# = 0, even after being changed later on, expn# WILL NEVER = exp# -
or in math
400 DOES NOT EQUAL 0"


If I put it before the loop will that solve it.
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 29th Jun 2005 22:38
Thanks James for the 2D-3D advice, I think I'll aim for 3D.

I made some improvements to the code.(Note: Full source code also at the bottom)

Firstly I swaped the lines speedquality# and SPEED# so SPEED# can be read in the first Loop, also I changed the timer so instead of a random timer it is now using the speed stat


I also changed the Move$="H" slightly
Now instead of being 1000 every time it uses the variable Mdamage#
added to HP thus allowing different Levels and stats to have different levels of effiency in healing. To get this to work I also had to add in the variable Mattack#




I am planing on storing things like level and exp in a text file and calling it. Is that the best way of storing that type of data.
And if I were to save it to a text file How would I update it every battle.

Any help would be great thanks.
Killonyas Slayer
19
Years of Service
User Offline
Joined: 13th Apr 2005
Location: Mozerok,Eartreg
Posted: 30th Jun 2005 02:29
Do you know about functions and for/next

They would be a great help if you want to continue the game.

here's an example of how you can use for/next for level up's.



an example of a function can be a simple texting function



You can even use it for a battle, remember that functions go over and over.

If this doesn't make sense,just say so

-"I'm over twice as strong as I was when we last met"-
-"Good, Twice the fall, double the glory"-
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 30th Jun 2005 06:00 Edited at: 30th Jun 2005 06:02
Thanks Timsplitter. Can you explain what the differnt parts do as I am not familiar with them. One question how will the program remember what level you are at when you return to the main game after winning a battle. And is there an easy way to save the characters progress such as level,exp and position in world/storyline ect. Thanks again for your help

Edit: Just a quick question to anyone reading this; Is my battle system improving and heading in the right direction or is it in need of a major overhaul and if so where would you recommend starting?
Killonyas Slayer
19
Years of Service
User Offline
Joined: 13th Apr 2005
Location: Mozerok,Eartreg
Posted: 30th Jun 2005 06:35
Here is an example of how I would do something like this.




It may not be the best way for you, remember, this is only how I would do it. Stick to whatever seems the easiest to you.

anyway, I hope this helps.

-"I'm over twice as strong as I was when we last met"-
-"Good, Twice the fall, double the glory"-
Jonathan Valintine
19
Years of Service
User Offline
Joined: 30th Apr 2005
Location:
Posted: 1st Jul 2005 21:20
Thanks timesplitter. I do not have at lot of experiance with functions, there are a couple to things some of you might be able to help me out with. If I for example win the battle and return to the main game(world map) how will the game remember what level I was at during the previous battle, will the function retain this inforamtion or reset itself and if I was to quit the game how would you save where you are in a particular function, for example i'm level 3 lets say and I want to save and quit, next time I load the game will I be able to return ro level 3 or will I revert back to level one, if the later is true is ther any way around this. I am going through some of the tutorials on functions at the minute so hopefully that will help. Anyway Thanks again to everyone who has helped so far.
Killonyas Slayer
19
Years of Service
User Offline
Joined: 13th Apr 2005
Location: Mozerok,Eartreg
Posted: 2nd Jul 2005 11:22
1.that's what that for x=... thing is for.
2. Not really sure about saving.

-"I'm over twice as strong as I was when we last met"-
-"Good, Twice the fall, double the glory"-

Login to post a reply

Server time is: 2024-09-23 23:21:19
Your offset time is: 2024-09-23 23:21:19