copy's nützliche Scripte

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • copy's nützliche Scripte

      Ich sammle inzwischen mir ziemlich viele Scripte an, die ich im Laufe der Zeit immer wieder brauchte oder kompliziert sind/waren und speichere sie mir in einem extra Ordner. Nun, da der Ordner ziemlich voll geworden ist und es einige Scripte in die Kategorie "auf jeden Fall veröffentlichen" geschafft haben, will ich diesem mal nachkommen.

      Aber vorerst:
      • Hierbei handelt es sich um Scripte, die eine gewisse GML-Verständnis erfordern.
      • Alle Scripte sind für den Game Maker 6.1 geschrieben, dass sie auch (bei korrekter Anwendung) auf anderen Versionen laufen, kann ich nicht garantieren.
      • Einige Scripts benötigen die registrierte/Pro-Version des Game Makers.
      • Manche Skripte sollte man, um verstehen zu können, was sie bewirken, einfach mal ausprobieren.
      • Der Einfachheit halber sind alle Scripte hier als Text verfügbar und können kopiert werden.
      (Bei Bedarf pack' ich alle Scripte in eine .gm6 Datei zum mergen.)

      Erstmal genug zu den ganzen Voraussetzungen und Infos.
      Jetzt kommt, was ihr alle so sehnsüchtig erwartet habt! :D

      cb_move(x,y,speed,fric)
      Beschleunigt das Objekt in Richtung Zielposition.
      Spoiler anzeigen
      x/y: Dort soll das Objekt hinbewegt werden.
      speed: Geschwindigkeitsmodifier (Standart: 1).
      fric: Reibungskraft (Standart: 0.2).
      speed und fric sind optional und müssen nicht angegeben werden.

      Beispiel:

      GML-Quellcode

      1. cb_move(mouse_x,mouse_y);
      2. // Bewegt das Objekt in Richtung Maus

      Script:

      GML-Quellcode

      1. var xx,yy,spd,fric;
      2. xx = argument0;
      3. yy = argument1;
      4. spd = argument2;
      5. if (spd==0) {spd = 1;}
      6. fric = argument3;
      7. if (fric==0) {fric = 0.2;}
      8. motion_add(point_direction(x,y,xx,yy),point_distance(x,y,xx,yy)/10*spd);
      9. speed *= 1-fric;

      cb_move2(x,y,speed,min)
      Bewegt das Objekt zur Zielposition. Die Geschwindigkeit entspricht der Distanz/Schrittgröße.
      Spoiler anzeigen
      x/y: Dort soll das Objekt hinbewegt werden.
      speed: Schrittgröße (2 = halbe Schritte, 4 = viertel Schritte).
      min: Mindestschrittgröße.

      Beispiel:

      GML-Quellcode

      1. cb_move2(mouse_x,mouse_y,2,10);
      2. // Bewegt das Objekt in Richtung Maus
      3. // und zwar immer die Hälfte der Strecke
      4. // mindestens jedoch 10 Pixel.

      Script:

      GML-Quellcode

      1. var xx,yy,spd,min,dir,dis;
      2. xx = argument0;
      3. yy = argument1;
      4. spd = argument2;
      5. min = argument3;
      6. dir = point_direction(x,y,xx,yy);
      7. dis = point_distance(x,y,xx,yy);
      8. if (dis > min) {motion_set(dir,max(min,dis/spd));}
      9. else {x = xx; y = yy;}

      cb_platform()
      Einfaches Platform Script, optimiert und komprimiert bis zum "geht nicht mehr".
      Spoiler anzeigen
      Veränderungen selbst im Script vornehmen.
      Bei Fragen zum Script bitte PN an mich!

      Script:

      GML-Quellcode

      1. acc = 0.3;
      2. fric = 0.1;
      3. jump = 5.5;
      4. maxspd = 4;
      5. // Keyboard
      6. if (keyboard_check(vk_left)) {hspd -= acc;}
      7. if (keyboard_check(vk_right)) {hspd += acc;}
      8. if !(keyboard_check(vk_left) xor keyboard_check(vk_right))
      9. {hspd *= 0.9;} else {
      10. if (keyboard_check(vk_left) and hspd>0) {hspd *= 1-fric;}
      11. if (keyboard_check(vk_right) and hspd<0) {hspd *= 1-fric;}
      12. }
      13. hspd = max(-maxspd,min(maxspd,hspd));
      14. if (!keyboard_check(vk_up) and vspd<0) {vspd *= 1-fric;}
      15. if (place_meeting(x,y+1,objBlock) and keyboard_check_pressed(vk_up)) {vspd = -jump;}
      16. // Collision & Move
      17. if (place_meeting(x,y+1,objBlock)) {
      18. grav = 0;
      19. if (vspd > 0) {
      20. move_contact_solid(270,vspd);
      21. vspd = 0;
      22. }
      23. } else {grav = 0.2;}
      24. vspd += grav;
      25. vspd = min(10,vspd);
      26. if (hspd != 0) {
      27. if (place_meeting(x+hspd,y,objBlock)) {
      28. if (hspd >= 0) {dir = 0;} else {dir = 180;}
      29. move_contact_solid(dir,abs(hspd));
      30. } else {x += hspd;}
      31. }
      32. if (vspd != 0) {
      33. if (place_meeting(x,y+vspd,objBlock)) {
      34. if (vspd >= 0) {dir = 270;} else {dir = 90;}
      35. move_contact_solid(dir,abs(vspd));
      36. } else {y += vspd;}
      37. }
      38. if (place_meeting(x+sign(hspd),y,objBlock)) {hspd = 0;}
      Alles anzeigen

      string_get(str,sep,ind)
      Einfaches Script zum Trennen von einem String, der durch ein oder mehrere (gleiche) Zeichen aufgeteilt ist.
      Spoiler anzeigen
      str: String, der mehrere Substrings enthält..
      sep: ..getrennt durch dieses Zeichen.
      ind: Welcher Substring zurückgegeben werden soll (Beginnt bei 0).

      Beispiel:

      GML-Quellcode

      1. str = "Ein|String|auf|Reisen!";
      2. show_message(string_get(str,"|",0)); // Ergibt "Ein"
      3. show_message(string_get(str,"|",1)); // Ergibt "String"
      4. show_message(string_get(str,"|",3)); // Ergibt "Reisen!"

      Script:

      GML-Quellcode

      1. var str,sep,ind,rep,count,pos,len;
      2. str = argument0;
      3. sep = argument1;
      4. ind = argument2;
      5. rep = "¦";
      6. count = string_count(sep,str);
      7. if (ind>count) { return ""; }
      8. if (ind>=1) {
      9. repeat (ind-1) {
      10. str = string_replace(str,sep,rep);
      11. } pos = string_pos(sep,str)+1;
      12. } else { pos = 1; }
      13. if (ind<count) {
      14. if (ind!=0) { str = string_replace(str,sep,rep); }
      15. len = string_pos(sep,str)-pos;
      16. } else { len = string_length(str)-pos+1; }
      17. return string_copy(str,pos,len);
      Alles anzeigen

      string_split(str,trenn,list) (reg/pro only)
      Teilt einen String an einem bestimmten Trennzeichen auf und fügt die einzelnen Substrings einer Liste hinzu.
      Spoiler anzeigen
      str: String, der mehrere Substrings enthält..
      trenn: ..getrennt durch dieses Zeichen.
      list: Die Liste.

      Beispiel:

      GML-Quellcode

      1. list = ds_list_create();
      2. str = "Ein|String|auf|Reisen!";
      3. string_split(str,"|",list));
      4. // Folgendes geht auch:
      5. list = string_split(str,"|",ds_list_create());
      6. show_message(ds_list_find_value(list,1)); // Ergibt "String"

      Script:

      GML-Quellcode

      1. var str,split,list,pos,line;
      2. str = argument0;
      3. split = argument1;
      4. list = argument2;
      5. if (string_count(split,str)==0) {ds_list_add(list,str);}
      6. else {
      7. do {
      8. pos = string_pos(split,str);
      9. line = string_copy(str,0,pos-1);
      10. ds_list_add(list,line);
      11. str = string_replace(str,line+split,"");
      12. } until (string_count(split,str)==0);
      13. ds_list_add(list,str);
      14. }
      15. return list;
      Alles anzeigen

      ds_list_foreach(list,script,arg0,arg1,...) (reg/pro only)
      Führt für jeden Eintrag in der Liste einen Script aus.
      Spoiler anzeigen
      list: Die Liste.
      script: Der Script.
      argX: Zusätzliche Argumente.

      Beispiel:

      GML-Quellcode

      1. list = ds_list_create();
      2. ds_list_add(list,"Ains");
      3. ds_list_add(list,"Zwai");
      4. ds_list_add(list,"Drai");
      5. ds_list_foreach(list,ein_script,"Blubb: ");
      6. // So sieht ein_script aus:
      7. show_message(argument1+argument0);

      Script:

      GML-Quellcode

      1. var list,script,i;
      2. list = argument0;
      3. script = argument1;
      4. for (i=0;i<ds_list_size(list);i+=1) {
      5. script_execute(script,ds_list_find_value(list,i),
      6. argument2,argument3,argument4,argument5,
      7. argument6,argument7,argument8,argument9,
      8. argument10,argument11,argument12,argument13,
      9. argument14);
      10. }

      cb_valchange(val1,val2,speed,min)
      Gibt eine Zahl zurück, die näher an val2 liegt (ähnlich wie cb_move2()).
      Spoiler anzeigen
      var1: Momentane Zahl.
      val2: Zielzahl.
      speed: Schrittgröße (2 = halbe Schritte, 4 = viertel Schritte).
      min: Mindestschrittgröße.

      Beispiel:

      GML-Quellcode

      1. x = cb_valchange(x,mouse_x,4,2);
      2. // Bewegt das Objekt horizontal in Richtung Maus,
      3. // genauer gesagt immer ein viertel der Strecke.

      Script:

      GML-Quellcode

      1. var val1,val2,spd,min,dis;
      2. val1 = argument0;
      3. val2 = argument1;
      4. spd = argument2;
      5. min = argument3;
      6. dis = val2-val1;
      7. if (abs(dis) > min) {val1 += dis/spd;} else {val1 = val2;}
      8. return val1;

      ds_list_create_files(dir,ext) (reg/pro only)
      Erstellt eine Liste, füllt diese mit den Namen aller Dateien mit einer bestimmten Endung und gibt sie zurück.
      Spoiler anzeigen
      dir: Verzeichnis.
      ext: Dateiendung.

      Beispiel:

      GML-Quellcode

      1. list = ds_list_create_files(working_directory+"\",".bmp")

      Script:

      GML-Quellcode

      1. _files_path = argument0;
      2. _files_ext = argument1;
      3. _files_list = ds_list_create();
      4. _file = file_find_first(_files_path+"*"+_files_ext,0);
      5. if (_file != "") {
      6. ds_list_add(_files_list,_file);
      7. while (1) {
      8. _file = file_find_next();
      9. if (_file = "") {break;}
      10. else {ds_list_add(_files_list,_file);}
      11. }
      12. }
      13. file_find_close();
      14. return _files_list;
      Alles anzeigen

      draw_line_aa(x1,y1,x2,y2)
      Zeichnet ein Linie mit Antialiasing. Benutzt den Wu-Algorithmus.
      Spoiler anzeigen
      Beispiel:

      GML-Quellcode

      1. draw_line_aa(142,200,300,423);

      Script:

      GML-Quellcode

      1. var grad,xd,yd,length,xm,ym,
      2. xgap,ygap,xend,yend,xf,yf,
      3. xx,yy,ix1,ix2,iy1,iy2,c1,c2,
      4. alpha,temp;
      5. x1 = argument0;
      6. y1 = argument1;
      7. x2 = argument2;
      8. y2 = argument3;
      9. alpha = draw_get_alpha();
      10. xd = (x2-x1);
      11. yd = (y2-y1);
      12. if (xd==0||yd==0||abs(xd)==abs(yd)) {
      13. draw_line(x1,y1,x2,y2); exit;
      14. }
      15. if (abs(xd) > abs(yd)) {
      16. if (x1 > x2) {
      17. temp = x1; x1 = x2; x2 = temp;
      18. temp = y1; y1 = y2; y2 = temp;
      19. }
      20. grad = yd/xd;
      21. // End Point 1
      22. xend = round(x1);
      23. yend = y1+grad*(xend-x1);
      24. xgap = 1-frac(x1+.5);
      25. ix1 = xend;
      26. iy1 = floor(yend);
      27. c1 = (1-frac(yend))*xgap*alpha;
      28. c2 = frac(yend)*xgap*alpha;
      29. draw_set_alpha(c1); draw_point(ix1,iy1);
      30. draw_set_alpha(c2); draw_point(ix1,iy1+1);
      31. yf = yend+grad;
      32. // End Point 2
      33. xend = round(x2);
      34. yend = y2+grad*(xend-x2);
      35. xgap = 1-frac(x2-.5);
      36. ix2 = xend;
      37. iy2 = floor(yend);
      38. c1 = (1-frac(yend))*xgap*alpha;
      39. c2 = frac(yend)*xgap*alpha;
      40. draw_set_alpha(c1); draw_point(ix2,iy2);
      41. draw_set_alpha(c2); draw_point(ix2,iy2+1);
      42. // Main Loop
      43. for (xx=ix1+1;xx<ix2;xx+=1) {
      44. c1 = (1-frac(yf))*alpha;
      45. c2 = frac(yf)*alpha;
      46. draw_set_alpha(c1); draw_point(xx,floor(yf));
      47. draw_set_alpha(c2); draw_point(xx,floor(yf)+1);
      48. yf += grad;
      49. }
      50. } else {
      51. if (y1 > y2) {
      52. temp = y1; y1 = y2; y2 = temp;
      53. temp = x1; x1 = x2; x2 = temp;
      54. }
      55. grad = xd/yd;
      56. // End Point 1
      57. yend = round(y1);
      58. xend = x1+grad*(yend-y1);
      59. ygap = 1-frac(y1+.5);
      60. iy1 = yend;
      61. ix1 = floor(xend);
      62. c1 = (1-frac(xend))*ygap*alpha;
      63. c2 = frac(xend)*ygap*alpha;
      64. draw_set_alpha(c1); draw_point(ix1,iy1);
      65. draw_set_alpha(c2); draw_point(ix1,iy1+1);
      66. xf = xend+grad;
      67. // End Point 2
      68. yend = round(y2);
      69. xend = x2+grad*(yend-y2);
      70. ygap = 1-frac(y2-.5);
      71. iy2 = yend;
      72. ix2 = floor(xend);
      73. c1 = (1-frac(xend))*ygap*alpha;
      74. c2 = frac(xend)*ygap*alpha;
      75. draw_set_alpha(c1); draw_point(ix2,iy2);
      76. draw_set_alpha(c2); draw_point(ix2+1,iy2);
      77. // Main Loop
      78. for (yy=iy1+1;yy<iy2;yy+=1) {
      79. c1 = (1-frac(xf))*alpha;
      80. c2 = frac(xf)*alpha;
      81. draw_set_alpha(c1); draw_point(floor(xf),yy);
      82. draw_set_alpha(c2); draw_point(floor(xf)+1,yy);
      83. xf += grad;
      84. }
      85. }
      86. draw_set_alpha(alpha);
      Alles anzeigen

      draw_rectangle_texture(x,y,width,height,border,texture,rotation,centered) (reg/pro only)
      Zeichnet ein Rechteck mit bestimmter Größe, Textur und Randbreite an der Position.
      Spoiler anzeigen
      x/y: Position.
      width/height: Größe.
      border: Randbreite (0=kein Rand).
      texture: Textur.
      rotation: Richtung.
      centered: Mittig ausgerichtet?

      Beispiel:

      GML-Quellcode

      1. draw_rectangle_texture(x,y,200,150,5,tex,direction,true);

      Script:

      GML-Quellcode

      1. var x1,y1,x2,y2,border,rot;
      2. xx = argument0;
      3. yy = argument1;
      4. width = argument2;
      5. height = argument3;
      6. border = argument4;
      7. rot = argument6;
      8. if (argument7) {
      9. xx -= lengthdir_x(width/2,rot)+lengthdir_x(height/2,rot-90);
      10. yy -= lengthdir_y(width/2,rot)+lengthdir_y(height/2,rot-90);
      11. }
      12. if (border==0) {
      13. draw_primitive_begin_texture(pr_trianglefan,argument5);
      14. draw_vertex_texture(xx+lengthdir_x(width/2,rot)+lengthdir_x(height/2,rot-90),
      15. yy+lengthdir_y(width/2,rot)+lengthdir_y(height/2,rot-90),0.5,0.5);
      16. draw_vertex_texture(xx,yy,0,0);
      17. draw_vertex_texture(xx+lengthdir_x(width,rot),yy+lengthdir_y(width,rot),1,0);
      18. draw_vertex_texture(xx+lengthdir_x(width,rot)+lengthdir_x(height,rot-90),
      19. yy+lengthdir_y(width,rot)+lengthdir_y(height,rot-90),1,1);
      20. draw_vertex_texture(xx+lengthdir_x(height,rot-90),yy+lengthdir_y(height,rot-90),0,1);
      21. draw_vertex_texture(xx,yy,0,0);
      22. } else {
      23. draw_primitive_begin_texture(pr_trianglestrip,argument5);
      24. draw_vertex_texture(xx,yy,0,0);
      25. draw_vertex_texture(xx+lengthdir_x(border,rot-45),yy+lengthdir_y(border,rot-45),0,0);
      26. draw_vertex_texture(xx+lengthdir_x(width,rot),yy+lengthdir_y(width,rot),1,0);
      27. draw_vertex_texture(xx+lengthdir_x(width,rot)+lengthdir_x(border,rot-135),
      28. yy+lengthdir_y(width,rot)+lengthdir_y(border,rot-135),1,0);
      29. draw_vertex_texture(xx+lengthdir_x(width,rot)+lengthdir_x(height,rot-90),
      30. yy+lengthdir_y(width,rot)+lengthdir_y(height,rot-90),1,1);
      31. draw_vertex_texture(xx+lengthdir_x(width,rot)+lengthdir_x(height,rot-90)+lengthdir_x(border,rot+135),
      32. yy+lengthdir_y(width,rot)+lengthdir_y(height,rot-90)+lengthdir_y(border,rot+135),1,1);
      33. draw_vertex_texture(xx+lengthdir_x(height,rot-90),yy+lengthdir_y(height,rot-90),0,1);
      34. draw_vertex_texture(xx+lengthdir_x(height,rot-90)+lengthdir_x(border,rot+45),
      35. yy+lengthdir_y(height,rot-90)+lengthdir_y(border,rot+45),0,1);
      36. draw_vertex_texture(xx,yy,0,0);
      37. draw_vertex_texture(xx+lengthdir_x(border,rot-45),yy+lengthdir_y(border,rot-45),0,0);
      38. }
      39. draw_primitive_end();
      Alles anzeigen

      EDIT: strings_get in string_get umbenannt. string_split und draw_rectangle_texture hingefügt.
      EDIT2: string_get aktualisiert (ihr könnt euch nicht vorstellen, wie alt das jetzt schon ist ...), ds_list_foreach und draw_line_aa hinzugefügt.

      Viel Spaß und Erfolg mit den Scripts,
      Gruß, euer kopierjunge

      Dieser Beitrag wurde bereits 8 mal editiert, zuletzt von copyboy ()

    • Nice :)

      Sag mal warum machst du Underscorevariablen ohne var - sind das dann immernoch lokale Variablen? Die Funktion strings_get würde ich übrigens string_split oder string_explode nennen, das erhöht den Wiedererkennungswert - wobei es wird ja kein Array o.ä. zurückgegeben. Was aber sinnvoller wäre, da man sonst die gleiche Funktion öfters aufrufen muss, wenn man auf mehr als eine Position zugreifen will.
      On teh internet u pwn noobs - but in real life noobs own you.
    • Ist ganz nett. Das mit dem string get würd ich auch string split nennen und so wie oben beschrieben abändern (hab ich glaub ich auch schon mal gemacht). Bis jetzt ist aber noch nichts richtig kompliziertes drinnen (obwohl das Plattform Skript doch sehr sauber wirkt). Aber es soll ja noch was kommen... :thumbsup:
      PULSE

      Zweispieler [||||||||||]
      Einspieler [||||||||||]

      [Die Entgrater ist auf Eis gelegt]
    • Andere nützliche Skripte

      Da ich keinen anderen "Nützliche Skripte" Ordner finde habe ich mir mal erlaubt, es hier reinzuklatschen - weil mir dieses Skript mal wieder die Lösung war. Bitte schieben.

      Antroid's move_round()
      Spoiler anzeigen

      Quellcode

      1. ////////////////////////////////////////////////////////////////
      2. // script name: move_round
      3. // creator: ANTROID
      4. // date: 30.07.2003
      5. //
      6. // description: Dieses Script rundet die Kollision!
      7. //
      8. // arguments: argument0: Maximale Abrundung in Pixeln.
      9. //
      10. // remarks: Sollte in jedem Step ausgeführt werden!
      11. // Gibt wieder, ob Abrundung stattgefunden hat!
      12. // Object muss solid sein! Gibt die Länge der
      13. // gerundeten Strecke in Pixeln wieder.
      14. ////////////////////////////////////////////////////////////////
      15. var move_round_ok,move_round_tool,move_round_dis;
      16. move_round_dis=0
      17. if (!place_free(x+hspeed,y+vspeed))
      18. {
      19. move_round_ok=false
      20. move_round_tool=1
      21. move_round_dis=1
      22. while (move_round_dis<=round(argument0))
      23. {
      24. if (place_empty(x+hspeed+cos(degtorad(direction+90))*move_round_tool*move_round_dis,
      25. y+vspeed-sin(degtorad(direction+90))*move_round_tool*move_round_dis))
      26. {
      27. x += cos(degtorad(direction+90))*move_round_tool*move_round_dis
      28. y -= sin(degtorad(direction+90))*move_round_tool*move_round_dis
      29. move_round_ok=true
      30. break;
      31. }
      32. else
      33. {
      34. if (move_round_tool=1)
      35. {
      36. move_round_tool=-1
      37. }
      38. else
      39. {
      40. move_round_tool=1
      41. move_round_dis+=1
      42. }
      43. }
      44. }
      45. if (!move_round_ok)
      46. {
      47. speed=0
      48. }
      49. }
      50. return move_round_dis
      Alles anzeigen

      Wirkt Wunder, wenn Objekte irgendwo steckenbleiben.
      Ist zwar schon alt - aber ich wette, viele kennen es noch nicht. Kann ich immer wieder empfehlen.

      Explode() - hab leider vergessen von wem das war. Jemand von der Community hier.

      Spoiler anzeigen

      Quellcode

      1. var kommas, i, kommapos;
      2. kommas=string_count(argument2,argument0);
      3. for (i=0;i<=kommas; i+=1) {
      4. kommapos=string_pos(argument2,argument0);
      5. if (kommapos=0) kommapos=string_length(argument0)+1;
      6. variable_local_array_set(argument1,i,string_copy(argument0,1,kommapos-1));
      7. argument0=string_delete(argument0,1,kommapos);
      8. }
      9. /*
      10. String: Der String, der geschnitten werden soll. (String)
      11. Arrayname: Der Name des Arrays, in das dann alles rein soll. (String)
      12. Zeichen: Zeichen, an dem geschnitten werden soll. (String)
      13. explode(String,Arrayname,Zeichen);
      Alles anzeigen

      Brauche ich nie, aber da Ihr gerade drüber gesprochen habt...

      StringCompare() - das ist aus PointMagic. Zu finden bei 64digits.

      Spoiler anzeigen

      Quellcode

      1. /*
      2. Arguments:
      3. 0 - string - string 1
      4. 1 - string - string 2
      5. Returns: real - string similarity ( 0: no match | 1: exact match | 0-1: fractional match )
      6. */
      7. // Vars
      8. var c, d, i, j, ml, s1, s2, s1len, s2len;
      9. s1 = argument0;
      10. s2 = argument1;
      11. s1len = string_length(s1);
      12. s2len = string_length(s2);
      13. // Get max length
      14. ml = max(s1len,s2len);
      15. // If both strings are empty, return exact string similarity
      16. if (ml == 0) return 1;
      17. // If either string is empty, set dist as other string length
      18. d = -1;
      19. if (s1len == 0) d = s2len;
      20. if (s2len == 0) d = s1len;
      21. // Else
      22. if (d == -1) {
      23. // init string comparison array
      24. global.array_strcomp[s1len+1,s2len+1] = 0;
      25. for (i = 0; i <= s1len; i += 1;) global.array_strcomp[i,0] = i;
      26. for (j = 0; j <= s2len; j += 1;) global.array_strcomp[0,j] = j;
      27. // get minimum string distance
      28. c = 0;
      29. for (i = 1; i <= s1len; i += 1;) {
      30. for (j = 1; j <= s2len; j += 1;) {
      31. if (string_copy(s2,j-1,1) == string_copy(s1,i-1,1)) c = 0;
      32. else c = 1;
      33. global.array_strcomp[i,j] = min(
      34. global.array_strcomp[i-1,j] + 1,
      35. global.array_strcomp[i,j-1] + 1,
      36. global.array_strcomp[i-1,j-1] + c);
      37. }
      38. }
      39. d = global.array_strcomp[s1len,s2len];
      40. }
      41. // Return string similarity
      42. return 1-d/ml;
      Alles anzeigen

      Das brauche ich zugegeben auch nie. Dieses Skript vergleicht zwei Strings und sagt uns, wie sehr sich die Inhalte gleichen - z.B. für Autokorrektur. Bei PointMagic haben die das benutzt um Bewegungsabläufe zu vergleichen. Super.

      Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von Melancor ()

    • Ich hab das hier mal irgentwann aus Spaß gemacht:

      Move-Skript
      Spoiler anzeigen

      GML-Quellcode

      1. /* ***Move-Script***
      2. ***Argument 0: Type (0=Absolut, 1=Relative, 2=Relative to mouse)***
      3. ***Argument 1: Key-Type (0=Arrowkeys, 1=W-A-S-D)***
      4. ***Speeds:
      5. ***Argument 2: Speed (forward/up)***
      6. ***Argument 3: Speed (backward/down)***
      7. ***Argument 4: Speed (left)***
      8. ***Argument 5: Speed (right)***
      9. ***Argument 6: Stop (power,0=none)***
      10. ***Argument 7: Max Speed***
      11. */
      12. /* Absolute Part */
      13. if argument0=0 {
      14. /*Arrow Keys*/
      15. if argument1=0 {
      16. if keyboard_check(vk_up) {direction=90; speed=argument2;}
      17. if keyboard_check(vk_down) {direction=270;speed=argument3;}
      18. if keyboard_check(vk_left) {direction=180;speed=argument4;}
      19. if keyboard_check(vk_right){direction=0; speed=argument5;}
      20. }
      21. /*W-A-S-D*/
      22. if argument1=1 {
      23. if keyboard_check(ord("W")){direction=90; speed=argument2;}
      24. if keyboard_check(ord("S")){direction=270;speed=argument3;}
      25. if keyboard_check(ord("A")){direction=180;speed=argument4;}
      26. if keyboard_check(ord("D")){direction=0; speed=argument5;}
      27. }
      28. friction=argument6; //Setting the friction
      29. }
      30. /* Relative [1] Part */
      31. if argument0=1 {
      32. if argument1=0 {
      33. /*Arrow Keys*/
      34. if keyboard_check(vk_up) {motion_add(direction,argument2);}
      35. if keyboard_check(vk_down) {speed-=argument3;}
      36. if keyboard_check(vk_left) {direction+=argument4;}
      37. if keyboard_check(vk_right){direction-=argument5;}
      38. }
      39. if argument1=1 {
      40. /*W-A-S-D*/
      41. if keyboard_check(ord("W")){motion_add(direction,argument2);}
      42. if keyboard_check(ord("S")){speed-=argument3;}
      43. if keyboard_check(ord("A")){direction+=argument4;}
      44. if keyboard_check(ord("D")){direction-=argument5;}
      45. }
      46. image_angle=direction; //Making the sprite turn,too
      47. friction=argument6; //Setting the friction
      48. /*Speed Limits*/
      49. if speed>argument7 {
      50. speed=argument7;
      51. }
      52. if speed<-argument7 {
      53. speed=-argument7;
      54. }
      55. }
      56. /* Relative [2] Part */
      57. if argument0=2 {
      58. image_angle=point_direction(x,y,mouse_x,mouse_y); //Turn the sprite to the mouse
      59. if argument1=0 {
      60. /*Arrow Keys*/
      61. /*ATTENTION!**The script uses image_angle to move, so you're not able to set it anywhere else*/
      62. if keyboard_check(vk_up) {motion_add(image_angle,argument2); }
      63. if keyboard_check(vk_down) {motion_add(image_angle+180,argument3);}
      64. if keyboard_check(vk_left) {motion_add(image_angle+90,argument4); }
      65. if keyboard_check(vk_right){motion_add(image_angle-90,argument5); }
      66. }
      67. if argument1=1 {
      68. /*W-A-S-D*/
      69. /*ATTENTION!**The script uses image_angle to move, so you're not able to set it anywhere else*/
      70. if keyboard_check(ord("W")){motion_add(image_angle,argument2); }
      71. if keyboard_check(ord("S")){motion_add(image_angle+180,argument3);}
      72. if keyboard_check(ord("A")){motion_add(image_angle+90,argument4); }
      73. if keyboard_check(ord("D")){motion_add(image_angle-90,argument5); }
      74. }
      75. friction=argument6;
      76. /*Speed Limits*/
      77. if speed>argument7 {
      78. speed=argument7;
      79. }
      80. if speed<-argument7 {
      81. speed=-argument7;
      82. }
      83. }
      84. /* END */
      Alles anzeigen

      Sind verschiedene "Bewegungsarten", einfach mal ausprobieren ^^

      Könnte für Anfänger nützlich sein...aber sonst eigentlich unnötig oder nur für Sachen geeignet, wo man "nur mal schnell was testen will". :rolleyes:
    • Hab hier mal meinen draw_text_outline Script:

      GML-Quellcode

      1. //////////////////////////////////////////////////////////////////////////////////////////////////////
      2. // argument0: x //
      3. // argument1: y //
      4. // argument2: text color //
      5. // argument3: outline color //
      6. // argument4: text //
      7. // argument5: breite der outline ( funktioniert nur bei groesseren fonts gut ) ( standart: 1 ) //
      8. // argument6: precise ( bei grossen font auf 'true' schalten. ) //
      9. //////////////////////////////////////////////////////////////////////////////////////////////////////
      10. var xx, yy, tcol, ocol, tmpcol, b, p;
      11. xx = argument0;
      12. yy = argument1;
      13. tcol = argument2;
      14. ocol = argument3;
      15. text = argument4;
      16. b = argument5;
      17. p = argument6;
      18. tmpcol = draw_get_color();
      19. draw_set_color(ocol);
      20. draw_text(xx+b,yy,text);
      21. draw_text(xx,yy+b,text);
      22. draw_text(xx-b,yy,text);
      23. draw_text(xx,yy-b,text);
      24. if (p) {
      25. draw_text(xx+b,yy-b,text);
      26. draw_text(xx-b,yy+b,text);
      27. draw_text(xx+b,yy+b,text);
      28. draw_text(xx-b,yy-b,text);
      29. }
      30. draw_set_color(tcol);
      31. draw_text(xx,yy,text);
      32. draw_set_color(tmpcol);
      Alles anzeigen


      Mit diesem Script lässt sich ein Text mit einer Outline drumrum zeichnen.

      Bsp.:

      GML-Quellcode

      1. draw_text_outline(x,y,c_white,c_black,"text",1,true);


      ...sieht so aus:


      =)
      fabse64 -> haiyyu
    • fabse64 schrieb:

      Mit diesem Script lässt sich ein Text mit einer Outline drumrum zeichnen.

      Bsp.:

      GML-Quellcode

      1. draw_text_outline(x,y,c_white,c_black,"text",1,true);


      ...sieht so aus:


      =)
      Sieht nett aus ^^

      Danke auch an den Rest. Wenn ichs mal brauch, geb ich Credits (auch wenn ich eigentlich >fast< nix veröffentliche)
      So far, Schattenphoenix~
      _____________________________________________________________________________
      "Who needs a stairway to heaven...
      If there is an elevator to hell... ?
      "
      - Vergessen
      "Auch ein perfektes Chaos ist etwas vollkommenes."
      - Jean Genet
    • Habe für ein Spiel mal ein Skript geschrieben, der die Schrieft "selber schreibt".
      Nannte den Skript "draw_text_array" - Nicht ganz passend, aber sinngemäß.
      Sollte eigtnl sich selbst erklären, habe aber den GM7 Pro und dies damit erstellt, noch nie mit Lite version oder den GM6.1 getestet.

      GML-Quellcode

      1. {
      2. /*
      3. * MADE BY PASCAL PIDUHN
      4. * @YOYOGAMES: METALKNIGHT
      5. * E-MAIL: M.METALKNIGHT@HOTMAIL.COM
      6. */
      7. var i, j, h, k, w, z;
      8. i = 1; // 2te Schleifen-Variable, die aber auf 1 zurückgestellt wird, bei Zeilenbrüchen. (Um linksbündig zu schreiben)
      9. j = 1; // Gibt die Zeile an
      10. h = 1; // Schleifen-Variable (Gibt den Index an)
      11. k = argument1; // Die Schrieft-Größe, muss in der Funktion angegeben werden
      12. w = 0; // Ist für kleine Buchstaben (wie I), damit größere Lücken nicht entstehen
      13. z = 0; // Ist für gr0ße Zeichen (wie @), damit keine größeren Lücken entstehen
      14. for (h = 1; h <= string_length(argument0); h += 1)
      15. {
      16. if !(string_char_at(argument0,h) == "*")
      17. {
      18. if (string_char_at(argument0,h) == "#")
      19. {
      20. j += 1;
      21. h += 1;
      22. i = 1;
      23. w = 0;
      24. z = 0;
      25. }
      26. if (string_char_at(argument0,h-1) == "i")
      27. w += k-(k/4*3);
      28. if (string_char_at(argument0,h-1) == "I")
      29. w += k-(k/2);
      30. if (string_char_at(argument0,h-1) == "@")
      31. z -= k-(k/2);
      32. draw_text(((x+(k*i))-w)-z,y+(k*j),string_char_at(argument0,h));
      33. screen_refresh();
      34. if !(string_char_at(argument0,h) == " ")
      35. sound_play(snd_schreiben);
      36. sleep(50);
      37. }
      38. else
      39. sleep(2000);
      40. i += 1;
      41. k = argument1;
      42. }
      43. sleep(3000);
      44. if (argument2 == 1)
      45. room_goto_next();
      46. else if (argument2 == 2)
      47. room_goto(1);
      48. else
      49. exit;
      50. }
      Alles anzeigen


      P.S.: Ist nich ganz fertig bzw. fehlen noch viele Buchstaben die man mit Korrekturen machen könnte. (siehe Große und Kleine Buchstabenvariablen)
      Habe nur die gemacht, die ich grade brauchte.

      Benutzten kann man dies sow:

      GML-Quellcode

      1. else if (room == 14)
      2. {
      3. draw_set_color(c_red);
      4. draw_set_font(font_title);
      5. draw_text_array("Thank You for playing =D*#My Game ;D*# #Please comment =D",24,1);
      6. }

      (Kleiner ausschnitt aus mein "The 2D Game")

      Edit:
      Vergessen ^^'''
      Argument0 = Text (string)
      Argument1 = Schrieftgröße
      Argument2 = { 1 = Zum nächster raum | 2 = In einen Beliebigen raum weiterschicken (muss geändert werden, kann auch mit Arguments verändert werden) | Alles andere = es passiert nichts }
    • Ich hab auch einmal einen Script gemacht, wo man einen Schatten bei einen Text macht.
      [scr_draw_shadow]

      GML-Quellcode

      1. //argument0 = x
      2. //argument1 = y
      3. //argument2 = shadow color
      4. //argument3 = text color
      5. //argument4 = distance from text to shadow
      6. //argument5 = alpha from shadow
      7. //argument6 = text
      8. //argument7 = direction (1=left, 0=right)
      9. var xx, yy, scol, tcol, dgc, text, r, b, alpha;
      10. xx=argument0;
      11. yy=argument1;
      12. scol=argument2;
      13. tcol=argument3;
      14. b=argument4;
      15. alpha=argument5;
      16. text=argument6;
      17. r=argument7;
      18. dgc=draw_get_color();
      19. draw_set_color(scol);
      20. draw_set_alpha(alpha);
      21. if (r=0)
      22. {draw_text(xx+b,yy+b,text);}
      23. if (r=1)
      24. {draw_text(xx-b,yy+b,text);}
      25. draw_set_alpha(1);
      26. draw_set_color(tcol);
      27. draw_text(xx,yy,text);
      28. draw_set_color(dgc);
      Alles anzeigen


      Und mit dem Code schreibt man eben mit Schatten:

      GML-Quellcode

      1. scr_draw_shadow(x,y,c_black,c_white,5,0.5,"Text",1)

      Ist mein erster Versuch also hoffe es ist nicht zu schlecht.

      Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von Afroman ()

    • Grmpf, genau sowas hatte ich auch in Arbeit.
      Ich find ihn schon mal sehr gut. ;)
      Vielleicht solltest du noch Alpha einbauen, um das ganze ein wenig realistischer zu machen.
      Und einen Parameter, bei dem man den Alpha Wert des Schattens festlegen kann.
      fabse64 -> haiyyu
    • Gut. =)
      -
      Da ich meinen Script nicht umsonst geschrieben haben möchte, setze ich ihn doch mal rein:

      draw_text_shadow(...);

      Hier ist der Script:

      GML-Quellcode

      1. /*
      2. * argument0: x
      3. * argument1: y
      4. * argument2: Text Farbe
      5. * argument3: Schatten Farbe
      6. * argument4: Schatten Alpha
      7. * argument5: Text
      8. * argument6: Abstand des Schattens vom Text
      9. * argument7: Richtung des Schattens ('direction')
      10. */
      11. var xx, yy, tcol, scol, salpha, text, b, dir, tmpcol, tmpalpha;
      12. xx = argument0;
      13. yy = argument1;
      14. tcol = argument2;
      15. scol = argument3;
      16. salpha = argument4;
      17. text = argument5;
      18. b = argument6;
      19. dir = argument7;
      20. tmpcol = draw_get_color();
      21. tmpalpha= draw_get_alpha();
      22. draw_set_color(tcol);
      23. draw_text(xx,yy,text);
      24. draw_set_alpha(salpha);
      25. draw_set_color(scol);
      26. draw_text(xx+lengthdir_x(b,dir),yy+lengthdir_y(b,dir),text);
      27. draw_set_alpha(tmpalpha);
      28. draw_set_color(tmpcol);
      Alles anzeigen


      Es funktioniert alles. =)
      fabse64 -> haiyyu
    • Ich hab gleich noch einen Script gemacht, einen Text, wo unter dem Text eine Spiegelung ist:

      [scr_draw_mirror]

      GML-Quellcode

      1. //argument0 = x
      2. //argument1 = y
      3. //argument2 = mirror color
      4. //argument3 = text color
      5. //argument4 = distance from text to mirror
      6. //argument5 = text
      7. //argument6 = alpha
      8. var text, mcol, tcol, xx, yy, dgc, he, we, alph, dga;
      9. xx=argument0
      10. yy=argument1
      11. mcol=argument2
      12. tcol=argument3
      13. we=argument4
      14. text=argument5
      15. alph=argument6
      16. dgc=draw_get_color()
      17. dga=draw_get_alpha()
      18. he=string_height_ext(text,we,1)
      19. draw_set_color(tcol)
      20. draw_text(xx,yy,text)
      21. draw_set_alpha(alph)
      22. draw_set_color(mcol)
      23. draw_text_transformed(xx,yy+he,text,1,-0.8,0)
      24. draw_set_color(dgc)
      25. draw_set_alpha(dga)
      Alles anzeigen

      Und das muss man schreiben:

      GML-Quellcode

      1. scr_draw_mirror(x,y,c_white,c_black,12,"Text",0.5)

      Dort wo 12 steht ist zu empfhelen, immer die größe der Font hinzuschreiben.
      Hoffe es gefällt euch.
      Wollt ihr denn gespiegelten Text ein bisschen länger oder so, dann einfach mit der Zeile herumspielen:

      GML-Quellcode

      1. draw_text_transformed(xx,yy+he,text,1,-0.8,0)

      Hoffe es gefällt euch. :D

      Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von Afroman ()

    • Wir könnten ne 'draw_text_...' Sammlung machen. =P

      Ich hab wieder 2 Scripte geschrieben:

      draw_text_underlined

      GML-Quellcode

      1. // Achtung: Der Valign sollte auf 'fa_top' gestellt sein.
      2. var xx, yy, text;
      3. xx = argument0;
      4. yy = argument1;
      5. text = argument2;
      6. draw_text(xx,yy,text);
      7. draw_line(xx,yy+string_height(text)+2,xx+string_width(text),yy+string_height(text)+2);

      GML-Quellcode

      1. draw_text_underlined(x,y,"text");


      draw_text_bold

      GML-Quellcode

      1. var xx, yy, text;
      2. xx = argument0;
      3. yy = argument1;
      4. text = argument2;
      5. draw_text(xx+1,yy,text);
      6. draw_text(xx,yy+1,text);
      7. draw_text(xx-1,yy,text);
      8. draw_text(xx,yy-1,text);
      9. draw_text(xx+1,yy-1,text);
      10. draw_text(xx-1,yy+1,text);
      11. draw_text(xx+1,yy+1,text);
      12. draw_text(xx-1,yy-1,text);
      13. draw_text(xx,yy,text);
      Alles anzeigen

      GML-Quellcode

      1. draw_text_bold(x,y,"text");
      fabse64 -> haiyyu
    • Ich finde, dass das solangsam ziemlich ausartet. Jetzt schon mindestens 6 Skripte um irgendwelche Texte zu zeichnen. Ich glaube nicht, dass der Thread für sowas gedacht war. Die ersten Skripte waren ja noch sehr hilfreich, aber irgendwelche kleinen Spielereien sollte doch wohl jeder selber auf die Reihe bekommen.
    • Ja ich weiss, dass das sicher sehr viel Leistung frisst.
      Und ich weiss auch, dass man bei den Font-Ressourcen einstellen kann, dass sie Fett sein soll.
      Aber ich hab den Script eigentlich nur dafür geschrieben, dass man nich immer ne neue Font erstellen muss, nur weil man mal was Fett schreiben will...
      fabse64 -> haiyyu