Charas-Project

Game Creation => Requests => RPG Maker Programming => Topic started by: Shadowless1 on February 15, 2006, 10:45:35 PM

Title: coding help needed
Post by: Shadowless1 on February 15, 2006, 10:45:35 PM
ok i want the hero to be a cursor and an event to go to the hero when i press enter, for those of you who have played diablo 2 something simmular to that but not using the mouse,so far i have made the x and y co-ordinates for the hero and the event

please help me with a parallel process event which will make it so when i press enter the event will travel to the co-ordinates where enter was pressed and not follow the hero

thanks in advance
Title:
Post by: Meiscool-2 on February 15, 2006, 10:48:44 PM
I'm to lazy to explain this right now. If dragonblaze doesn't do it for me within a few hours, I should do it, but right now, Meislazy.
Title:
Post by: WarxePB on February 15, 2006, 11:50:39 PM
That's easily enough done.

Before you do any coding, you'll have to create an event called "Dummy Hero" on every map. Make sure that it's the first event on every map you make; if it's the fourth, that's fine, but make sure it's the same for every map.

First, create a new Common Event, called Swap Hero. Set it to parallel process, and activated by a switch (so you can turn it off in certain places). Start the code with a Key Input Process command, using a variable called INPUT, that activates the code. I usually use Shift, which is equal to 7, but you can use whatever you please. Create a Conditional Branch that checks if the INPUT variable is equal to whatever, and inside that branch, create another branch that checks if a switch called "CURSOR ON" is OFF (I'll get to that later). In the True part of the branch (right underneath the branch), use a Memorize Position command to get the coordinates of the hero, with three variables called HERO-X, HERO-Y and HERO-ID. Now, set an event to the hero's position (using a Change Event Location command, and with the hero's coordinates). Now, change the hero's graphic to the cursor, and set him to Phasing Mode ON (using a Move Event command). Finally, turn the CURSOR ON switch ON,
Now, in the Else Handler of the CURSOR ON branch, get the coordinates of the dummy hero with two more variables, DUMMY-X and DUMMY-Y. Change the hero back to their normal sprite, set them to Phasing Mode OFF, and use Recall to Memorized Position to return the hero to his original coordinates, with the DUMMY-X, DUMMY-Y and HERO-ID variables. Turn the CURSOR ON switch OFF, and you're done! I think.
Title:
Post by: DragonBlaze on February 16, 2006, 04:01:53 AM
Quote
Originally posted by Meiscool
I'm to lazy to explain this right now. If dragonblaze doesn't do it for me within a few hours, I should do it, but right now, Meislazy.


Warxe beat me to it :p Anyway, because I'm bored, I'm gonna write my own version of this. Though I suggest trying out Warxe's first. I just pulled this off the top of my head, and it may not work. But anyway, for this you'll need a picture file of the cursor, and one parallel process common event.

-Make a common event, lets just name it cursor. Set it to parallel process, and assign a switch to it so it won't always have to be running. (it'll only run if you turn the switch on).

- Make 2 variables, [herox], and [heroy]. Set [herox] to the hero's screen relative x position, and do ths same for the y.
- Make 2 move variables [cursorx] and [cursory], set them equal to [herox] and [heroy]
- Show a picture, select the cursor, set the image to number 10 or something, and display it at [cursorx] and [cursory].
- Move the hero, select pause, and select repeat pattern. This will stop the hero from moving while we move the cursor.
- Make a key input process, select the variable [cursor move], and select the up, down, left, right, and decision keys. Do not have the 'wait until key is entered' option or whatever selected.
- Make 5 conditional branches, one for if [cursor move] is 1, one for 2, one for 3, etc.
- In the branch for 1 (cursor moving down), add 16 to [cursory]. Then move picture (cursor) to [cursorx], [cursory], over the course of .5 seconds or whatever. Also select the box for 'halt other processes during transition'.
- You can also pan the screen 1 tile down, but if you do, it needs to be before the move picture event.
-- since each tile is 16, adding 16 and then moving it the the new location will move it one tile down.
- Do the same for all the other directions 2-4. UP will be subtracting 16 from [cursory], for right, add 16 to [cursorx], and for left, subtract 16 from [cursorx].
After these for branches, make another label, 2.
- In the branch for if [cursor move] is 5, make 2 conditional branches. One for if [Cursorx] Is greater than [herox]. And one for if [cursory] is greater than [heroy]. Give then an else case.
- In the first branch, Make another conditional branch for if [cursory] is greater than [heroy]. In this branch, move the hero down right. In the else case in this current branch, make another branch for if [cursory] is less than [heroy]. In this branch move the hero up right. In the else case for this current event, move the hero right.
- In the else case for if the [cursorx] is greater than [herox]. Make another conditional branch. On for if [cursory] is greater than [heroy]. In here, move the hero down left. In the else case, make a branch for if [cursory] is less than [heroy], if so, move the hero up left. In this else case, move the hero left.
- I hope you see the pattern here and are able to repeat it for the next branch that tests the y's first instead of the x's.
- At the end of these two branches, make a 3rd branch for if [cursorx] is equal to [herox] and another inside if [cursory] is equal to [heroy]. In both these branches, make else cases, and in the else cases, jump to label 2.
- That should be everything :)

EDIT I just realised something with the screen, since you panned it earlier, when you move the hero, the screen will move to an extra amount. I'm not exactly familuar with the pan screen feature because I don't use it much in this way. Anyway, I imaging if you lock the pan screen before you move the hero, and unlock the pan screen after you move the hero, everything will work out allright. Or you can return the screen to its origin and have it follow the hero when he/she starts to move.

Oh if you would have any questions on this, feel free to ask. I can also help you out if you want to limit the range of how far the cursor can go and whatever else.
Title:
Post by: Prpl_Mage on February 16, 2006, 06:09:47 AM
Hmm, this was intresting... But what if I want the Hero sprite to always be in the middle, so that the camera doesnīt scroll after the cursor? That would leave the cursor in a limited area of "walking"...

And what if I want a "pick and drag" system for my items?
Using the cursor and pick up my items displayed at the bottom right corner, and then pull them as example. i have a key, I walk up to the door and pull it from my inventory to the door, but when I click on the key item(the key) the cursor should now change apearance to the key. And when it is on the gate the icon shold get a yellow aura showing that you can use it here.

Any ideas?

Title:
Post by: Meiscool-2 on February 16, 2006, 02:08:21 PM
I'll let one of them explain the item dragging, because it'll take more then a few seconds to explain that.

To keep the camera on the hero event instead of the cursor, make an event that doesn't allow the camera to move (aka, lock camera posistion) . When you press the key to make your hero event move, turn that lock off, (or leave it on depending on how you coded things), and have the camera move the same way the hero event does at the same speed. Example: If pressing 1 makes your hero event move left at normal speed, then also have the camera move left at normal speed too.

I hope that's what you ment at any rate.
Title:
Post by: Prpl_Mage on February 16, 2006, 04:52:10 PM
Yeah that look right, but are you sure that the cursor can not move outside the screen?

And to add some more things:

Running- Is there a way to make the hero event run when you press another button?

Wait!-How about stopping the hero event from moving to the point chosed?

Diagonal- Is there a way to make the hero event possible to move up-left/right and down-left/right?

Item use- Maybe the item pulling was a bit hard, so here is another example, you enter the CMS and enter the Inventory, you scroll along your items and chose one, when you exit the CMS it is no longer a cursor, now it is the item instead, maybe a press on a negative(Esc, 0) make it disapear and you change back to the cursor? Well um maybe it became to simple now...

Examine/Talk/Trigger/X-Well I kind of wanna know if it is able to change the grafic when moving across special places Examples:
Examine:There is a door, when moving the cursor upon it the cursor changes to a magnefying glass and if you press enter the hero event moves up and the event starts.(maybe a quick auto movement that moves the hero event to a special place infront of it.)
Talk:When moving the cursor above a NPC the cursor change grafic into a speaker box, by pressing the button the NPC stop moving and the hero event move up to the person, not the exact place. And then the conversation starts.
Trigger: You notice a treasure chest, but when you move your cursor above it the cursor change grafic into a cog-wheel and when clicking the hero event move up to the chest and open it.
X: (Easy one) When moving the cursor above a tree or a stone it change from the normal cursor to a darker one(transparent maybe) that show the player that "you canīt walk here"

Hehe try to work these out...
Title:
Post by: Shadowless1 on February 16, 2006, 09:25:59 PM
nope none of these work, meiscool what was your way of doing this?
Title:
Post by: Meiscool-2 on February 16, 2006, 10:36:58 PM
I don't think Warxe's would work, but DragonBlaze's should work 100% fine.

Basically:

Have 6 varibles. 2 will be Cursor (hero) X, 2 will be the Y, and 1 will be the Hero (event) X, one will be Hero (event) Y

Have a common event that looks like this:

Cursor X1=Hero (as in your hero, not the event) X
Cursor Y1= Hero (same as above) Y
Wait 0.0
Hero X= Event Hero X
Hero Y = Event Hero Y
Wait 0.0

Then, have another event for the cursor. Have it go:

Cursor X2=CursorX1
Cursor Y2=CursorY1
Loop:
Con Branch: If Cursor X2 Is greater then Hero X, Hero moves right
Else Handle: Hero moves left
End Branch
Con Branch: If Cursor Y2 Is greater then Hero Y, Hero moves down
Else Handle: Hero Moves up
End Branch
Wait 0.0
Con Branch Cursor X2=HeroX
Con Branch Cursor Y2=HeroY
Break Loop
end branch
end branch

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

That's a very basic and customizible cursor click right there.
Title:
Post by: Shadowless1 on February 16, 2006, 11:11:19 PM
hmm it kind of works but the event just move up and down or left and right
Title:
Post by: Meiscool-2 on February 17, 2006, 12:01:36 AM
well, you gotta put the key input and stuff in yourself. I don't know how your game is so far, so depending on how you've already programmed it is how it will work.
Title:
Post by: Shadowless1 on February 17, 2006, 12:09:56 PM
i havent done anything to it so far, im trying to get that working and then i can work on it
Title:
Post by: Shadowless1 on February 17, 2006, 12:26:04 PM
ive got it working with key input but all it does wherever i press enter it moves right twice and then it keeps moving left and right and doesnt stop

heres what i have so far:

Common Event 0001:Set co-ordinates             Parallel process
<>Variable Oper: [0001:Cursor X1] set,hero X coord.
<>Variable Oper: [0003:Cursor Y1] set,hero y coord.

Event:Player Marine                                          Parallel process
<>Variable Oper:[0005:Marine X] set,this event x coord.
<>Variable Oper:[0006:Marine Y] set,this event y coord


Common Event 0002:Cursor                             Parallel process
<>Variable Oper:[0002:Cursor X2] set, Var [0001]'s Value
<>Variable Oper:[0004:Cursor Y2] set, Var [0003]'s Value
<>Key input proc: [0007:Cursor input]
<>Branch if Var [0007:Cursor input] is 5
<>Loop
<>Branch if Var [0002:Cursor X2] is V[0005] Greater
<>Move event: player marine, move right
<>
:Else Handler
<>Move event: player marine, move left
<>
End
<>Wait 0.0 sec
<>Branch if Var [0004:Cursor Y2] is V [0006] Greater
<>Move event: player marine, move down
<>
:Else Handler
<>Move event: player marine, move up
<>
End
<>Wait 0.0 Sec
<>Branch if Var [0004:Cursor Y2] is V[0006] Equal
<>Branch if Var [0002:Cursor X2] is V[0005] Equal
<>Break loop
<>Variable Oper: [0007:Cursor input] Set, 0
<>
End
<>
End
<>
End Loop
<>
End
Title:
Post by: DragonBlaze on February 17, 2006, 07:40:51 PM
I noticed a few things. First off,

<>Branch if Var [0002:Cursor X2] is V[0005] Greater
<>Move event: player marine, move right
<>
:Else Handler
<>Move event: player marine, move left
<>
End

So if the cursor is to the right of the hero, the hero moves right, thats good. But then if the cursor is left of the hero OR the cursor has the same x as the hero, the hero will move left. Change it to look like this:

<>Branch if Var [0002:Cursor X2] is V[0005] Greater
<>Move event: player marine, move right
<>
:Else Handler
<>Branch if Var [0002:Cursor X2] is V[0005] Greater
<>Move event: player marine, move left
<>
End
<>
End

Make the same change for

<>Branch if Var [0004:Cursor Y2] is V [0006] Greater
<>Move event: player marine, move down
<>
:Else Handler
<>Move event: player marine, move up
<>

Let me know if that fixes your problem :)
Title:
Post by: Meiscool-2 on February 17, 2006, 08:43:15 PM
I expected him to do the greater then/ less then thing himself, but I guess I was wrong.

Edit- this is probally just a honest mistake on DB's part, but right here:

<>Branch if Var [0002:Cursor X2] is V[0005] Greater
<>Move event: player marine, move right
<>
:Else Handler
<>Branch if Var [0002:Cursor X2] is V[0005] Greater
<>Move event: player marine, move left

He actually ment:

<>Branch if Var [0002:Cursor X2] is V[0005] Greater
<>Move event: player marine, move right
<>
:Else Handler
<>Branch if Var [0002:Cursor X2] is V[0005] Less
<>Move event: player marine, move left
Title:
Post by: DragonBlaze on February 17, 2006, 09:09:05 PM
XD yeah, my bad. I'm too lazy to write down the coding, so I just copied it and pasted it instead, I guess I forgot to change the greater than to less than. But yeah, change it to what meiscool has writen down.
Title:
Post by: Shadowless1 on February 17, 2006, 09:48:45 PM
cheers,thanks a lot ;)
 it works but for some reason it kind of lags, it goes to the location where enter was previously was pressed

heres the code now:

Common Event 0002:Cursor Parallel process
<>Variable Oper:[0002:Cursor X2] set, Var [0001]'s Value
<>Variable Oper:[0004:Cursor Y2] set, Var [0003]'s Value
<>Key input proc: [0007:Cursor input]
<>Branch if Var [0007:Cursor input] is 5
<>Loop
<>Branch if Var [0002:Cursor X2] is V[0005] Greater
<>Move event: player marine, move right
<>
:Else Handler
<>Branch if Var [0002:Cursor X2] is V[0005] Less
<>Move event: player marine, move left
<>
End
<>Wait 0.0 sec
<>Branch if Var [0004:Cursor Y2] is V [0006] Greater
<>Move event: player marine, move down
<>
:Else Handler
<>Branch if VAr [0004:Cursor Y2] is V [0006] Less
<>Move event: player marine, move up
<>
End
<>Wait 0.0 Sec
<>Branch if Var [0004:Cursor Y2] is V[0006] Equal
<>Branch if Var [0002:Cursor X2] is V[0005] Equal
<>Break loop
<>Variable Oper: [0007:Cursor input] Set, 0
<>
End
<>
End
<>
End Loop
<>
End
Title:
Post by: Meiscool-2 on February 17, 2006, 10:27:59 PM
at the begining of the loop, put another key input, and make it to where you don't have to wait untill the key is pressed to continue the script. Make it where (in the loop) if Cursor input ever equals 5, then it breaks then it jumps up to label one (which you should put at the top of the script. Also, cut your current key input and put it at the very top of the script, right before the label. The label should be right under it.

It'll look like this:
Common Event 0002:Cursor Parallel process
<>Key input proc: [0007:Cursor input] (wait)
Label 1
<>Variable Oper:[0008: Enter Wait] set, 0
<>Variable Oper:[0002:Cursor X2] set, Var [0001]'s Value
<>Variable Oper:[0004:Cursor Y2] set, Var [0003]'s Value
<>Branch if Var [0007:Cursor input] is 5
<>Loop
<>Varible [0008] +1
<>Branch if Var [0008: Enter Wait] is 5 or more
<>Key input proc: [0007:Cursor input] (no wait)
<>Branch if Var [0007: Cursor input] is 5
<>Jump to Label 1
End
End
<>Branch if Var [0002:Cursor X2] is V[0005] Greater
<>Move event: player marine, move right
<>
:Else Handler
<>Branch if Var [0002:Cursor X2] is V[0005] Less
<>Move event: player marine, move left
<>
End
<>Wait 0.0 sec
<>Branch if Var [0004:Cursor Y2] is V [0006] Greater
<>Move event: player marine, move down
<>
:Else Handler
<>Branch if VAr [0004:Cursor Y2] is V [0006] Less
<>Move event: player marine, move up
<>
End
<>Wait 0.1 Sec
<>Branch if Var [0004:Cursor Y2] is V[0006] Equal
<>Branch if Var [0002:Cursor X2] is V[0005] Equal
<>Break loop
<>Variable Oper: [0007:Cursor input] Set, 0
<>
End
<>
End
<>
End Loop
<>
End
Title:
Post by: Shadowless1 on February 17, 2006, 10:47:12 PM
cheers, thanls man that rocks ;)