Markolainen
Member
Hi,
I have been using Game Maker for some time and I've under these years become quite good at GML. So I decided to share my knowledge in a scripts thread so all of you that need help can come here and request help and look through my scripts. I'll keep all the scripts on the first post and add new as I have time and you request them. I'll only post GML coding. If there is something that you're unsure of please look for it on the GM wiki site or the official documentation before asking. All the scripts are made by me and if there is something I can't help you with I'll try to point you to a script/tutorial that does what you requested.
As for credit you can give it if you want, it is really not necessary.
If you'd like some script don't hesitate either posting in this thread or PM me if you'd like to be anonymous.
If you do a too big request I'll propably point you to another script/tutorial. I'm here to help if you got stuck on something and not for making your game for you.
You can read these scripts and do changes on them to better suit your needs and use them as a base or idea giver for your custom engines without having to credit me.
Difference between two values - Last update 100206
Movement in eight direction with pixel perfect collission - Last update 100206
Gravity - Last update 100207
Collision with floor (to be used with gravity NOT with Manual Gravity. On MG you only need to put the objects to solid!) - Last update 010207
Variable jumping - Last update 100207
Platform movement with slopes - Last update 100206
Pixel Perfect Gravity (Manual Gravity) - Last update 100403
I have been using Game Maker for some time and I've under these years become quite good at GML. So I decided to share my knowledge in a scripts thread so all of you that need help can come here and request help and look through my scripts. I'll keep all the scripts on the first post and add new as I have time and you request them. I'll only post GML coding. If there is something that you're unsure of please look for it on the GM wiki site or the official documentation before asking. All the scripts are made by me and if there is something I can't help you with I'll try to point you to a script/tutorial that does what you requested.
As for credit you can give it if you want, it is really not necessary.
If you'd like some script don't hesitate either posting in this thread or PM me if you'd like to be anonymous.
If you do a too big request I'll propably point you to another script/tutorial. I'm here to help if you got stuck on something and not for making your game for you.
You can read these scripts and do changes on them to better suit your needs and use them as a base or idea giver for your custom engines without having to credit me.
Difference between two values - Last update 100206
Code:
<div class="gml" id="{CB}" style="font-family: monospace;"><ol><span style="font-style: italic; color: green;">//Difference between two values
<span style="font-style: italic; color: green;">//made by Markolainen
<span style="font-style: italic; color: green;">//Put in any event when this calculation is needed
<span style="font-style: italic; color: green;">//argument0=value 1
<span style="font-style: italic; color: green;">//argument1=value 2
<span style="font-style: italic; color: green;">//Example difference=script_difference(10,-10);
<span style="font-style: italic; color: green;">//If both positive or negative
<span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](argument0)=[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](argument1){
<span style="font-weight: bold; color: #000000;">return([url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url]([url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url](argument0)-[url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url](argument1)));}
<span style="font-style: italic; color: green;">//If one is negative and the other positive
<span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](argument0)!=[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](argument1){
<span style="font-weight: bold; color: #000000;">return([url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url]([url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url](argument0)+[url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url](argument1)));}
Code:
<div class="gml" id="{CB}" style="font-family: monospace;"><ol><span style="font-style: italic; color: green;">//8 directional movement
<span style="font-style: italic; color: green;">//made by Markolainen
<span style="font-style: italic; color: green;">//Put in step event for walking normally
<span style="font-style: italic; color: green;">//argument0=speed
<span style="font-style: italic; color: green;">//Example script_move(3);
{
<span style="font-style: italic; color: green;">//Declare temporary variables
<span style="font-weight: bold; color: #000000;">var xsp, ysp;
<span style="font-style: italic; color: green;">//Check if buttons are pressed
xsp=([url=http://www.zonamakers.com/gmlreference/keyboard_check.html]<span style="color: navy;">keyboard_check[/url](<span style="color: #663300;">vk_right)-[url=http://www.zonamakers.com/gmlreference/keyboard_check.html]<span style="color: navy;">keyboard_check[/url](<span style="color: #663300;">vk_left))*argument0;
ysp=([url=http://www.zonamakers.com/gmlreference/keyboard_check.html]<span style="color: navy;">keyboard_check[/url](<span style="color: #663300;">vk_down)-[url=http://www.zonamakers.com/gmlreference/keyboard_check.html]<span style="color: navy;">keyboard_check[/url](<span style="color: #663300;">vk_up))*argument0;
<span style="font-style: italic; color: green;">//Execute movement
<span style="font-weight: bold; color: #000000;">repeat([url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url](xsp)){
<span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x+[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](xsp),<span style="font-weight: bold; color: #000000;">y) then <span style="font-weight: bold; color: #000000;">x+=[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](xsp);}
<span style="font-weight: bold; color: #000000;">repeat([url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url](ysp)){
<span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x,<span style="font-weight: bold; color: #000000;">y+[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](ysp)) then <span style="font-weight: bold; color: #000000;">y+=[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](ysp);}
}
Code:
<div class="gml" id="{CB}" style="font-family: monospace;"><ol><span style="font-style: italic; color: green;">//Gravity
<span style="font-style: italic; color: green;">//made by Markolainen
<span style="font-style: italic; color: green;">//Put in step event for normal gravity
<span style="font-style: italic; color: green;">//argument0=gravity;
<span style="font-style: italic; color: green;">//argument1=maximum fall speed
<span style="font-style: italic; color: green;">//Example: script_gravity(0.2,4);
<span style="font-weight: bold; color: #000000;">gravity=[url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x,y<span style="color: #cc66cc;">+1)*argument0;
<span style="font-weight: bold; color: #000000;">vspeed=[url=http://www.zonamakers.com/gmlreference/min.html]<span style="color: navy;">min[/url](<span style="font-weight: bold; color: #000000;">vspeed,argument1);
Code:
<div class="gml" id="{CB}" style="font-family: monospace;"><ol><span style="font-style: italic; color: green;">//Collision with floor
<span style="font-style: italic; color: green;">//To be used with gravity
<span style="font-style: italic; color: green;">//Remember to use parents if you have multiple floors such as slopes
<span style="font-style: italic; color: green;">//made by Markolainen
<span style="font-style: italic; color: green;">//Put in collision event with your floor/wall object
<span style="font-style: italic; color: green;">//Example script_collison_with_floor();
<span style="font-weight: bold; color: #000000;">if vspeed><span style="color: #cc66cc;">0{
[url=http://www.zonamakers.com/gmlreference/move_contact_solid.html]<span style="color: navy;">move_contact_solid[/url](<span style="color: #cc66cc;">270,<span style="color: #cc66cc;">10);
<span style="font-weight: bold; color: #000000;">y=[url=http://www.zonamakers.com/gmlreference/round.html]<span style="color: navy;">round[/url](<span style="font-weight: bold; color: #000000;">y);}
<span style="font-weight: bold; color: #000000;">if vspeed<<span style="color: #cc66cc;">0{
[url=http://www.zonamakers.com/gmlreference/move_contact_solid.html]<span style="color: navy;">move_contact_solid[/url](<span style="color: #cc66cc;">90,<span style="color: #cc66cc;">10);}
<span style="font-weight: bold; color: #000000;">vspeed=<span style="color: #cc66cc;">0;
<span style="font-weight: bold; color: #000000;">gravity=<span style="color: #cc66cc;">0;
Code:
<div class="gml" id="{CB}" style="font-family: monospace;"><ol><span style="font-style: italic; color: green;">//Variable jumping
<span style="font-style: italic; color: green;">//by Markolainen
<span style="font-style: italic; color: green;">//Put in step event for jumping normally
<span style="font-style: italic; color: green;">//argument0=jump speed (has to be negative)
<span style="font-style: italic; color: green;">//argument1=If variable jumping should be used. Options: true & false.
<span style="font-style: italic; color: green;">//Example script_jump(-4,true);
<span style="font-weight: bold; color: #000000;">if ![url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x,y<span style="color: #cc66cc;">+1) and [url=http://www.zonamakers.com/gmlreference/keyboard_check_pressed.html]<span style="color: navy;">keyboard_check_pressed[/url](<span style="color: #663300;">vk_up){
<span style="font-weight: bold; color: #000000;">vspeed=argument0;}
<span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x,y<span style="color: #cc66cc;">+1) and [url=http://www.zonamakers.com/gmlreference/keyboard_check_released.html]<span style="color: navy;">keyboard_check_released[/url](<span style="color: #663300;">vk_up) and vspeed<<span style="color: #cc66cc;">0 and argument1=<span style="color: #cc66cc;">1{
<span style="font-weight: bold; color: #000000;">vspeed/=<span style="color: #cc66cc;">2;}
Code:
<div class="gml" id="{CB}" style="font-family: monospace;"><ol><span style="font-style: italic; color: green;">//Platform movement with slopes
<span style="font-style: italic; color: green;">//made by Markolainen
<span style="font-style: italic; color: green;">//Put in step event for walking normally
<span style="font-style: italic; color: green;">//argument0=speed
<span style="font-style: italic; color: green;">//Example script_move(3);
{
<span style="font-style: italic; color: green;">//Declare temporary variables
<span style="font-weight: bold; color: #000000;">var xsp;
<span style="font-style: italic; color: green;">//Check if buttons are pressed
xsp=([url=http://www.zonamakers.com/gmlreference/keyboard_check_direct.html]<span style="color: navy;">keyboard_check_direct[/url](<span style="color: #663300;">vk_right)-[url=http://www.zonamakers.com/gmlreference/keyboard_check_direct.html]<span style="color: navy;">keyboard_check_direct[/url](<span style="color: #663300;">vk_left))*argument0;
<span style="font-style: italic; color: green;">//Execute movement
<span style="font-weight: bold; color: #000000;">repeat([url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url](xsp)){
<span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x+[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](xsp),y<span style="color: #cc66cc;">+1) and ![url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x,y<span style="color: #cc66cc;">+1){
<span style="font-weight: bold; color: #000000;">x+=[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](xsp);
<span style="font-weight: bold; color: #000000;">y+=<span style="color: #cc66cc;">1;}
<span style="font-weight: bold; color: #000000;">else <span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x+[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](xsp),<span style="font-weight: bold; color: #000000;">y){
<span style="font-weight: bold; color: #000000;">x+=[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](xsp);}
<span style="font-weight: bold; color: #000000;">else <span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x+[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](xsp),y<span style="color: #cc66cc;">-1) and ![url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x,y<span style="color: #cc66cc;">+1){
<span style="font-weight: bold; color: #000000;">x+=[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](xsp);
y-=<span style="color: #cc66cc;">1;}}
}
Code:
<div class="gml" id="{CB}" style="font-family: monospace;"><ol><span style="font-style: italic; color: green;">//Pixel Perfect Gravity (Manual Gravity)
<span style="font-style: italic; color: green;">//made by Markolainen
<span style="font-style: italic; color: green;">//Put in step event for normal gravity on always
<span style="font-style: italic; color: green;">//argument0=gravity;
<span style="font-style: italic; color: green;">//argument1=maximum fall speed
<span style="font-style: italic; color: green;">//Example: script_gravity(0.2,4);
<span style="font-style: italic; color: green;">//You need to put ysp=0 in Create event of each object that uses this code!!!
<span style="font-weight: bold; color: #000000;">repeat([url=http://www.zonamakers.com/gmlreference/abs.html]<span style="color: navy;">abs[/url](ysp)){
<span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x,<span style="font-weight: bold; color: #000000;">y+[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](ysp)){
<span style="font-weight: bold; color: #000000;">y+=[url=http://www.zonamakers.com/gmlreference/sign.html]<span style="color: navy;">sign[/url](ysp);}}
<span style="font-weight: bold; color: #000000;">if [url=http://www.zonamakers.com/gmlreference/place_free.html]<span style="color: navy;">place_free[/url](<span style="font-weight: bold; color: #000000;">x,y<span style="color: #cc66cc;">+1){
ysp=[url=http://www.zonamakers.com/gmlreference/min.html]<span style="color: navy;">min[/url](argument0+ysp,argument1);}
<span style="font-weight: bold; color: #000000;">else{
ysp=<span style="color: #cc66cc;">0;}