Xer0botXer0
Senpai
Keeping this on hold, have other minor problems to solve first. Basically breaking the problems down one by one.
Hi fellow game devs,
I've got quite a problem, it's a barrier I can't over come on my own.
A player logs in and returns to the room they were at previous (i think) and then say another player logs in and is in that room then an instance is created for that player on this players client and you can see him, but you cant see movement. and when i leave the area and return then they vanish.
CLIENT:
Hi fellow game devs,
I've got quite a problem, it's a barrier I can't over come on my own.
A player logs in and returns to the room they were at previous (i think) and then say another player logs in and is in that room then an instance is created for that player on this players client and you can see him, but you cant see movement. and when i leave the area and return then they vanish.
CLIENT:
SERVER:Code:obj_player_other //no code in this object
Code:obj_play //as soon as obj_play is created, the player data is received & loaded from server
obj_play Create Event
Code:///Handle active other player instances for (i = 0; i < 10; i ++) { global.arr_other_player_information[i,0] = "" //username global.arr_other_player_information[i,1] = -1 //Instance id global.arr_other_player_information[i,2] = -1 //room x global.arr_other_player_information[i,3] = -1 //room y global.arr_other_player_information[i,4] = -1 //x pos global.arr_other_player_information[i,5] = -1 //y pos global.arr_other_player_information[i,9] = -1 //loaded or not //Add more for direction, sprite set.. etc }
obj_play Step Event
Code:///Create other players if not already created for (i = 0; i < array_height_2d(global.arr_other_player_information); i ++) { if global.arr_other_player_information[i,0] != "" //If the other_player slot is not empty { if global.arr_other_player_information[i,9] == -1 //if the other_player slot is not empty, and the other_player slot is not already in an instance { //create other_player instance and set x/y pos other_x = global.arr_other_player_information[i,4] other_y = global.arr_other_player_information[i,5] other_player = instance_create(other_x,other_y,obj_player_other) //Assign other_player player information other_player.my_username = global.arr_other_player_information[i,0] // sprite information etc //Set other_player slot as active global.arr_other_player_information[i,9] = 1; other_player = -1; //reset } } }
obj_play Networking
Code:case 15: ///Receive other player Instance information for (qu = 0; qu < 10; qu ++) { if global.arr_other_player_information[qu,0] == "" //Look for empty slot { ///Populate other player slot with other player information global.arr_other_player_information[qu,0] = buffer_read(buffer,buffer_string) //username global.arr_other_player_information[qu,1] = -1 //Instance id (use to store instance id upon creation, to use after) global.arr_other_player_information[qu,2] = buffer_read(buffer,buffer_u8) //room x global.arr_other_player_information[qu,3] = buffer_read(buffer,buffer_u8) //room y global.arr_other_player_information[qu,4] = buffer_read(buffer,buffer_u16) //x pos global.arr_other_player_information[qu,5] = buffer_read(buffer,buffer_u16) //y pos qu = 11 } } break;
obj_player_self
Code:///Update :: Other Player Instances buffer_seek( global.Buffer , buffer_seek_start , 0 ); buffer_write( global.Buffer , buffer_u8 , 15); //case 15 is request from server other player information if they're in the same room as this client var Result = network_send_packet( global.Socket , global.Buffer , buffer_tell( global.Buffer ) );
I broke the code up into client/server and then the scripts into code blocks within quotes for specific events, all the code is relevant to my conundrum!obj_server networking event:
Code:case 15: //See other players (client awareness of other players entering zone, and updating of other players in zone) ///1 - FIND CURRENT SOCKET|PLAYER ARRAY INFORMATION var which_room_player = "" ///Find the current player in arr_player_info for (c16_0 = 0; c16_0 < array_height_2d(arr_player_information); c16_0 ++) { if arr_player_information[c16_0,1] == socket { //player found var c16_0_1 = c16_0 var c16_0_2 = string(arr_player_information[c16_0_1,4]) //converting these to string var c16_0_3 = string(arr_player_information[c16_0_1,5]) var which_room = c16_0_2 + "," + c16_0_3 //room player is in found which_room_player = which_room } } ///2 - LOOP THROUGH LIST OF PLAYERS, LOOK AT ROOM X/Y POSITION PROPERTIES, COMPARE TO TARGET SOCKET PLAYER X/Y. for (ot = 0; ot < array_height_2d(arr_player_information); ot ++) { var rm_x_pos = string(arr_player_information[ot,4]) //get room x pos var rm_y_pos = string(arr_player_information[ot,5]) //get room y pos var w_room = rm_x_pos + "," + rm_y_pos //room player is in found var w_room_player = w_room //IS THAT PLAYER ONLINE [TOGGLE] ADD IF STATEMENT //and add ISONLINE PROPERTY to ARRAY. if w_room_player == which_room_player //If the other player room coordinates is the same as this players room coordinates .. { ///Find the current player array slot for (pug = 0; pug < array_height_2d(arr_player_information); pug ++) { if arr_player_information[pug,1] == socket { target_sock_username = arr_player_information[pug,0] pug = 999; //end loop } } if arr_player_information[ot,0] != target_sock_username //If target player data is not the same as the socket requesting it { //Send other player information to client. buffer_seek( Buffer, buffer_seek_start, 0) buffer_write(Buffer, buffer_u8, 15) // 15 - tell client the following data has other player information. buffer_write(Buffer, buffer_string, arr_player_information[ot,0]) //username buffer_write(Buffer, buffer_u8, arr_player_information[ot,4]) //room x pos buffer_write(Buffer, buffer_u8, arr_player_information[ot,5]) //room y pos buffer_write(Buffer, buffer_u16, arr_player_information[ot,2]) //xpos buffer_write(Buffer, buffer_u16, arr_player_information[ot,3]) //ypos network_send_packet( socket , Buffer , buffer_tell( Buffer ) ); } } } break;
Last edited: