Here are my scripts. I couldn’t upload a pic for some reason, but the error message appears in the console when I go into build mode.
local characterMovement =
{
Properties =
{
cam_z = {default = EntityId()},
cam_y = {default = EntityId()},
survivalHud = {default = EntityId()},
buildMode = {default = EntityId()},
}
}
function characterMovement:OnActivate()
self.incomingDataId = GameplayNotificationId(self.entityId, “messageData”, “float”);–message receiver
self.incomingDataBus = GameplayNotificationBus.Connect(self, self.incomingDataId);
inWater = false;
pi = 3.14159265359;
self.tickBusHandler = TickBus.Connect(self);
self.inventoryBusId = InputEventNotificationId(“inventory”);
self.inventoryBus = InputEventNotificationBus.Connect(self, self.inventoryBusId);
self.fbBusId = InputEventNotificationId(“fb”);
self.fbBus = InputEventNotificationBus.Connect(self, self.fbBusId);
self.lrBusId = InputEventNotificationId(“lr”);
self.lrBus = InputEventNotificationBus.Connect(self, self.lrBusId);
self.mouse_x_bus_id = InputEventNotificationId(“mouse_x”);
self.mouse_x_bus = InputEventNotificationBus.Connect(self, self.mouse_x_bus_id);
self.mouse_y_bus_id = InputEventNotificationId(“mouse_y”);
self.mouse_y_bus = InputEventNotificationBus.Connect(self, self.mouse_y_bus_id);
self.jump_bus_id = InputEventNotificationId(“jump”);
self.jump_bus = InputEventNotificationBus.Connect(self, self.jump_bus_id);
self.rollBusId = InputEventNotificationId(“roll”);
self.rollBus = InputEventNotificationBus.Connect(self, self.rollBusId);
self.fightBusId = InputEventNotificationId(“fight”);
self.fightBus = InputEventNotificationBus.Connect(self, self.fightBusId);
self.bBusId = InputEventNotificationId(“b”);
self.bBus = InputEventNotificationBus.Connect(self, self.bBusId);
self.oneBusId = InputEventNotificationId(“1”);
self.oneBus = InputEventNotificationBus.Connect(self, self.oneBusId);
self.twoBusId = InputEventNotificationId(“2”);
self.twoBus = InputEventNotificationBus.Connect(self, self.twoBusId);
self.threeBusId = InputEventNotificationId(“3”);
self.threeBus = InputEventNotificationBus.Connect(self, self.threeBusId);
self.fourBusId = InputEventNotificationId(“4”);
self.fourBus = InputEventNotificationBus.Connect(self, self.fourBusId);
self.fiveBusId = InputEventNotificationId(“5”);
self.fiveBus = InputEventNotificationBus.Connect(self, self.fiveBusId);
self.sixBusId = InputEventNotificationId(“6”);
self.sixBus = InputEventNotificationBus.Connect(self, self.sixBusId);
self.sevenBusId = InputEventNotificationId(“7”);
self.sevenBus = InputEventNotificationBus.Connect(self, self.sevenBusId);
self.xBusId = InputEventNotificationId(“x”);
self.xBus = InputEventNotificationBus.Connect(self, self.xBusId);
self.yBusId = InputEventNotificationId(“y”);
self.yBus = InputEventNotificationBus.Connect(self, self.yBusId);
self.zBusId = InputEventNotificationId(“z”);
self.zBus = InputEventNotificationBus.Connect(self, self.zBusId);
is_jumping = false;
velocity = 1;
walking_bw = false;
is_moving = false;
roll = false;
fight = false;
in_air = false;
mouseSpeed = .002;
camZbottom = 1.2;
camZtop = 2;
isTreadingWater = false;
mouseCursor = false;
camZbottom = 1.2;
camZtop = 2;
isBuilding = false;
end
function characterMovement:OnDeactivate()
self.bBus:Disconnect()
self.fbBus:Disconnect()
self.lrBus:Disconnect()
self.jump_bus:Disconnect()
self.fightBus:Disconnect()
self.rollBus:Disconnect()
self.mouse_x_bus:Disconnect()
self.mouse_y_bus:Disconnect()
self.tickBusHandler:Disconnect()
self.incomingDataBus:Disconnect()
self.inventoryBus:Disconnect()
self.xBus:Disconnect()
self.yBus:Disconnect()
self.zBus:Disconnect()
self.fiveBus:Disconnect()
self.fourBus:Disconnect()
self.threeBus:Disconnect()
self.twoBus:Disconnect()
self.oneBus:Disconnect()
self.sixBus:Disconnect()
self.sevenBus:Disconnect()
end
function characterMovement:OnEventUpdating(incomingDataUpdating)
if incomingDataUpdating == 3 then
velocity = .5;
end
if incomingDataUpdating == 110 then
isBuilding = true;
end
end
function characterMovement:OnEventBegin(incomingDataBegin)–incoming
end
function characterMovement:OnEventEnd(incomingDataEnd)–incoming
if incomingDataEnd == 3 then
velocity = 1;
end
end
function characterMovement:OnHeld(floatValue)
local current_bus = InputEventNotificationBus.GetCurrentBusId()
if current_bus == self.fbBusId and inWater == true then
is_moving = true;
isSwimming = true;
isTreadingWater = false;
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “swimming”, floatValue);
end
if current_bus == self.fbBusId and
floatValue > 0 then
is_moving = true
walking_bw = false
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventUpdating(stamRegenId, 1)
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “speed”, 1 * velocity);
end
if current_bus == self.fbBusId and
floatValue < 0 then
is_moving = true
walking_bw = true
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “speed”, -.5);
end
if current_bus == self.lrBusId and
walking_bw == false then
is_moving = true
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventUpdating(stamRegenId, 1)
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “speed”, 1 * velocity);
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “direction”, floatValue);
end
if (current_bus == self.lrBusId)
and (walking_bw == true) then
is_moving = true
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “speed”, -.5);
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “direction”, -floatValue);
end
if ((is_moving == true) and (current_bus == self.mouse_x_bus_id)) then
TransformBus.Event.RotateAroundLocalZ(self.entityId, -floatValue * mouseSpeed);
end
if ((is_moving == false) and (current_bus == self.mouse_x_bus_id)) then
TransformBus.Event.RotateAroundLocalZ(self.Properties.cam_z, -floatValue * mouseSpeed);
end
if current_bus == self.mouse_y_bus_id then
TransformBus.Event.RotateAroundLocalX(self.Properties.cam_y, -floatValue * mouseSpeed);
end
if current_bus == self.fightBusId and mouseCursor == false and isBuilding == false then
AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “fight”, true)
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventUpdating(stamRegenId, 1)
end
end
function characterMovement:OnPressed(floatValue)
local current_bus = InputEventNotificationBus.GetCurrentBusId()
if current_bus == self.xBusId then
local buildRotXId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(buildRotXId, 130)
end
if current_bus == self.yBusId then
local buildRotYId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(buildRotYId, 131)
end
if current_bus == self.zBusId then
local buildRotZId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(buildRotZId, 132)
end
if current_bus == self.rollBusId then
local deleteBusId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(deleteBusId, 133)
end
if current_bus == self.fightBusId then
local spawnBusId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(spawnBusId, 134)
end
if current_bus == self.rollBusId and mouseCursor == false and isBuilding == false then
is_rolling = true
AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “roll”, true)
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(stamRegenId, 2)
end
if is_jumping == false and in_air == false and
current_bus == self.jump_bus_id and mouseCursor == false then
is_jumping = true
AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “jump”, true)
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(stamRegenId, 2)
end
if current_bus == self.bBusId and mouseCursor == false then–*************************************************************************************************************************************
local buildModeId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(buildModeId, 100)
end
if current_bus == self.inventoryBusId then
mouseCursor = not mouseCursor
end
if mouseCursor == true then
LyShineLua.ShowMouseCursor(true)
mouseSpeed = 0
local inventoryId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(inventoryId, 50)
– UiElementBus.Event.SetIsEnabled(inventory, true)
end
if mouseCursor == false then
LyShineLua.ShowMouseCursor(false)
mouseSpeed = .002
local inventoryId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventEnd(inventoryId, 50)
end
–building
if current_bus == self.oneBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 120)
mouseCursor = false
end
if current_bus == self.twoBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 121)
mouseCursor = false
end
if current_bus == self.threeBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 122)
mouseCursor = false
end
if current_bus == self.fourBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 123)
mouseCursor = false
end
if current_bus == self.fiveBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 124)
mouseCursor = false
end
if current_bus == self.sixBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 125)
mouseCursor = false
end
if current_bus == self.sevenBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 126)
mouseCursor = false
end
if current_bus == self.eightBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 127)
mouseCursor = false
end
if current_bus == self.nineBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 128)
mouseCursor = false
end
if current_bus == self.zeroBusId then
local currentItemId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 129)
mouseCursor = false
end
end
function characterMovement:OnReleased(floatValue)
local current_bus = InputEventNotificationBus.GetCurrentBusId()
is_jumping = false;
walking_bw = false;
if current_bus == self.fbBusId and inWater == true then
is_moving = false
isTreadingWater = true;
isSwimming = false;
TransformBus.Event.SetWorldZ(self.entityId, 13.1)
end
if current_bus == self.fbBusId then
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);
GameplayNotificationBus.Event.OnEventEnd(stamRegenId, 1)
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “speed”, floatValue);
is_moving = false;
end
if current_bus == self.lrBusId then
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);
GameplayNotificationBus.Event.OnEventEnd(stamRegenId, 1)
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “direction”, floatValue);
AnimGraphComponentRequestBus.Event.SetNamedParameterFloat(self.entityId, “speed”, 0);
is_moving = false;
end
if current_bus == self.rollBusId then
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);
GameplayNotificationBus.Event.OnEventEnd(stamRegenId, 1)
AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “roll”, false);
is_moving = false;
end
if current_bus == self.jump_bus_id then
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);
GameplayNotificationBus.Event.OnEventEnd(stamRegenId, 1)
AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “jump”, false);
is_moving = false;
is_jumping = false;
end
if current_bus == self.fightBusId then
local stamRegenId = GameplayNotificationId(self.Properties.survivalHud, “messageData”, “float”);
GameplayNotificationBus.Event.OnEventEnd(stamRegenId, 1)
– UiSliderBus.Event.SetValue(stamina, staminaCurrent - 10)
AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “fight”, false)
end
if current_bus == self.bBusId then–*************************************************************************************************************************************
local buildModeId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventEnd(buildModeId, 100)
end
end
function characterMovement:OnTick(deltaTime)
local depth = TransformBus.Event.GetWorldZ(self.entityId)
local current_bus = InputEventNotificationBus.GetCurrentBusId()
local cam_y_loc = TransformBus.Event.GetLocalY(self.Properties.cam_y)
local cam_z_rot = TransformBus.Event.GetLocalRotation(self.Properties.cam_z)
local player_rot = TransformBus.Event.GetLocalRotation(self.entityId)
local camZLoc = TransformBus.Event.GetLocalZ(self.Properties.cam_z)
if cam_y_loc > -1 then cam_y_loc = -1 – clamp
end
if cam_y_loc < -2 then cam_y_loc = -2 --clamp
end
if camZLoc > camZtop then camZLoc = camZtop
end
if camZLoc < camZbottom then camZLoc = camZbottom
end
–swimming
if depth < 13.5 then
AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “swimming”, true)
inWater = true
end
if depth > 13.5 then
AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “swimming”, false)
inWater = false;
isSwimming = false;
isTreadingWater = false;
TransformBus.Event.SetLocalY(self.Properties.cam_z, 0.0)
camZbottom = 1.2
end
local camZLoc = TransformBus.Event.GetLocalZ(self.Properties.cam_z)
if camZLoc > camZtop then camZLoc = camZtop
end
if camZLoc < camZbottom then camZLoc = camZbottom
end
if isSwimming == true then
TransformBus.Event.SetLocalZ(self.Properties.cam_z, camZLoc - .02)
TransformBus.Event.SetLocalY(self.Properties.cam_z, .8)
TransformBus.Event.SetLocalX(self.Properties.cam_y, .2)
camZbottom = .8
end
if isTreadingWater == true then
TransformBus.Event.SetLocalZ(self.Properties.cam_z, camZLoc + .02)
TransformBus.Event.SetWorldZ(self.entityId, 12.5)
is_moving = false;
camZtop = 2.5;
end
if is_moving == true then
TransformBus.Event.SetLocalY(self.Properties.cam_y, cam_y_loc -.01) --zoom out
end
if is_moving == false then
TransformBus.Event.SetLocalY(self.Properties.cam_y, cam_y_loc +.01) --zoom in
end
if is_moving == true and cam_z_rot.z > pi and cam_z_rot.z < 6.18 then
TransformBus.Event.RotateAroundLocalZ(self.entityId, -.1)
TransformBus.Event.RotateAroundLocalZ(self.Properties.cam_z,.1)
end
if is_moving == true and cam_z_rot.z < pi and cam_z_rot.z > .1 then
TransformBus.Event.RotateAroundLocalZ(self.entityId, .1)
TransformBus.Event.RotateAroundLocalZ(self.Properties.cam_z,-.1)
end
–in_air
– local config = RayCastConfiguration()
– local worldPosition = TransformBus.Event.GetWorldTM(self.entityId)
– config.origin = worldPosition:GetTranslation()
— config.direction = Vector3(0.0, 0.0,-1.0);
– local result = PhysicsSystemRequestBus.Broadcast.RayCast(config)
– local count = result:GetHitCount()
– if count > 0 then
– local hit = result:GetHit(1)
– local dist = (result:GetHit(1).position.z - config.origin.z) *-1 --distance from ground
– end
– if dist > 1 then
– AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “in_air”, true)
– else
– AnimGraphComponentRequestBus.Event.SetNamedParameterBool(self.entityId, “in_air”, false)
– end
end
return characterMovement;
– inventoryId…50
– buildModeId…100
– buildModeTextId…101
– buildMode currentItem foundation…120
– buildMode currentItem wall…121
– buildMode currentItem doorWay…122
– buildMode currentItem ramp…123
– buildMode currentItem Triangle…124
– buildMode currentItem midTriangle…125
– buildMode currentItem window…126
– buildRotXId… 130
– buildRotYId… 131
– buildRotZId… 132
– deleteBusId…133
– spawnBusId…134
local buildMode =
{
Properties =
{
cam_z = {default = EntityId()},
cam_y = {default = EntityId()},
ghostWindow = {default = EntityId()},
ghostFoundation = {default = EntityId()},
ghostTriangle = {default = EntityId()},
ghostMidTriangle = {default = EntityId()},
ghostWall = {default = EntityId()},
ghostDoorWay = {default = EntityId()},
ghostRamp = {default = EntityId()},
character = {default = EntityId()},
survivalHud = {default = EntityId()},
}
}
function buildMode:OnActivate()
self.incomingDataId = GameplayNotificationId(self.entityId, “messageData”, “float”);
self.incomingDataBus = GameplayNotificationBus.Connect(self, self.incomingDataId);–message receiver
pi = 3.14159265359;
self.tickBusHandler = TickBus.Connect(self);
isBuilding = false;
camZbottom = 1.2;
camZtop = 2;
xroundto = 0;
yroundto = 0;
zroundto = 0;
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostFoundation)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostWall)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostDoorWay)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostRamp)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostTriangle)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostMidTriangle)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostWindow)
end
function buildMode:OnDeactivate()
self.tickBusHandler:Disconnect()
self.incomingDataBus:Disconnect()
end
function buildMode:OnEventUpdating(incomingDataUpdating)
if isBuilding == true then
local isBuildingId = GameplayNotificationId(self.Properties.character, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEvenUpdating(isBuildingId, 110)
end
end
function buildMode:OnEventBegin(incomingDataBegin)
if incomingDataBegin == 100 then
isBuilding = not isBuilding
end
if isBuilding == false then
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostFoundation)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostWall)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostDoorWay)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostRamp)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostTriangle)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostMidTriangle)
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostWindow)
end
if incomingDataBegin == 120 then
ghostFoundationActivate = not ghostFoundationActivate
ghostWallActivate = false
ghostWindowActivate = false
ghostTriangleActivate = false
ghostMidTriangleActivate = false
ghostDoorWayActivate = false
ghostRampActivate = false
xroundto=.5
yroundto=.5
zroundto=4
end
if incomingDataBegin == 121 then
ghostWallActivate = not ghostWallActivate
ghostDoorWayActivate = false
ghostWindowActivate = false
ghostTriangleActivate = false
ghostMidTriangleActivate = false
ghostFoundationActivate = false
ghostRampActivate = false
xroundto=1
yroundto=1
zroundto=4
end
if incomingDataBegin == 122 then
ghostDoorWayActivate = not ghostDoorWayActivate
ghostFoundationActivate = false
ghostTriangleActivate = false
ghostMidTriangleActivate = false
ghostWindowActivate = false
ghostWallActivate = false
ghostRampActivate = false
xroundto=1
yroundto=1
zroundto=4
end
if incomingDataBegin == 123 then
ghostRampActivate = not ghostRampActivate
ghostWallActivate = false
ghostTriangleActivate = false
ghostMidTriangleActivate = false
ghostWindowActivate = false
ghostDoorWayActivate = false
ghostFoundationActivate = false
xroundto=1
yroundto=1
zroundto=4
end
if incomingDataBegin == 124 then
ghostTriangleActivate = not ghostTriangleActivate
ghostWallActivate = false
ghostWindowActivate = false
ghostMidTriangleActivate = false
ghostDoorWayActivate = false
ghostFoundationActivate = false
ghostRampActivate = false
xroundto=1
yroundto=1
zroundto=4
end
if incomingDataBegin == 125 then
ghostMidTriangleActivate = not ghostMidTriangleActivate
ghostWallActivate = false
ghostWindowActivate = false
ghostDoorWayActivate = false
ghostFoundationActivate = false
ghostRampActivate = false
ghostTriangleActivate = false
xroundto=1
yroundto=1
zroundto=4
end
if incomingDataBegin == 126 then
ghostWindowActivate = not ghostWindowActivate
ghostWallActivate = false
ghostTriangleActivate = false
ghostMidTriangleActivate = false
ghostDoorWayActivate = false
ghostFoundationActivate = false
ghostRampActivate = false
xroundto=1
yroundto=1
zroundto=4
end
--------------------------------------------------------------------------------------------------------errorControl
if isBuilding == true and
incomingDataBegin == 133 then
GameEntityContextRequestBus.Broadcast.DestroyGameEntityAndDescendants(spawnedBlock); --delete misplaced slice
end
--------------------------------------------------------------------------------------------------------foundationControl
if isBuilding == true and
incomingDataBegin == 134 then
SpawnerComponentRequestBus.Event.Spawn(self.Properties.ghostFoundation)
end
if isBuilding == true and
incomingDataBegin == 130 then
TransformBus.Event.RotateAroundLocalX(self.Properties.ghostFoundation, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 131 then
TransformBus.Event.RotateAroundLocalY(self.Properties.ghostFoundation, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 132 then
TransformBus.Event.RotateAroundLocalZ(self.Properties.ghostFoundation, (pi * .50082)) --.50082
end
--------------------------------------------------------------------------------------------------------wallControl
if isBuilding == true and
incomingDataBegin == 134 then
SpawnerComponentRequestBus.Event.Spawn(self.Properties.ghostWall)
end
if isBuilding == true and
incomingDataBegin == 130 then
TransformBus.Event.RotateAroundLocalX(self.Properties.ghostWall, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 131 then
TransformBus.Event.RotateAroundLocalY(self.Properties.ghostWall, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 132 then
TransformBus.Event.RotateAroundLocalZ(self.Properties.ghostWall, (pi * .50082)) --.50082
end
--------------------------------------------------------------------------------------------------------doorWayyControl
if isBuilding == true and
incomingDataBegin == 134 then
SpawnerComponentRequestBus.Event.Spawn(self.Properties.ghostDoorWay)
end
if isBuilding == true and
incomingDataBegin == 130 then
TransformBus.Event.RotateAroundLocalX(self.Properties.ghostDoorWay, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 131 then
TransformBus.Event.RotateAroundLocalY(self.Properties.ghostDoorWay, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 132 then
TransformBus.Event.RotateAroundLocalZ(self.Properties.ghostDoorWay, (pi * .50082)) --.50082
end
-------------------------------------------------------------------------------------------------------rampControl
if isBuilding == true and
incomingDataBegin == 134 then
SpawnerComponentRequestBus.Event.Spawn(self.Properties.ghostRamp)
end
if isBuilding == true and
incomingDataBegin == 130 then
TransformBus.Event.RotateAroundLocalX(self.Properties.ghostRamp, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 131 then
TransformBus.Event.RotateAroundLocalY(self.Properties.ghostRamp, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 132 then
TransformBus.Event.RotateAroundLocalZ(self.Properties.ghostRamp, (pi * .50082)) --.50082
end
--------------------------------------------------------------------------------------------------------triangleControl
if isBuilding == true and
incomingDataBegin == 134 then
SpawnerComponentRequestBus.Event.Spawn(self.Properties.ghostTriangle)
end
if isBuilding == true and
incomingDataBegin == 130 then
TransformBus.Event.RotateAroundLocalX(self.Properties.ghostTriangle, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 131 then
TransformBus.Event.RotateAroundLocalY(self.Properties.ghostTriangle, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 132 then
TransformBus.Event.RotateAroundLocalZ(self.Properties.ghostTriangle, (pi * .50082)) --.50082
end
--------------------------------------------------------------------------------------------------------windowControl
if isBuilding == true and
incomingDataBegin == 134 then
SpawnerComponentRequestBus.Event.Spawn(self.Properties.ghostWindow)
end
if isBuilding == true and
incomingDataBegin == 130 then
TransformBus.Event.RotateAroundLocalX(self.Properties.ghostWindow, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 131 then
TransformBus.Event.RotateAroundLocalY(self.Properties.ghostWindow, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 132 then
TransformBus.Event.RotateAroundLocalZ(self.Properties.ghostWindow, (pi * .50082)) --.50082
end
--------------------------------------------------------------------------------------------------------midTriangleControl
if isBuilding == true and
incomingDataBegin == 134 then
SpawnerComponentRequestBus.Event.Spawn(self.Properties.ghostMidTriangle)
end
if isBuilding == true and
incomingDataBegin == 130 then
TransformBus.Event.RotateAroundLocalX(self.Properties.ghostMidTriangle, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 131 then
TransformBus.Event.RotateAroundLocalY(self.Properties.ghostMidTriangle, (pi * .50082)) --.50082
end
if isBuilding == true and
incomingDataBegin == 132 then
TransformBus.Event.RotateAroundLocalZ(self.Properties.ghostMidTriangle, (pi * .50082)) --.50082
end
Debug.Log(tostring(incomingDataBegin))
end
function buildMode:OnEventEnd(incomingDataEnd)
end
function buildMode:OnHeld(float)
end
function buildMode:OnReleased(float)
end
function buildMode:OnTick(deltaTime)
local cam_y_loc = TransformBus.Event.GetLocalY(self.Properties.cam_y)
local cam_z_rot = TransformBus.Event.GetLocalRotation(self.Properties.cam_z)
local camZLoc = TransformBus.Event.GetLocalZ(self.Properties.cam_z)
if camZLoc > camZtop then camZLoc = camZtop
end
if camZLoc < camZbottom then camZLoc = camZbottom
end
if isBuilding == true then
TransformBus.Event.SetLocalZ(self.Properties.cam_z, camZLoc + .02)
end
if isBuilding == false then
TransformBus.Event.SetLocalZ(self.Properties.cam_z, camZLoc - .01)
end
–buildMode
if isBuilding == true then
if ghostFoundationActivate == true then
GameEntityContextRequestBus.Broadcast.ActivateGameEntity(self.Properties.ghostFoundation)
TransformBus.Event.SetWorldTranslation(self.Properties.ghostFoundation, buildLoc)
else
ghostFoundationActivate = false
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostFoundation)
end
if ghostWallActivate == true then
GameEntityContextRequestBus.Broadcast.ActivateGameEntity(self.Properties.ghostWall)
TransformBus.Event.SetWorldTranslation(self.Properties.ghostWall, buildLoc)
else
ghostWallActivate = false
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostWall)
end
if ghostWindowActivate == true then
GameEntityContextRequestBus.Broadcast.ActivateGameEntity(self.Properties.ghostWindow)
TransformBus.Event.SetWorldTranslation(self.Properties.ghostWindow, buildLoc)
else
ghostWindowActivate = false
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostWindow)
end
if ghostDoorWayActivate == true then
GameEntityContextRequestBus.Broadcast.ActivateGameEntity(self.Properties.ghostDoorWay)
TransformBus.Event.SetWorldTranslation(self.Properties.ghostDoorWay, buildLoc)
else
ghostDoorWayActivate = false
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostDoorWay)
end
if ghostRampActivate == true then
GameEntityContextRequestBus.Broadcast.ActivateGameEntity(self.Properties.ghostRamp)
TransformBus.Event.SetWorldTranslation(self.Properties.ghostRamp, buildLoc)
else
ghostRampActivate = false
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostRamp)
end
if ghostTriangleActivate == true then
GameEntityContextRequestBus.Broadcast.ActivateGameEntity(self.Properties.ghostTriangle)
TransformBus.Event.SetWorldTranslation(self.Properties.ghostTriangle, buildLoc)
else
ghostTriangleActivate = false
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostTriangle)
end
if ghostMidTriangleActivate == true then
GameEntityContextRequestBus.Broadcast.ActivateGameEntity(self.Properties.ghostMidTriangle)
TransformBus.Event.SetWorldTranslation(self.Properties.ghostMidTriangle, buildLoc)
else
ghostMidTriangleActivate = false
GameEntityContextRequestBus.Broadcast.DeactivateGameEntity(self.Properties.ghostMidTriangle)
end
–raycast
local build = RayCastConfiguration()
local camPosition = TransformBus.Event.GetWorldTM(self.Properties.cam_y)
local mask = PhysicalEntityTypes.Static + PhysicalEntityTypes.Terrain;
build.origin = camPosition:GetPosition()
build.direction = camPosition:GetColumn(1);
build.maxDistance = 20;
build.physicalEntityTypes = mask
local result = PhysicsSystemRequestBus.Broadcast.RayCast(build)
local count = result:GetHitCount()
if count > 0 then
local hit = result:GetHit(1)
buildHit = hit.position
spawnedBlock = hit.entityId
end
– Debug.Log(tostring(xx))
–snapping
if buildHit.x*xroundto<0 then x=-.5 else x=.5 end
Integer, decimal = math.modf(buildHit.x*xroundto+x)
xx = Integer/xroundto
if buildHit.y*yroundto<0 then x=-.5 else x=.5 end
Integer, decimal = math.modf(buildHit.y*yroundto+x)
yy = Integer/yroundto
if buildHit.z*zroundto<0 then x=-.5 else x=.5 end
Integer, decimal = math.modf(buildHit.z*zroundto+x)
zz = Integer/zroundto
buildLoc = Vector3(xx,yy,zz)
end
end
return buildMode
local survivalHud =
{
Properties =
{
character = {default = EntityId()},
buildMode = {default = EntityId()},
}
}
function survivalHud:OnActivate()
canvasEntityId = UiCanvasAssetRefBus.Event.LoadCanvas(self.entityId)
buildModeText = UiCanvasBus.Event.FindElementByName(canvasEntityId, “buildMode”)
UiElementBus.Event.SetIsEnabled(buildModeText, false)
inventoryActivate = UiCanvasBus.Event.FindElementByName(canvasEntityId, “Inventory”)
UiElementBus.Event.SetIsEnabled(inventoryActivate, false)
self.incomingDataId = GameplayNotificationId(self.entityId, “messageData”, “float”);–message receiver
self.incomingDataBus = GameplayNotificationBus.Connect(self, self.incomingDataId);
self.tickBusHandler = TickBus.Connect(self);
stamina = UiCanvasBus.Event.FindElementByName(canvasEntityId, “Stamina”)
UiSliderBus.Event.SetMinValue(stamina, 0)
UiSliderBus.Event.SetMaxValue(stamina, 100)
UiSliderBus.Event.SetValue(stamina, 50)
UiSliderBus.Event.SetStepValue(stamina, 0)
stamRegen = .1;
equiped = UiCanvasBus.Event.FindElementByName(canvasEntityId, “Equiped”)
equipedSlot1 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot1”)
equipedSlot2 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot2”)
equipedSlot3 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot3”)
equipedSlot4 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot4”)
equipedSlot5 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot5”)
equipedSlot6 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot6”)
equipedSlot7 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot7”)
equipedSlot8 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot8”)
equipedSlot9 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot9”)
equipedSlot0 = UiCanvasBus.Event.FindElementByName(canvasEntityId, “EquipedSlot0”)
– currentItem = UiElementBus.Event.GetChild(equipedSlot1, 0)
end
function survivalHud:OnDeactivate()
self.tickBusHandler:Disconnect()
self.incomingDataBus:Disconnect()
end
function survivalHud:OnEventUpdating(incomingDataUpdating)
if incomingDataUpdating == 1 then
stamRegen = -.05
end
end
function survivalHud:OnEventBegin(incomingDataBegin)
local staminaCurrent = UiSliderBus.Event.GetValue(stamina)
if incomingDataBegin == 2 then
UiSliderBus.Event.SetValue(stamina, staminaCurrent - 10)
end
if incomingDataBegin == 50 then
UiElementBus.Event.SetIsEnabled(inventoryActivate, true)
end
if incomingDataBegin == 101 then
UiElementBus.Event.SetIsEnabled(buildModeText, true)
end
if incomingDataBegin == 120 then
– Debug.Log(tostring(120))
currentItem = UiElementBus.Event.GetChild(equipedSlot1, 0)----------------------------------------------------------------
end
if incomingDataBegin == 121 then
currentItem = UiElementBus.Event.GetChild(equipedSlot2, 0)----------------------------------------------------------------
end
if incomingDataBegin == 122 then
currentItem = UiElementBus.Event.GetChild(equipedSlot3, 0)----------------------------------------------------------------
Debug.Log(tostring(incomingDataBegin))
end
if incomingDataBegin == 123 then
currentItem = UiElementBus.Event.GetChild(equipedSlot4, 0)----------------------------------------------------------------
end
if incomingDataBegin == 124 then
currentItem = UiElementBus.Event.GetChild(equipedSlot5, 0)----------------------------------------------------------------
end
if incomingDataBegin == 125 then
currentItem = UiElementBus.Event.GetChild(equipedSlot6, 0)----------------------------------------------------------------
end
if incomingDataBegin == 126 then
currentItem = UiElementBus.Event.GetChild(equipedSlot7, 0)----------------------------------------------------------------
end
if currentItem == UiCanvasBus.Event.FindElementByName(canvasEntityId, “foundation”) then
local currentItemId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 120)
end
if currentItem == UiCanvasBus.Event.FindElementByName(canvasEntityId, “wall”) then
local currentItemId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 121)
end
if currentItem == UiCanvasBus.Event.FindElementByName(canvasEntityId, “doorWay”) then
local currentItemId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 122)
Debug.Log(tostring(currentItemId))
end
if currentItem == UiCanvasBus.Event.FindElementByName(canvasEntityId, “ramp”) then
local currentItemId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 123)
end
if currentItem == UiCanvasBus.Event.FindElementByName(canvasEntityId, “triangle”) then
local currentItemId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 124)
end
if currentItem == UiCanvasBus.Event.FindElementByName(canvasEntityId, “midTriangle”) then
local currentItemId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 125)
end
if currentItem == UiCanvasBus.Event.FindElementByName(canvasEntityId, “window”) then
local currentItemId = GameplayNotificationId(self.Properties.buildMode, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventBegin(currentItemId, 126)
end
end
function survivalHud:OnEventEnd(incomingDataEnd)
if incomingDataEnd == 1 then
stamRegen = .1
end
if incomingDataEnd == 2 then
stamRegen = .1
end
if incomingDataEnd == 50 then
UiElementBus.Event.SetIsEnabled(inventoryActivate, false)
end
if incomingDataEnd == 101 then
UiElementBus.Event.SetIsEnabled(buildModeText, false)
end
end
function survivalHud:OnTick(deltaTime)
– Debug.Log(tostring(currentItem))
local staminaCurrent = UiSliderBus.Event.GetValue(stamina)
local staminaMax = UiSliderBus.Event.GetMaxValue(stamina)
UiSliderBus.Event.SetValue(stamina, staminaCurrent + stamRegen)
if staminaCurrent < 25 then
local tiredId = GameplayNotificationId(self.Properties.character, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventUpdating(tiredId, 3) --tired
end
if staminaCurrent > 25 then
local tiredId = GameplayNotificationId(self.Properties.character, “messageData”, “float”);—message sender
GameplayNotificationBus.Event.OnEventEnd(tiredId, 3) --tired
end
– Debug.Log(tostring(currentItem))
–Debug.Log(“yay” …tostring(stopData))
end
return survivalHud