Skip to content

Instantly share code, notes, and snippets.

@nomisum
Created March 8, 2023 20:10
Show Gist options
  • Save nomisum/cb5516625bff68194eb092fd4e64fed5 to your computer and use it in GitHub Desktop.
Save nomisum/cb5516625bff68194eb092fd4e64fed5 to your computer and use it in GitHub Desktop.
class WITA_MapLocator_Class: SCR_MapLocator
{
// user script
// code here
override void EOnInit(IEntity owner)
{
if (!GetGame().InPlayMode() || !m_WorldDirections)
return;
// SCR_MapEntity.GetOnMapOpen().Insert(ShowMapHint);
// SCR_MapEntity.GetOnMapClose().Insert(HideMapHint);
vector mins,maxs;
GetGame().GetWorldEntity().GetWorldBounds(mins, maxs);
m_iGridSizeX = maxs[0]/3;
m_iGridSizeY = maxs[2]/3;
IEntity m_gameMode = GetGame().FindEntity("gameModeEnt");
if(!m_gameMode)
return;
SCR_RespawnSystemComponent respComp = SCR_RespawnSystemComponent.Cast(m_gameMode.FindComponent(SCR_RespawnSystemComponent));
if (!respComp)
return;
bool isServer = true;
RplComponent rplComponent = RplComponent.Cast(m_gameMode.FindComponent(RplComponent));
if (rplComponent && !rplComponent.IsMaster())
isServer = false;
if (!isServer)
return;
GetGame().GetCallqueue().CallLater(checkForAgentPosition, 60000, true, respComp)
// proto void CallLater(func fn, int delay = 0, bool repeat = false, void param1 = NULL, void param2 = NULL, void param3 = NULL, void param4 = NULL, void param5 = NULL, void param6 = NULL, void param7 = NULL, void param8 = NULL, void param9 = NULL);
}
protected void checkForAgentPosition(SCR_RespawnSystemComponent respComp) {
Print("checkForAgentPosition");
array<int> players = {};
GetGame().GetPlayerManager().GetPlayers(players);
Faction factionFIA = GetGame().GetFactionManager().GetFactionByKey("FIA");
if (!factionFIA)
return;
if ((players.Count()) < 1)
return;
foreach (int player : players)
{
// Print("Group Member checking");
// Faction factionPlayer = GetGame().GetFactionManager().GetFactionByIndex(player);
// not sure if necessary
if (!player)
return;
Faction factionPlayer = respComp.GetPlayerFaction(player);
if (!factionPlayer)
return;
Print(factionPlayer.GetFactionName());
Print(factionFIA.GetFactionName());
if (factionPlayer == factionFIA) {
IEntity playerEnt = GetGame().GetPlayerManager().GetPlayerControlledEntity(player);
CalculateClosestLocation(playerEnt);
}
}
}
[RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
protected void RpcDo_maplocatorShowHint (string closestLocationName, vector agentPosition) {
SCR_HintManagerComponent hintComponent = SCR_HintManagerComponent.GetInstance();
hintComponent.ShowCustomHint("Near " + closestLocationName, "Agent Location", 20);
SCR_ParticleEmitter fxEffect = SCR_ParticleEmitter.CreateEx(SCR_ParticleEmitterClass, "{7B4A41DA320475FF}Smoke.ptc", agentPosition);
}
protected void callRpcWorkaround (string closestLocationName, vector posPlayer) {
Rpc(RpcDo_maplocatorShowHint, closestLocationName, posPlayer)
}
protected void CalculateClosestLocation(IEntity playerEnt)
{
if (!playerEnt)
{
if (m_wUIHintLayout)
{
m_wUIHintLayout.RemoveFromHierarchy();
m_wUIHintLayout = null;
}
return;
}
SCR_EditableEntityCore core = SCR_EditableEntityCore.Cast(SCR_EditableEntityCore.GetInstance(SCR_EditableEntityCore));
if (!core)
return;
vector posPlayer = playerEnt.GetOrigin();
Print(posPlayer);
SCR_EditableEntityComponent nearest = core.FindNearestEntity(posPlayer, EEditableEntityType.COMMENT, EEditableEntityFlag.LOCAL);
if (!nearest)
return;
GenericEntity nearestLocation = nearest.GetOwner();
SCR_MapDescriptorComponent mapDescr = SCR_MapDescriptorComponent.Cast(nearestLocation.FindComponent(SCR_MapDescriptorComponent));
string closestLocationName;
if (!mapDescr)
return;
MapItem item = mapDescr.Item();
closestLocationName = item.GetDisplayName();
vector lastLocationPos = nearestLocation.GetOrigin();
float lastDistance = vector.DistanceSqXZ(lastLocationPos, posPlayer);
LocalizedString closeLocationAzimuth;
vector result = posPlayer - lastLocationPos;
result.Normalize();
float angle1 = vector.DotXZ(result,vector.Forward);
float angle2 = vector.DotXZ(result,vector.Right);
if (angle2 > 0)
{
if (angle1 >= angleA)
closeLocationAzimuth = "#AR-MapLocationHint_DirectionNorth";
if (angle1 < angleA && angle1 >= angleB )
closeLocationAzimuth = "#AR-MapLocationHint_DirectionNorthEast";
if (angle1 < angleB && angle1 >=-angleB)
closeLocationAzimuth = "#AR-MapLocationHint_DirectionEast";
if (angle1 < -angleB && angle1 >=-angleA)
closeLocationAzimuth = "#AR-MapLocationHint_DirectionSouthEast";
if (angle1 < -angleA)
closeLocationAzimuth = "#AR-MapLocationHint_DirectionSouth";
}
else
{
if (angle1 >= angleA)
closeLocationAzimuth = "#AR-MapLocationHint_DirectionNorth";
if (angle1 < angleA && angle1 >= angleB )
closeLocationAzimuth = "#AR-MapLocationHint_DirectionNorthWest";
if (angle1 < angleB && angle1 >=-angleB)
closeLocationAzimuth = "#AR-MapLocationHint_DirectionWest";
if (angle1 < -angleB && angle1 >=-angleA)
closeLocationAzimuth = "#AR-MapLocationHint_DirectionSouthWest";
if (angle1 < -angleA)
closeLocationAzimuth = "#AR-MapLocationHint_DirectionSouth";
};
int playerGridPositionX = posPlayer[0]/m_iGridSizeX;
int playerGridPositionY = posPlayer[2]/m_iGridSizeY;
int playerGridID = GetGridIndex(playerGridPositionX,playerGridPositionY);
if (lastDistance < 40000) {
// todo add logic to differentiate here
// Rpc(RpcDo_maplocatorShowHint, closestLocationName, posPlayer)
GetGame().GetCallqueue().Call(callRpcWorkaround, closestLocationName, posPlayer);
Print("sending shit");
} else
{
GetGame().GetCallqueue().Call(callRpcWorkaround, closestLocationName, posPlayer);
Print("sending shit 2");
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment