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!!
![]()
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)
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!!
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] = 90Alarm[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] = 90Alarm[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] = 90Client
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.



This topic is locked







