Jump to content


Photo

39dll Enemy Help


  • This topic is locked This topic is locked
6 replies to this topic

#1 l1ttledand

l1ttledand

    GMC Member

  • GMC Member
  • 61 posts
  • Version:GM8

Posted 28 January 2012 - 04:47 AM

Hello! I have been working with 39dll and I've come to the point in my game where I would like to add Enemies and NPC's. I have been trying to figure this out myself for quite a while (trying to keep myself from asking on the forums) but have had no luck. I searched around the forums looking for good information about creating Enemies for a 39dll game. I found several topics that dealt with the same issue i'm having but they were incomplete and for the most part useless lol. I have figured out a few things but still need help. I'm using Blaxun's 39dll example as the base for my game but i've obviously changed and added a lot. I know that you have to give each enemy object its own id and have that sent to the server and back.. I'm just not sure how to get this to work correctly. I would love it if somebody could put an end to my misery and help me out with some sort of step by step method!! :happy:

Here's what I have as of right now (I know its wrong but I just wanted to give an idea of what help I need and the type of format I would like a response to be in so its easy for me to understand!!! haha :blink: )

Thank you in advance to anybody who can help me! I hope this topic doesn't go unsolved because I'm sure there are others out there who have the same problem I do!! :rolleyes:


EDIT: The old code above that obviously does not work is not in the equation anymore and has been removed. This is what I have now.
What it does is creates an enemy in the right spot when the player logs into the room where the enemy is. The problem is.. if the player logs into the room where it is not, it creates a still moving enemy at the coordinates..very strange...i dont want this.. anyway here I go..

Client
obj_player Step Event:
if (player_room != room){ // if the cur sprite doesnt equal the orig sprite
roomchange = 1
player_room = room;
}

if roomchange = 1{
alarm[3] = 1 // sets an alarm to make the sprite change to reduce lagg
roomchange = 0
}

obj_player Alarm[3]:
clearbuffer()
writebyte(MSG_ENEMY)
send_server()

roomchange = 0

Server
case_msg_enemy()
if(!instance_exists(obj_monster)){//if theres not one...
instance_create(x,y,obj_monster)//create a obj_monster server side
}else
if (instance_exists(obj_monster)){
with(obj_monster){
if(obj_player.cur_room = cur_room){
clearbuffer();
writebyte(MSG_ENEMY);
writebyte(1);
writeushort(x);
writeushort(y);
writeushort(monster_id);
writeushort(dir);
writeushort(cur_room);
send_client('room',cur_room);
}
}}

obj_monster Create Event:
monster_id=global.monster;//Set it an unique monster id to that monster
global.monster+=1;//Add 1 to global.monster so the next monster won't have the same monster_id
//Now were ready to send the monster's data

x = 50
y = 50
dir = 50
cur_room = 0
go = 0

clearbuffer();
writebyte(MSG_ENEMY);
writebyte(1);
writeushort(x);
writeushort(y);
writeushort(monster_id);
writeushort(dir);
writeushort(cur_room);
send_client('room',cur_room);
alarm[0] = 90

Alarm[0]:
//move_towards_point(x+10,y,1)
x+=30

clearbuffer();
writebyte(MSG_ENEMY);
writebyte(2);//Tell's the client we want to execute The Set New X,Y,Dir
writeushort(monster_id);
writeushort(x);
writeushort(y);
writeushort(dir);
send_client('room',cur_room);
alarm[1] = 90

Alarm[1]:
//move_towards_point(x-10,y,1)
x-=30
clearbuffer();
writebyte(MSG_ENEMY);
writebyte(2);//Tell's the client we want to execute The Set New X,Y,Dir
writeushort(monster_id);
writeushort(x);
writeushort(y);
writeushort(dir);
send_client('room',cur_room);
alarm[0] = 90

Client
case_msg_enemy()
switch readbyte()
{
//Creates Monster
case 1:
xx = readushort()
yy = readushort()
monsterid = readushort()
dir = readushort()
cur_room = readushort()

if(xx != 0 && yy != 0){
i=instance_create(xx,yy,obj_enemy);
i.monster_id=monsterid;//Takes the id from the server
i.direction=dir;//Set The Direction of the monster
i.cur_room = readushort()
}
break;
//Sets new x,y and dir to the monster
case 2:
monster_id=readushort();
with obj_enemy{
if monster_id=other.monster_id{
x=readushort();
y=readushort();
direction=readushort();
}
}
break;
}

Edited by l1ttledand, 07 February 2012 - 12:14 AM.

  • 0

#2 Turbine

Turbine

    GMC Member

  • New Member
  • 18 posts
  • Version:GM7

Posted 31 January 2012 - 11:09 PM

Not a good method for enemy, but what you've written makes no sense. If it's written like so, then you might want to redo the structure of the networking.
  • 0

#3 l1ttledand

l1ttledand

    GMC Member

  • GMC Member
  • 61 posts
  • Version:GM8

Posted 31 January 2012 - 11:13 PM

I'm aware that whats written makes absolutely no sense, Im asking for help because i have no idea how to set this up. Can you help me?
  • 0

#4 orange451

orange451

    GMC Member

  • GMC Member
  • 1097 posts
  • Version:GM8.1

Posted 01 February 2012 - 01:18 PM

I'm aware that whats written makes absolutely no sense, Im asking for help because i have no idea how to set this up. Can you help me?



I think you should read about how buffers work, and how they are used w/ 39dll.
You keep reading information from the buffer while looping through your enemy objects. Setting all their information to that which was just received from the server.
  • 0

#5 l1ttledand

l1ttledand

    GMC Member

  • GMC Member
  • 61 posts
  • Version:GM8

Posted 02 February 2012 - 05:39 AM

I think you should read about how buffers work, and how they are used w/ 39dll.
You keep reading information from the buffer while looping through your enemy objects. Setting all their information to that which was just received from the server.


I'm sorry, I dont understand what youre asking me to do.. I understand that my code is completely wrong, ignore the code above. I just need help on how to do this!! Okay like i said, i know you have to store the enemies id's server side.. How would I do this? And how would the code look?

Client:
obj_enemy sent in Create Event & When It Moves:
clearbuffer()
writebyte(MSG_ENEMY)
writeshort(x)//x coord
writeshort(y)//y coord
writeshort(dir)//direction
send_server()

That sends the enemies variables, x,y,direction okay. Now Server Side, I'm gonna read the variables, send them back to the client and put those variables in the correct enemy object so everything's the same on all clients..right? no? ..now I have to let the clients know which enemy object gets which variables.. so i do this by having a certain id stored server side for each enemy..and then having the server send the id and the coordinates to the clients so it knows where each set of variables go to.... right?.. If i'm wrong, tell me, I really need help on this.. If i'm right, how can I do what I said?? ughh :wacko:

Edited by l1ttledand, 04 February 2012 - 05:55 AM.

  • 0

#6 iPodClassic

iPodClassic

    GMC Member

  • GMC Member
  • 277 posts
  • Version:GM:Studio

Posted 04 February 2012 - 05:52 AM

writeushort at the very first script. Use writeshort instead.
  • 0

#7 l1ttledand

l1ttledand

    GMC Member

  • GMC Member
  • 61 posts
  • Version:GM8

Posted 04 February 2012 - 05:57 AM

writeushort at the very first script. Use writeshort instead.

lmao thanks.. That's the most productive thing that somebody's replied with so far! haha :rolleyes: I knew that though, just made the mistake throwing this dumb piece of codes together to have something to show. I really need help on this though .. :sad:

Edit: Is that little error what the two above were referring to? lol ughhh I know a lot more than that .... :skull:

Edited by l1ttledand, 04 February 2012 - 06:01 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users