Skip to content

Commit 42ad23a

Browse files
authored
Bugfix/tp2squadmate locality issues (#26)
* renamed layout to reflect what it is * moved to rpc from local GM to server for teleporting other players * fixed review comments, moved static emptyTerrainAreaRadius and removed unnessecary function * added prefix to static variable
1 parent 4f2df21 commit 42ad23a

File tree

7 files changed

+93
-33
lines changed

7 files changed

+93
-33
lines changed

Configs/Editor/ActionLists/Context/TempEdit.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ SCR_EditorActionList {
99
m_iOrder 200
1010
m_bEnableShortcutLogics 0
1111
m_bShowOnCooldownNotification 0
12-
m_bIsServer 1
1312
}
1413
}
1514
}

Configs/System/chimeraMenus.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MenuManager {
22
MenuPresets {
3-
MenuPreset ODIN_ListBox_ID {
4-
Layout "{73A9C9284FFE3376}UI/layouts/ODIN_ListBox.layout"
3+
MenuPreset ODIN_Listbox_SingleSelect_ID {
4+
Layout "{73A9C9284FFE3376}UI/layouts/ODIN_ListBox_SingleSelect.layout"
55
Class "ODIN_ListboxSingleSelectDialog"
66
}
77
}

Scripts/Game/ODIN/Editor/Containers/Actions/ContextActions/ODIN_TeleportToSquadmateContextAction.c

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//------------------------------------------------------------------------------------------------
22
[BaseContainerProps(), SCR_BaseContainerCustomTitleUIInfo("m_Info")]
33
class ODIN_TeleportToSquadmateContextAction: SCR_BaseContextAction
4-
{
5-
static int emptyTerrainAreaRadius = 20;
6-
4+
{
75
override bool CanBeShown(SCR_EditableEntityComponent hoveredEntity, notnull set<SCR_EditableEntityComponent> selectedEntities, vector cursorWorldPosition, int flags)
86
{
97
if (!hoveredEntity)
@@ -32,7 +30,7 @@ class ODIN_TeleportToSquadmateContextAction: SCR_BaseContextAction
3230

3331
GenericEntity owner = hoveredEntity.GetOwner();
3432

35-
MenuBase myMenu = GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.ODIN_ListBox_ID, DialogPriority.INFORMATIVE, 0, true);
33+
MenuBase myMenu = GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.ODIN_Listbox_SingleSelect_ID, DialogPriority.INFORMATIVE, 0, true);
3634

3735
// null check
3836
if (!myMenu)
@@ -105,35 +103,19 @@ class ODIN_TeleportToSquadmateContextAction: SCR_BaseContextAction
105103
ODIN_LogHelper.Log("ChimeraCharacter in userdata for selected listbox item is null", "TeleportToSquadmateContextAction", LogLevel.WARNING);
106104
return;
107105
}
108-
109-
// If target is sitting in a vehicle, move player inside as well (Taken from SCR_PlayerSpawnPoint.c)
110-
SCR_CompartmentAccessComponent compartmentAccessTarget = SCR_CompartmentAccessComponent.Cast(selectedPlayer.FindComponent(SCR_CompartmentAccessComponent));
111-
IEntity vehicle = compartmentAccessTarget.GetVehicle();
112-
if (vehicle)
113-
{
114-
SCR_CompartmentAccessComponent compartmentAccessPlayer = SCR_CompartmentAccessComponent.Cast(hoveredEntity.GetOwner().FindComponent(SCR_CompartmentAccessComponent));
115-
116-
// only return here if we were succesfull in moving into vehicle. If false its likely vehicle is full; Then we continue function to move unit right next to vehicle
117-
if (compartmentAccessPlayer.MoveInVehicleAny(vehicle))
118-
return;
119-
}
120106

121-
// Get world coordinates of player
122-
vector target_pos;
123-
SCR_WorldTools.FindEmptyTerrainPosition(target_pos, selectedPlayer.GetOrigin(), emptyTerrainAreaRadius);
124-
125-
// get transform for rotation etc.
126-
vector target_transform[4];
127-
hoveredEntity.GetTransform(target_transform);
128-
129-
// use new position, but keep rotation
130-
target_transform[3] = target_pos;
131-
132-
hoveredEntity.SetTransform(target_transform, true);
107+
// get target player RplId
108+
RplComponent targetRpl = RplComponent.Cast(selectedPlayer.FindComponent(RplComponent));
109+
if (!targetRpl)
110+
return;
111+
112+
// Call RPC through EditorManagerEntity to reach server
113+
SCR_EditorManagerEntity managerEntity = SCR_EditorManagerEntity.GetInstance();
114+
managerEntity.ODIN_TeleportEntityToPlayer(hoveredEntity.GetOwnerRplId(), targetRpl.Id());
133115
}
134116

135117
override bool IsServer()
136118
{
137-
return true;
119+
return false;
138120
}
139121
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/** @ingroup Editor_Entities
2+
*/
3+
4+
/*!
5+
The entity which enables all editor functionality for the player.
6+
7+
- It's **created by SCR_EditorManagerCore** when a player connects.
8+
+ Every player receives one.
9+
- In multiplayer, the entity is **local to the player**.
10+
+ This is required to allow communication with server (see Replication for more details).
11+
+ Requires RplComonent to function.
12+
- This entity handles **only barebone editor functionality**, like access rules, or opening and closing.
13+
- Everything else, like camera or menu handling, must be on specialized editor modes (SCR_EditorModeEntity) and components (SCR_BaseEditorComponent)!
14+
- Editor can have a limitied state, influenced by its modes and checked by IsLimited() function:
15+
+ Editor is **limited** if all its modes are.
16+
+ If at least one mode is unlimited, the editor is **unlimited** as well.
17+
+ The state influences behavior of certain components, e.g., photo mode camera movement may be restricted if the editor is limited.
18+
+ As a rule of thumb, unlimited state means that player can ***cheat*** with the editor.
19+
- Default editor manager prefab is defined in SCR_EditorManagerCore (config is Configs/Core folder).
20+
*/
21+
modded class SCR_EditorManagerEntity : SCR_EditorBaseEntity
22+
{
23+
static int ODIN_emptyTerrainAreaRadius = 20;
24+
25+
/*!
26+
Functions to tell the server to move an entity
27+
*/
28+
void ODIN_TeleportEntityToPlayer(RplId sourceEntityId, RplId targetEntityId)
29+
{
30+
Rpc(ODIN_Server_TeleportEntityToPlayer, sourceEntityId, targetEntityId);
31+
}
32+
33+
[RplRpc(RplChannel.Reliable, RplRcver.Server)]
34+
protected void ODIN_Server_TeleportEntityToPlayer(RplId entityId, RplId targetEntityId)
35+
{
36+
// get entity from id
37+
RplComponent entityRpl = RplComponent.Cast(Replication.FindItem(entityId));
38+
RplComponent targetRpl = RplComponent.Cast(Replication.FindItem(targetEntityId));
39+
40+
if (!entityRpl || !targetRpl)
41+
return;
42+
43+
IEntity sourceEntity = entityRpl.GetEntity();
44+
IEntity targetEntity = targetRpl.GetEntity();
45+
46+
if (!sourceEntity || !targetEntity)
47+
return;
48+
49+
// If target is sitting in a vehicle, move player inside as well (Taken from SCR_PlayerSpawnPoint.c)
50+
SCR_CompartmentAccessComponent compartmentAccessTarget = SCR_CompartmentAccessComponent.Cast(targetEntity.FindComponent(SCR_CompartmentAccessComponent));
51+
IEntity vehicle = compartmentAccessTarget.GetVehicle();
52+
if (vehicle)
53+
{
54+
SCR_CompartmentAccessComponent compartmentAccessPlayer = SCR_CompartmentAccessComponent.Cast(sourceEntity.FindComponent(SCR_CompartmentAccessComponent));
55+
56+
// if we succeed, we return to avoid teleporting the unit after having moved him into the vehicle. If we fail, we just continue and TP player next to vehicle
57+
if (compartmentAccessPlayer.MoveInVehicleAny(vehicle))
58+
return;
59+
}
60+
61+
// Get world coordinates of player
62+
vector target_pos;
63+
SCR_WorldTools.FindEmptyTerrainPosition(target_pos, targetEntity.GetOrigin(), ODIN_emptyTerrainAreaRadius);
64+
65+
// get transform for rotation etc.
66+
vector target_transform[4];
67+
sourceEntity.GetTransform(target_transform);
68+
69+
// use new position, but keep rotation
70+
target_transform[3] = target_pos;
71+
72+
// Get editable component
73+
SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(sourceEntity.FindComponent(SCR_EditableEntityComponent));
74+
75+
// call transform
76+
if (editableEntity)
77+
editableEntity.SetTransform(target_transform, true);
78+
}
79+
};

Scripts/Game/ODIN/UI/Menu/ChimeraMenuBase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
//! Menu presets
33
modded enum ChimeraMenuPreset
44
{
5-
ODIN_ListBox_ID,
5+
ODIN_Listbox_SingleSelect_ID,
66
};
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)