javascript request

I hope it's the good place for that.


I looking for a script able to tell if they have a an objet between the player and the desired objet.


Think about laser and you need to put objet to protect you for pass.


The perfect solution for me was a script that check notetag of event.


Notetag: Shooter


Notetag: Block


player.


If the player pass in same row or columb then the event with a notetag Shooter, then execute some code.


Ideally if he can freeze player and shot at him and call gameover that will be perfect.


Optionnaly, add option avoidable or notavoidable. If not avoidable, frreze an die, if avoidable that shoot a fireball that can be dodge. 


Thansk for your great help.
Ok should be relatively easy to do that


First let's hande the notetag part:


1. You have to keep in mind the difference between the game event and the event data. The game event is the "character" you see in the game, is the living part let's say. The data of the event instead in the name of the event, the note, the code istructions. The data itself should not run code if i recall correctly, so we have to pute our code in the game event class. Since the game event class doenst' contain the event note we need to access that, to do that we use this line


$dataMap.events[this._eventId].note


this will return the note of the event with the same id contained in the event data array.


Now to see if the note contains the words we are loking for we use the string method "includes()"


So we now translate this into an if:


if ($dataMap.events[this._eventId].note.includes("laser") {
// run code
}


but is not very clean but we'll clean it later


2. We have to find now how to make the laser and the block work.


First the laser has to know his direction. For this i suggest you to create a graphic for the laser origin (like a lense) as it was a character.


This will give 2 advatages: first you can animate the origin (like a fog efect) using the still animation of the event avoiding to code for that, second you can easily define and change the direction of the laser from the editor.


Now you have to know how much the laser will continue from its starting point. It collides with walls, blocks and the end of the map so we ahve to run a code like this


var x = laser.x;
var y = laser.y;
var laser_length = 0;

if (laser.dir = up) y += 1;
else if (laser.dir = down) y -= 1;
else if (laser.dir = left) x += 1;
else x -= 1;

while (true) {
if (!laser.canPass(x,y,laser.dir)) return laser_length;

if (laser.dir = up) y -= 1;
else if (laser.dir = down) y += 1;
else if (laser.dir = left) x -= 1;
else x += 1;

laser_length++;
}


This code will return the length of the laser in tiles from its starting position. This cose is a pseudo cause though (obviusly), which means that it doesnt' directly work but shows just the logic.


Also i dint' put a specific code for the block obstacle for now because if you cant' pass through it but can only push it it means il collidable therefore it doesnt' need special code since the laser just generally checks if a tile is passable or not.


Now i have other things to do but later or tomorrow if you are still intrested i will end this
ok I start trying that, I will update this post if I got trouble.
So i made it into a plugin, everything you need yhould be accessible via plugin parameters


It took more time than i expected so i hope it's worth it 🙂


View attachment LaserPlugin.js


Let me know if something isn't clear
Cool I try it right now!


OK first error on laod laser.png


It's normal I guest I need to find a laser picture can you send your?


Maybe the image file need to be a parameter to =:0)


Im not sure what mean offset parameter. I continue my testing =:0)


Maybe add a parameter for call a common event when touched.


And maybe a parameter avoidable or not, if avoidable, the player can dodge it by moving because it's shoot less fast instead of freeze.
Oooooh so the lasers are shot?


I tough they where beam lasers like mission impossible or things like dat, this is another thing...


For now i give you the laser graphic so you can see what i did, create a "sprites" folder inside the game folder and put the image in it


laser.png


In any case offets change the start and the end position (in pixels) of the bean.


for example, if the laser is set to "centered" (which means it starts at the middle of the tile") and you set the start offset to 10, the laser will start 10 pixels lower (if the laser is facing down). This is a graphical thing only, it doenst' affect gameply in any way.


If you instead you want the lasers to shoot like in star wars is way more complicated and CPU heavy. If you want to obtyin the same result with what i have don u can simply make the beam pulse. I dont' know if this is what you were already sayng though XD.


If you want to know if the laser hits the player look at the plugin guid (go to plugin manager, open the laser plugin, click on Guide)


If you want now to make the laser more cool you just have make the graphic of the surce of the laser.


If you want it to com out of like a pipe in the middle of a tile is simple you just make the things it comes from (like a pole or a cilinder for example) and make it into either a map graphic.


If you want the graphic to be a character graphic though, or you want the laser to come out the wall like from a lense, you ahve to create a graphich file of 4x2 characters, every character is 3x4 tiles, every tile is 48x48 pixels: result whould be 576x384


in this grid you have to populate one of the 8 character with the laser graphic (look at the existing character graphics undestrand).


This way you can also animate the origin of the laser. For the end instead if you want to ad like a ricular reflection where the beam hit i can do that.


EDIT


The script had some minor errors, here the fixed version

View attachment LaserPlugin.js
Yes it's laser like shoot, but I have some other vent that was shooter, so I said myself that maybe for your it's easy to make an option laser or shot.


By the way I get unable to fix the laser.png issue. I created a sprites folder and still don't work.


I check your code but see nothing refering to sprites/laser.png. Any idea? I got error laser.png missing when loading projet.
1 - make sure that the name of the folder is sprites (not Sprite of sprite or Sprite)


2 - the folder must be directly in the game foderr (ex. Project1\sprites), not in the img folder. If you want to put sprites folder in the img folder you have to change this line


return this.loadBitmap('sprites/', filename, hue, false);


in this line


return this.loadBitmap('img/sprites/', filename, hue, false);


3 - check if the name of the file is the same as the laser graphic name plugin property. If the file is laser.png the property should be laser (not laser.png or 'laser' or "laser")
he folder must be directly in the game foder, not in the img folder .

Exactly my mistake... I finish my main test and that's the result:


What I can do:


- I get able to set diretion of the laser with the orientation of the tower and also get able to make it invisible.


- I also get able to trigger an event when touched by the laser.


What I can't do:


- Make it visible when The player get touch.


- Make tower shoot in any direction. (optionnaly if you want more generic pluggin add also horizontal and vertical only)


- Set the distance that the laser touch. seem to be 3 spaces. But in my game it's only blocked by wall(regionID) or by block event.


What will make it better:


- Add posibility to add light effect on the laser like star war laser.


- Automaticly have the option to trigger a common even if touch. (That will help to use less parallele event)


- Make possible to do a battle animation on the map from the tower to the player.


- Have the laser kind(instakill) and the dragon king(shoot fireball on the player but he can dodge)


What bugs:


- Look the video for see a bug whenre I can be between the box and statue without be touch.


- If I made the statue moving that start to be really wierd, the beam don't react like we can expect.


View attachment Screen 07-04-2016 02-26-29.avi


If you want to know more what I curently creating, you can try lolo adventure:




For the laser put code: BKBL


Optionnally you can try each level for go there, you will see most of ennemie of the game(6 level)


You will get a good Idea of what I curently try to do =:0)
This is getting tricky lol


Ok let's go one by one... let's give these points a letter


"What i can't do"

Make it visible when The player get touch.

A. I can modify the code for you to be able to modify that (just did)

- Make tower shoot in any direction. (optionnaly if you want more generic pluggin add also horizontal and vertical only)

B. I can arrange that but is sort of lenghty, if you want to do it by youself you can put one of the beam on the right place, the others in another tile and at the start of the game teleport them on the same tile. you can just add a page one with the teleport and the se an inside switch ON. If you REALLY need this to be done via script i can do it

- Set the distance that the laser touch. seem to be 3 spaces. But in my game it's only blocked by wall(regionID) or by block event.

C. That is a bug, it sohuld behave as you planned it to be.. i will look into it


"What will make it better"

Add posibility to add light effect on the laser like star war laser.

D. I don't know what you mean. If you mean you want like short beams to be continusly shot like pewpewpew it can be "easily" done but it requires a lot of time, at that point i would have to ask you pay me lol

Automaticly have the option to trigger a common even if touch. (That will help to use less parallele event)

E. It's already like that, in the pluguin guide button it shows the line you need to use to know if the player has been it by the player.


You can put the script line in a conditional branch (in the last page you can find the script option) and the line is:


$gamePlayer.isCollidedWithLasers()

Make possible to do a battle animation on the map from the tower to the player

F. You need to be more specific, for now i can tell you that you can show either an animation either on the laser tower of the player, but if you want both you would have to strech the animation relatively to the distance between the 2 and i dont' really know how to do that.

Have the laser kind(instakill) and the dragon king(shoot fireball on the player but he can dodge)

G. You can do a laser that goes on and off, it's graphically different but if it goes on and off at the same rate at the fireballs it will be basically the same gameplay wise. I'll add a few line to make this more easy to execute


"Bugs"

Look the video for see a bug whenre I can be between the box and statue without be touch.

H. I'm looking into it

If I made the statue moving that start to be really wierd, the beam don't react like we can expect.

I-a. I didn't know you had to be able to do that. First of all probaly one of the strange things it does is changing direction, that's because laser direction for now relies on the laser event direction and by moving it the laser will shoot in the direction it is currently moving.


To fix that you can check the "fixed directio" box in the bottom-left corner in the vent editor.


Since you need to shoot multiple lasers sometimes i'll see if i can fix this for you.


I-b. The other strage things it does is probably that the start and the end of the laser jump to the next posision when the laser tower starts to  move right? It should, that's because i dint' knew you had to alsmo move them. I can fix that but as the last thin probably


"Arrows system"


J. Now the blocks only can pass how they want on arrows


H. I made a code to put inside a block for the pushing mechanic (it doesnt' support ice for now), make a script inside the block and put this


var event = this.event();
console.log(event);
var player = $gamePlayer;
var oldX = event._x;
var oldY = event._y;
event.moveStraight(player.direction());
if (event.isMoving())
player.moveForward();
if (!player.isMoving()) {
event._x = oldX;
event._y = oldY;
}








NOTES


From now on i will not add new post, if i make progress in something i will ad and UPDATE at the end of teh said point


THIS WILL BE THE PLUGIN FILE I'LL BE UPDATING, DOWNLOD THIS FOR THE MOST UPDATED VERSION


also i merged the arrow plugin with the laser plugin, for now i keep LaserPlugin as name but we will probably give it another name

View attachment LaserPlugin.js
Ok I just try it. Thanks for your help by the way, you save me probably more then 60 days of forum asking.


Point A:


I see that you the laser opacity. In fact both are good. Laser alway visible like in a museam secirity system and invisible.


If user get touch, then becaume visible when invisible(I think that you can have a script command for that)


Point B:


I understand the teleportation idea, but I will use so ofthen this tower in every level and except when used like a security system, that will alway shoot in all direction. Try lolo adventure with the link I give you you will see =:0) So if you can do it in pluggin, that will save me a lot of headcache.


Point C: Ok, wait for your update


Point D: Not exacly, like that. I talk like the laserblade in starwar, they glow. If the beam can glow that il lbe great. For the pewpewpew, its for another kind of tower that shoot this way, and these one can be avoidable. And yes I can pay you for your great help. But to be honest, I don't have that much money so we need to see if I can affort the price.


Point E: Curently I have a paralele process that alway check for $gamePlayer.isCollidedWithLasers() , it's nto the right way?


Point F: For the animation jsut forget about it for now. It's just an idea and not neccesery a good one.


G: try the 6 first level in lolo adventure, you will see the dragon soon. That will make you understand all my project eassily:


H: ok


I: ok, basic tower don't move, but they have some tower that move buth they alway shoot in all direction.


J: Great.


K: the code work, of course I will need to find a way for play sound, activate switch and ice. Maybe it's better to put it in the plugin too.


Let me know how much you want for your help, all hard work deserve to be paid, I jsut hope I can a affort the price...
A. you will be able to do that with editor or i can do it by script no rpoblem


B. I'm already updating the code to make you able to create more lasers by yourself in one single event (not more than 4 lasers)


D. you can make the beam glow by: using the add filter (doesnt' work with opacities lower than 255), or using a blurred and britght graphic and/or animating the opacity to make it slightly pulse (you can use a sine equation like)


var time = Graphics.frameCount;
var frequency = 0.1;
var delta_oscillation = Math.sin(time * frequency) / (Math.PI * 2);
var min_opacity = 120;
var max_opacity = 255;
var laser_opacity = (max_opacity - min_opacity) * delta_oscillation + min_opacity;
this.setLaserOpacity(laser_opacity);


Put this into a laser with parallel process and should work if i dint' screwed it up. Play around with the values maybe.


Anyone if this is what you need i can make it more easy to handle by modifing the pluging.


E. Basically when you call  $gamePlayer.isCollidedWithLasers() it gives you true if the player has been hit in that code cicle.


It just tells you wether or not he's been it when you ask him, but it updates itself so you dont' have to call it every cicle if you don't need to.


Use it as an IF condition when you need it


G. Ok i will look it up


I. I will make you able to move lasers and choose how many beams it fires (up to 4), from that point you will combine the things


The lasers when moving will graphically do it gradually, but logically they will jump from on tile to another (so if the laser is movind towards the player he will result hit befor the tower has stopped moving).


This is because collisiong checks works with absolute tile potisions. If you want instead that the laser moves gradually you ahve to tell me. It should be a short work but i will have to transition froma a tile based collsition system to an hitbox based one.


K. Ok we'll look into boxes later, i dont' think they will rewuire much time though


Let me know how much you want for your help, all hard work deserve to be paid, I jsut hope I can a affort the price...


It's up to you personally, I think you can give me what you feel is right based on how much you can afford and the work that i will do


In any case i will end the work i started otherwise the plugin you got would just be useless they are incomplete
A: I understand I can make it in he editor when player get touch, but I did't see any option set set visibility in the last version of your script. But of course if it's can be done directly in the script that will avoid me to do a lot of code for detect the tower that trigger the event, calculate path between him and the player and create a shooting.


B. Great =:0)


D. wow a lot more advenced coding then my currend level in javascript =:0) I will give a try but it's sure that by pluggin is more easy to handle. I seen in your code that you create animation, that even more then my idea. I first tinking about fixed light like in some rpg maker game that you see light when you see flames.


E Ideal solution that was to put in parameter the posibility to automaticly a common even when touch. If possible in common enven this. refering to the tower.


I. It's fine if he get touch jsut when it's 100% in front.


K. ok.


For money I really don't have much, so I don't want to insult you with an offort that I know it's not equivalent of the work you done.


But I can manage to get a 100$ and when I will get more money give you more for continuing adding stuff, seem a good idea to you?
A. Ok i will make it by code


D. same, you'll have to explain me exactely what you need or if it's in the game you sent me i'll see by myself


E. Can be done but is not the best solution. I can calla common event by id but if you move it will not work. The best thing is to have a comon event which is the main update cicle and inside that you put a code that checks if the player is hit and if so it calls teh common event you want


I. i already made the code so the laser are more precise with combined movements 😉


That amount of money fine for me, you can give it to me as soon as you feel you have something you can work with alone, then you'll tell me if you want me to continue (or if i have time to do so).


I would really need to have your contact in something like skype because i have often have to ask you things, reply me in private message if it's ok and which platform you rpefer, personally is skype for me cause it handles also file transfers and we can share the desktop to show things 🙂
D: It's not in the game I send you, in the game they have basic shooting, but I fI do exacly same, I will have trouble with copyright, so a laser is fine I will try to explain more. Maybe add tag toyer or tag shooter. Shooter shoot and can be dodge(exacly like dragon in the game).


Toyer shoot laser that can't be doge. Laser go at the light speed so it's appear imediatly. By the way, it's not necesary that the laser stop at the player, if it's more easy for you that the laser shoot trought the player(with a lot of blood, joking) to the wall, it's fine too.


A & I, nice.


Facebook contact is fine for you? I answer fast by facebook. Or maybe team viewer, but if you want I can create a skype account.


If I get able to do like in the game I will be really happy. Unfortunatly, I think to do exaclty like the game is imposible because of half tile movement.... In game you can push an objet in middle of 2 tiles and that can block two laser... I don't think it's possible without thousoud of hours of coding, but you can tell me if Im wrong.


I just don't have to create level that require this specific hald tile movement and I will be fine.


And of course, if you still have time after, they have a lot of other thing I try to do. Like you can see moving monster, I did't do yet any of these mosnter yet.  You will understand if you have played the game. In private we can talk about how transfer money., paypal I guest

Original thread: https://forums.rpgmakerweb.com/threads/javascript-request.64619/