I curently do a puzzle game and almost all in map was event.
All method that I see about shooting system is not relevant in my case.
So I want to tell you exacly what I want to do and I hope you can tell me how to do it with line script.
Basicly when I got ball, I shoot one at time. They have a parallele event that look if I press a key.
When pressed, the projectile event place to the player location and appear(working).
The projectile shoot in the direction of where the player look at. (working).
And now what I have difficulty with...
I put movement in a loop, and I want that if the ball(set to pass trought) pass over an event that make this verification:
- If the event is set to "under hero" then the ball just continue.
- If the event is on same level of the hero then, He will trigger the D switch of this event automaticly.
Basicly I need to be able to detect if the event is on the same location then another event and activate a local switch on this event.
Everyplace where this event will shoot will have D switch on all event, so supose to be fine.
I tryed to put paralele event with a switch on event, but on the puzzle they have usualy 50 events, so 50 parallele process will be a nightmare...
I why I try it this way...
Thansk for your help, with that done, a great part of my projet will work.
I thought I already answered that quesion in the other thread, I must not have been clear enough I guess.
You are right that 50 parallel processes is bad, and you should not do it that way.
What you need is a single parallel process maybe a common event maybe just an event on the map.
So inside that parallel process you will check if any of the map event coordinates match those of the ball.
Here is one way of doing that:
var i, a, b, c, d, e, ballId
ballId = 0 //Fill this with your ball event Id
e = $gameMap._events //e will contain the array of all map events
i = 1; a = e[ballId]._x; b = e[ballId]._y //we set a to event [ballId] x coordinate and b to its y coordinate
while (i<e.length) { //we run a loop for the size of the array of the map events.
c = e._x ; d = e._y; //we set c to event x coordinate and d to its y coordinate
if (a === c && b === d) {alert(i)} //We check if both sets of coordinates matches
//replace the alert with whatever you want to do when an event coordinate matches those of the ball
i++;
}
//Checking an event priority type can be done with:
e._priorityType === x
//With x being 0 for below, 1 for same, 2 for above
Hope I helped.
array = $gameMap.eventsXy(x, y);
This pulls an array of all the events in at a specific location. Might be more efficient than the above code. (Or it might do exactly the same thing)
I will try that, but if I put in a parallele event a script:
array = $gameMap.eventsXy(x, y);
what I do next? If I know they will never have more then one event at same place?(exceptionnaly 3) what I need to do next?
If I want to triger a local switch for this event? I know they have some plugging for activate switch, the probleme is the how to?
I jsut did't see it in my mind, Im in the common event called by a parralele event(the projectile) and I just can't see it in my mind.
The part
//replace the alert with whatever you want to do when an event coordinate matches those of the ball
cause me trouble because what I need to put now? Can I really put that must code in the smallbox for putting script?
Yes you can and it's not really that much code 🙂
I don't know what you want to do. For a self switch you can put $gameSelfSwitches.setValue([mapId,eventId,"name"],value)
You replace mapId by the id of the map, eventId by i, "name" by "A", "B",... and value by true or false.
- Accidental double post. Please ignore -
DId I can use that with array = $gameMap.eventsXy(x, y); ?
Shorter code will be more easy for start. But i is not there so...
What I got:
var i, a, b, c, d, e, p, ballId
p = this.character(0);
ballId = p.eventid
e = $gameMap.eventsXy(p.x, p.y);
i = 1; a = e[ballId]._x; b = e[ballId]._y
while (i<$e.length) {
c = e._x ; d = e._y;
if (a === c && b === d) {alert(i)}
if (e._priorityType != 1){
$gameSelfSwitches.setValue([32,i,"A"],true)
}
did't work yet.
Well that's because you didn't replace the alert with that code, just put it after ^^.
It should be like this:
var i, a, b, c, d, e, ballId
ballId = 0
e = $gameMap._events
i = 1; a = e[ballId]._x; b = e[ballId]._y
while (i<e.length) {
c = e._x ; d = e._y;
if (a === c && b === d) {
if (e._priorityType !== 1) { $gameSelfSwitches.setValue([mapId,i,name],true)} // this will set the self switch
//to true if the priority is not "same as charachter".
}
i++;
}
Also, you need to do a check with "!==" not "!=".
Ah right, damn small script box.
var i, a, b, c, d, e, ballId, mapId
ballId = 0; mapId = $gameMap.mapId(); e = $gameMap._events;
i = 1; a = e[ballId]._x; b = e[ballId]._y;
while (i<e.length) {
c = e._x ; d = e._y;
if (a === c && b === d) {
if (e._priorityType !== 1) { $gameSelfSwitches.setValue([mapId,i,name],true)}
}
i++
}
This works, fits inside a single script call, and will automatically update mapId to the current map Id.
You just need to set ballId to your ball eventId and name to your self switch.
Try deleting the comments. ie. everything after //
You can make multiple script calls, but it forgets any temporary variable names, so you probably don't want to do that.
Otherwise, the only way I know around long scripts is to include it in a plugin.
I don't know off hand how to get mapID, but try right clicking and showing the Map properties. See if it appears at the top fo the screen. Also, try opening the console (f8) and typing console.log($gameMap) and see if something id related pops up.
Hum, two things.
First: I made a typo in my code, you should delete the "$" before the e in the while check.
Second: once I made that modification, my code runs perfectly and produces desired results in my project.
My guess would be that one of the plugins you use modifies the properties of the event object.
If that is the case, I sadly can't do anything about it.
Edit: ah, disregard second then, just delete the dollar sign before the e and it should be working just fine. That was a typo on my part, sorry.
Edit of the edit:
var i, a, b, c, d, e, ballId, mapId
ballId = 77; mapId = $gameMap.mapId(); e = $gameMap._events;
i = 1; a = this.character(0).x; b = this.character(0).y;
while (i < e.length) { //delete the $ sign that was there
c = e._x ; d = e._y; //you can't do this, it will just not work. See explanations below
if (a === c && b === d) {
if (e._priorityType !== 1) { $gameSelfSwitches.setValue([mapId,i,A],true)}
}
i++
}
This can't and won't work.
What my code does is take all the map events and put it into an array so e is [0,event1,event2,...]
Then it checks the properties (in this case the x and y coordinate) of each of the events in the array, and compares them to the ball coordinates.
To do this for each event on the map I set a loop up, that will loop througout the array to read the properties of each object.
To that effect you need to go through each element of the array, hence the e[ i ] command. That tells the code to look for event i and sets c to event i x coordinate and d to event i y coordinate.
We then increase i by one and keep doing the same thing until all elements of the array have been checked.
If you delete it the code can't and won't work.
Looking at your first error message makes me think of a plugin related issue, sadly.
With some help I solve some trouble, apparently, because I don't have deleted some event creating a hole in the serie that caused this problem.
curent code don't give any error but did't activate selfswitch of the other event when touch it:
var i, a, b, c, d, e, mapId
mapId = $gameMap.mapId(); e = $gameMap._events;
i = 1; a = this.character(0).x; b = this.character(0).y;
while (i < e.length) {
if (e) {
c = e._x ; d = e._y;
if (a === c && b === d) {
if (e._priorityType !== 1) { $gameSelfSwitches.setValue([mapId,i,"A"],true)}
}
}
i++
}
I don't recognize this.character(0).x are you sure that gives you the right x's and y's?
Nice!!!
I have a quick question about that-- if there are holes in event IDs, then how do you know you're getting them all?
Like, let's say the array is [0, event1, event2, event6, event8]
Shouldn't it loop through checking event 1 and 2, and then not 3, and then not 4, and then stop since that's the length of the array???