SalTheThief
Member
I’ve been following Shaun Spalding’s ARPG tutorial for my own splitscreen multiplayer game and am having trouble getting the dialogue system to scale with multiple players. Currently I have it working, but it will only display dialogue to one player (obj_player). My goal is to have it so that all four players(obj_player,obj_player2,obj_player3, and obj_player3) can be interacting with the same NPC at their own pace. Here is the relevant code:
NewTextBox script
This is the PlayerStateFree script which allows an obj_player object to interact with an NPC
And here is the code present inside of the instance itself. This is where I call the NewTextBox script and provide the dialogue to run through it.
My thought process was to create an obj_text and obj_textqueued, which are responsible for drawing the text, for each player. This would allow me to enter the coordinates for each player's screen. I think this would work well but I'm not sure how to get the NPC instance to know which player it is talking to.
EDIT: I figured this one out on my own. In the NewTextBox script there is a variable called originInstance that tracks the id of whoever is talking to the NPC. Using this I'll be able to have an if statement that will react according to which player started the dialogue.
NewTextBox script
GML:
/// @arg Message
/// @arg Background
/// @arg [Responses]
function NewTextBox(){
var _obj;
//The following line checks for an obj_text object.
//If it exists, it will throw additional dialogue lines into obj_textqueued
if (instance_exists(obj_text)) _obj = obj_textqueued; else _obj = obj_text;
with (instance_create_layer(0,0,"Instances",_obj))
{
//The dialogue goes into messageText
messageText = argument[0]
if (instance_exists(other)) originInstance = other.id else originInstance = noone;
//background determines the color of the window text
if (argument_count > 1) background = argument[1]; else background = 1;
if (argument_count > 2)
{
//Trim markers from responses
responses = argument[2];
for (var i = 0; i < array_length(responses); i++)
{
var _markerPosition = string_pos(":",responses[i]);
//responseScripts is a switch case for scripts to execute after dialogue has happened
responseScripts[i] = string_copy(responses[i],1,_markerPosition-1);
responseScripts[i] = real(responseScripts[i]);
responses[i] = string_delete(responses[i],1,_markerPosition);
}
}
else
{
responses = [-1];
responseScripts = [-1];
}
}
//Capture the current player state and pause them until the dialogue ends
with (obj_player)
{
if (state != PlayerStateLocked)
{
lastState = state;
state = PlayerStateLocked;
}
}
}
This is the PlayerStateFree script which allows an obj_player object to interact with an NPC
GML:
function PlayerStateFree(){
//Movement
hSpeed = lengthdir_x(inputMagnitude * speedMove, inputDirection);
vSpeed = lengthdir_y(inputMagnitude * speedMove, inputDirection);
PlayerCollision();
//Update Sprite Index
var _oldSprite = sprite_index;
if (inputMagnitude != 0)
{
direction = inputDirection;
sprite_index = spriteMove;
} else sprite_index = spriteIdle;
if (_oldSprite != sprite_index) localFrame = 0;
//Update Image Index
PlayerAnimateSprite();
//Attack key logic
if (keyAttack)
{
//1. Check for an entity to activate
//2. If there is nothing, or there is something, but it has no script - attack!
//3. Otherwise, there is something, and it has a script, activate
//4. If ther thing we activate is an NPC, make it face towards us
var _activateX = lengthdir_x(32, direction);
var _activateY = lengthdir_y(32, direction);
activate = instance_position(x+_activateX, y+_activateY, pEntity);
if (activate == noone || activate.entityActivateScript == -1)
{
state = PlayerStateAttack;
stateAttack = SorcAttack;
}
else
{
//Activate the entity
script_execute_ext(activate.entityActivateScript, activate.entityActivateArgs);
//Make an NPC face the player
if (activate.entityNPC)
{
with (activate)
{
direction = point_direction(x,y,other.x,other.y);
image_index = CARDINAL_DIR;
}
}
}
}
}
My thought process was to create an obj_text and obj_textqueued, which are responsible for drawing the text, for each player. This would allow me to enter the coordinates for each player's screen. I think this would work well but I'm not sure how to get the NPC instance to know which player it is talking to.
EDIT: I figured this one out on my own. In the NewTextBox script there is a variable called originInstance that tracks the id of whoever is talking to the NPC. Using this I'll be able to have an if statement that will react according to which player started the dialogue.
Last edited: