Jump to content


Photo

new to GM and GML, HELP!


  • Please log in to reply
21 replies to this topic

#1 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 30 April 2012 - 06:28 PM

hi, and thank you all in advance. ive been waiting and wanting a program like this for a long time!

whatever my current issue is will be in my most recent post.

i've been trying to make a real-time rpg that i eventually hope to convert into a mmorpg but i don't have pro and i have a lot to learn before then anyway.

so far i use mostly drag and drop, (gm8.1 Lite) and even some of that is beyond me but i do have some programming experience in basic on a commadore64 over 20 years ago (and its oddly similar)

i've already had numerous issues with my game, so i will be posting numerous problems in this thread but will try and keep it to one at a time.

Edited by Piwaket, 04 May 2012 - 04:44 AM.

  • 0

#2 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 30 April 2012 - 06:31 PM

my game is overhead action rpg, and i want my objects to layer according to y axis. (objects with smaller y axis are behind objects with a larger y) so what i tried was this.

in "end step" event of all objects i put

depth= - (object.y)

where object is the name of whatever object it was. i was thinking that should set the depth of each object on a depth equal to - it's current y coordinate putting objects lower on the screen at a lower depth, but as far as i can tell its using the location of the first object of whatever type to determine the depth of all similar objects, rather than using itself for the y coordinate. any ideas?
  • 0

#3 Lemon Pie

Lemon Pie

    GMC Member

  • GMC Member
  • 194 posts

Posted 30 April 2012 - 06:56 PM

use depth = -y instead.
If the objects are static (like houses, trees, etc.) & don't move put that in the create event for faster step execution (helps with lots of objects in a room).
  • 0

#4 iceshield

iceshield

    GMC Member

  • GMC Member
  • 494 posts

Posted 30 April 2012 - 06:56 PM

use just
depth = -y;
edit:
damn ... I'm slow
btw , if you have lots of static objects you can set their depth from one single place (if you don't want to type the depth code in each object). Make a game controller object and add
in creation event
alarm[0]=1; // this makes sure that all object are created and one step had passed
and in alarm 0 event
with (all) depth = -y; //this will set the depth for all object created and active in the room
(this will work just for static objects , objects that doesen't change their depth and object that starts with the room (it will not work for spawn objects , like monsters gold ,items etc))
so maybe you not need this , but it's good to know this way too :D

Edited by iceshield, 30 April 2012 - 07:10 PM.

  • 0

#5 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 30 April 2012 - 07:11 PM

thank you very much, that worked liked i wanted. on with the next issue im having.........

in my game there will be good and evil players and monsters. i want aoe spells to target only good characters, or only evil characters. and i was having several issues with how to even make an aoe spell.

this is what i did so far....
i made it a key event on my character that you hit a key and it draws a circle at the cursor the size of the aoe effect(so you can see/target the area you will be effecting), then when you left click it makes an event i called explosion at the cursor coordinates.... now how would i make the explosion event dammage all "evil" characters within the aoe effect?

edit: every character uppon creation has a variable called "race" set to: 1 (being good) or 2 (being evil)

Edited by Piwaket, 30 April 2012 - 07:35 PM.

  • 0

#6 Ventwig

Ventwig

    GMC Member

  • New Member
  • 279 posts

Posted 30 April 2012 - 08:22 PM

I think parent objects would help you here.
Make two objects "Good" and "Evil
can be completely blank.

Then make every evil thing have a parent object of evil, same with good (google parent objects for gm, it's very simple)

Now in the AoE spell, make a collision event with the parent object of evil.

In that put:
with(other){enemy_hp -= 5}

Make it connect with the good parent if you want it to hit the good guys. Or healing put += instead.

Also, enemy_hp is the variable of the enemy's hp. Change it to whatever.
If you need help setting up hp, ill help you there, too.
  • 0

#7 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 30 April 2012 - 08:55 PM

uppon creation i set the monster i created to have variable "monsterhp" set to 100
im trying to make the spell do 20 dammage

so if i understand right

once i left click and it creates the "explosion" object i would have that object have an invisible sprite the same as the "aoe" sprite, then add a collision event with "evil" (the parent object of all evil objects) and then in that event "execute a piece of code" ...check "other"....and put in

{
monsterhp= -20
}

and then i could have it do other things like play a visible animation and destroy itself and such?


edit:i did that and it seems to work sort of, i had the collision event execute that code then turn the "explosion" object back into the normal cursor ... but it kills the monster in one hit instead of taking 20 of it's 100 HP and it only seems to hit one monster within the "aoe" sprite with each blast.

i also put a "animation end" event in the "explosion" object and told it to change back into the normal cursor object so if it doesnt collide with an evil it changes back to a normal cursor anyway and nothing happens.

i just realized why its killing in one hit....im changing the "monsterhp" variable to -20....but not relative to what it is to begin with. that still doesnt explain why its only hitting one monster, but how would i add that to the code?

Edited by Piwaket, 30 April 2012 - 09:49 PM.

  • 0

#8 Ventwig

Ventwig

    GMC Member

  • New Member
  • 279 posts

Posted 30 April 2012 - 09:16 PM

yeah, that works, too instead of the with other thing i did.
Actually, i think you need to ditch the brackets altogether {}
  • 0

#9 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 30 April 2012 - 09:46 PM

yeah, that works, too instead of the with other thing i did.
Actually, i think you need to ditch the brackets altogether {}



it didn't work though, it kills the monster instantly instead of just dammaging it some. ...i did an edit in my last post of what i did.


edit: i fixed it. the code needed to be: (with other box checked) monsterhp-=20

and i took out the change object part in the collision event and just left it in the end animation event so the sprite flashes, does its dammage (relative to the monsters current hp) and then changes back to normal cursor.

Edited by Piwaket, 30 April 2012 - 10:31 PM.

  • 0

#10 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 30 April 2012 - 10:38 PM

yet another problem solved, and thank you again so much! whippin right allong here.... :D

next issue.....

for my main character i just have a collision event with every solid object and in that event i drag and drop "bounce off solids" which is quick and easy but if i set my monsters to solid and have the same collision event they tend to pile up and get stuck on eachother. is there a way that i can have the monsters move away from eachother(or any other solid they happen to get stuck in) in the event that they overlap?
  • 0

#11 Ventwig

Ventwig

    GMC Member

  • New Member
  • 279 posts

Posted 30 April 2012 - 10:49 PM

In the collide with the enemy event: Don't check the other box
move_towards_point(other.x,other.y,-5); alarm[0] = 30

In the alarm 0 event, do whatever you need to to change the movement back to normal

Ir SHOULD work IIRC, im not entirely sure
  • 0

#12 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 30 April 2012 - 11:07 PM

im not sure what it means or why it works but that did it.

i feel like im in waaay over my head but im making progress and so far its looking good.

thank you once again! :)
  • 0

#13 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 01 May 2012 - 12:22 AM

how would i make a code so that everytime the hit point variable of an object changes it draws the difference (in red for - and in green for +) above the object sprite for say... two seconds
  • 0

#14 Ventwig

Ventwig

    GMC Member

  • New Member
  • 279 posts

Posted 01 May 2012 - 01:00 AM

hmmm, that one may be a little harder, ill look into that.
I think I've got it, though.
In the collision event where you damage the enemy, make a variable equal to damage.
Remember the quotations
like
other.diffdamage = "20" other.drawdiff = true other.alarm[1]  = 60

Then in the draw of the enemy object (you can do this in the parent, and if your enemies use draw, just use the inherit parent events D&D)
if drawdiff == true draw_text(x,y-32,diffdamage)
In alarm 1:
drawdiff = false

Make sure to assign those variables in the create event in the create event
Create:
drawdiff = false diffdamage = "0"


This should work if i've got it right


also, the way this code works incase you're curious:
move_towards_point(other.x,other.y,-5)
Is that it takes the position of the other object, and the code makes it move towards the other object (the enemy).
But the speed is a NEGATIVE 5. And when you move towards something with a negative, you end up being further away
(think number line. If you try to get 20 to 100 using a -5, you just end up further away from 100.)
  • 0

#15 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 01 May 2012 - 01:19 AM

i could see how that might work, its probably going to take a bit more work than that because i plan to have alot of variables to alter overall dammage, like resistances to elements and such, but i should be able to work with that and tailor it to my needs.

ill mess with that and let ya know how that goes, ......in the meantime..... :D

i kno this is a common issue and i can probably find the answer if i look hard enough but maybe someone could make it quick and simple...

lifebars, ....really just the main characters lifebar,

#1 i was having trouble with drawing it in a fixed place on screen (when i walk away and the screen scrolls at all the bar scrolls off screen)
^^^^^^^^
(problem solved=view_xview)

#2 i want the option of more than 100 hp and i kno there is a way to tie the built in lifebar system in GM to a variable that can be over 100....but i dont kno how.

edit: your draw dammage codes worked...but it made the monster character invisible for some reason?

as a quick fix i told the draw event of the monster to draw a sprite of itself over itself at relative 0x,0y, but i would rather the original sprite remained visible.

edit edit: you have to tell it to redraw the sprite in draw event, i found a script that re-draws whatever the current sprite for the object is.

also i found a tutorial for making lifebars that was very helpful and i think i have that mostly sorted out now.

Edited by Piwaket, 01 May 2012 - 03:59 AM.

  • 0

#16 Ventwig

Ventwig

    GMC Member

  • New Member
  • 279 posts

Posted 01 May 2012 - 10:24 PM

An easier drawing thing is put draw_self()
in the draw event.

That way sprites and everything is handled normally, and the draw event works with that stuff.

If you wanted to use formulas, it's not really hard. Here's a quick example:
Okay, to make this work right UNCHECK the other tab and just recheck the self tab.
Put this in the code and just edit to your liking

other.damage = self.atk * 2- other.def //keep the self and other, but change atk and def to the stats. The *2 stuff is the formula
other.monsterhp -=  damage
other.diffdamage = string(damage)
other.drawdiff = true
other.alarm[1]  = 60

Edited by Ventwig, 01 May 2012 - 10:25 PM.

  • 0

#17 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 03 May 2012 - 05:36 PM

ohhhhh u can specify self.whatever ...i think that will solve some issues im trying to figure out....i pretty much got the dammage/resists/draw dammage thing figured out.(i basically did exactly what you said to i just figured it out on my own).. im still totally lost on most code, but im slowly getting it. im trying to stay away from adding code that i dont understand into my game, as that makes changing anything later a real pain.

Curent Issue: collisions are evil..... lol im having an issue with monster re-spawn, they sometimes spawn inside and get stuck in solid objects, i realize i could have it check the spawn point before spawning and if its not clear then choose a different point, but as it seems to be a bit of an issue all around(my character sometimes gets wedged between two objects and stuck) i was hoping for a simple code solution that i can add to any mobile object that if its mask is touching/overlapping a solid object it pushes out of it.... perhaps with a slight randomizer to direction so if its perfectly between two solid objects they dont just force it back and forth.

right now im using the code you gave me which mostly works, but my character sometimes gets wedged in narrow spots and there's the spawning inside stuff problem(mobiles bump off other solids fine but if they get bumped inside another solid or spawn inside one and are actually overlapping they stick inside the object.), if everything mobile just pushed out/away from solids i think that would be easiest. it just needs to be at a slightly varied direction each check so theoretically it would eventually "wiggle" its way out no matter how stuck it was. (fyi...i know its a dumb move to make mobiles solid but my monsters are....it keeps them spread out so aoe cant target too many at once, and it allows them to block in the main character, who in turn has a "push" variable to shove monsters out of the way at a variable speed.)

Edited by Piwaket, 03 May 2012 - 06:28 PM.

  • 0

#18 Ventwig

Ventwig

    GMC Member

  • New Member
  • 279 posts

Posted 03 May 2012 - 10:52 PM

I'm not sure how to solve your collision problems (i hate them), im only really a logic helper.

Anyways, if you want, just ask what part of what you dont understand and ill explain.
  • 0

#19 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 04 May 2012 - 02:29 AM

i worked out a solution!!
i did have to do a location check for spawning...but the solution to things getting stuck together was partly a problem with my order of operations and partially a problem with d&d and the way collisions work....

if anyone else besides me is dumb enough to have solid mobiles.... heres a fairly easy way to avoid them getting stuck on eachother and other solids.

i solved it by making a parent object for all solids, and in the "end step", AND in the "collision with" obj_solid_parent of all mobiles i used the script:

if place_meeting (x,y,obj_solid_parent) then {move_towards_point (other.x,other.y, - (var_obj_speed +1) ); alarm[0] = 1}

then set alarm[0] to restore normal movement of your object, for var_obj_speed put the speed variable for your object. you can also add the same script replacing obj_solid_parent with any non-solid or non parented obj you want your mobil to avoid clipping or sticking up in.
(i also added in the "collision with" event after the script... "bounce off solids" just for added insurance, though it would probably work without.)
anyway, im proud of myself for figuring that one out! ...three days later.... XD

Edited by Piwaket, 04 May 2012 - 05:24 AM.

  • 0

#20 Piwaket

Piwaket

    GMC Member

  • New Member
  • 49 posts
  • Version:GM8

Posted 04 May 2012 - 04:59 AM

i need to kno what the code is for "if a statement is true continue on with the next drag and drop"

and i also need to know how to get the id of the nearest object of a certain type....and how to use the id to change a variable.

heres my problem, my main char is supposed to have a keyboard function that if a monster is within range and you press the spacebar it should attack the nearest monster in range (all monsters have parent object "evil"). if there is a monster in range then i want to execute the next block of d&d actions, and then that brings me to the other issue which is then doing dammage to that same monster and setting an alarm on that monster(which is why i need the object id of the monster im hitting and need to know how to use that id to have that particular monster perform actions.)

so i need something like:

if distance to object_nearest(x,y,evil) < var_range, perform the next block of actions.

and another code:

subtract self.damage from other.hp of object_nearest(x,y,evil), change alarm[1] of object_nearest(x,y,evil) to 60, change other.drawdamage of object_nearest(x,y,evil) to true.

i know what im trying to say i just dont know how to say it in gml code... :D help anyone?

Solved Edit: yup, syntax errors due to not knowing how to code in gml but i learned alot in the process. (instance_nearest(x,y,obj)).variable pretty basic if you know anything about gml i suppose, i just didnt understand how to use it right.

Edited by Piwaket, 04 May 2012 - 08:59 PM.

  • 0

#21 Lemon Pie

Lemon Pie

    GMC Member

  • GMC Member
  • 194 posts

Posted 04 May 2012 - 05:20 AM

i need to kno what the code is for "if a statement is true continue on with the next drag and drop"

and i also need to know how to get the id of the nearest object of a certain type....and how to use the id to change a variable.

ive tried "object_nearest(x,y,obj_name)" and i guess thats supposed to do something but i just dont understand code enough to use it i guess....

heres my problem, my main char is supposed to have a keyboard function that if a monster is within range and you press the spacebar it should attack the nearest monster in range (all monsters have parent object "evil"). if there is a monster in range then i want to execute the next block of d&d actions, and then that brings me to the other issue which is then doing dammage to that same monster and setting an alarm on that monster(which is why i need the object id of the monster im hitting and need to know how to use that id to have that particular monster perform actions.)

so i need something like:

if distance to object_nearest(x,y,evil) < var_range, perform the next block of actions.

and another code:

change hp of object_nearest(x,y,evil), change alarm[0] of object_nearest(x,y,evil)

i just dont know the proper syntax. help anyone?

e = instance_nearest(x,y,evil);
if distance_to_point(x,y,e.x,e.y) < var_range
{
    e.hp -=1
    e.alarm[0] = 10
}

  • 0

#22 Ventwig

Ventwig

    GMC Member

  • New Member
  • 279 posts

Posted 04 May 2012 - 07:50 PM

The "test expression" D&D works :GM060:
just dont write if

Uhhh, try

target = instance_nearest(x,y,evil)
if distance_to_object(target) < 100

To put this in D&D
:GM072: target = instance_nearest(x,y,evil)
:GM060: distance_to_object(target) < 100
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users