Skip to content

Instantly share code, notes, and snippets.

@Nimblz
Last active March 8, 2019 02:17
Show Gist options
  • Save Nimblz/38e226c25b8c94e20888a3e8658e86f5 to your computer and use it in GitHub Desktop.
Save Nimblz/38e226c25b8c94e20888a3e8658e86f5 to your computer and use it in GitHub Desktop.
local workspace = game:GetService("Workspace")
local replicatedStorage = game:GetService("ReplicatedStorage")
local modules = require(replicatedStorage.modules)
--local pathfinding = modules.load("pathfinding")
local utilities = modules.load("utilities")
local detection = modules.load("detection")
local network = modules.load("network")
local projectile = modules.load("projectile")
local placeSetup = modules.load("placeSetup")
--local MONSTER_END_POSITION_ALPHA = 1
return {
processDamageRequest = function(sourceId, baseDamage)
return baseDamage, "physical", "direct"
end;
default = "idling",
states = {
["setup"] = {
animationEquivalent = "dormant";
transitionLevel = 0;
step = function(monster)
end;
};
["sleeping"] = {
animationEquivalent = "dormant";
timeBetweenUpdates = 5;
transitionLevel = 1;
step = function(monster, canSwitchState)
if monster.__closestPlayer then
return "dormant"
end
end;
};
["dormant"] = {
timeBetweenUpdates = 3;
transitionLevel = 2;
step = function(monster, canSwitchState)
if monster.__closestPlayer then
local closestPlayerDistance = utilities.magnitude(monster.__closestHRP.Position - monster.manifest.Position)
if
closestPlayerDistance <= monster.aggressionRange and
monster:isTargetPlayerInLineOfSight(monster.aggressionRange, true)
then -- i smell a human
monster:setTargetPlayer(monster.__closestPlayer, monster.__closestHRP)
return "awaken" -- wake up sleepy one
end
end
end;
};
["awaken"] = {
transitionLevel = 3;
doNotStopAnimation = true;
doNotLoopAnimation = true;
lockTimeForPreventStateTransition = 4;
step = function(monster, canSwitchState)
if canSwitchState then -- wait for anim to finish
return "idling"
end
end;
};
["idling"] = {
timeBetweenUpdates = 2;
transitionLevel = 4;
step = function(monster, canSwitchState)
if canSwitchState then
if monster.__closestPlayer then
local closestPlayerDistance = utilities.magnitude(monster.__closestHRP.Position - monster.manifest.Position)
if
closestPlayerDistance <= monster.aggressionRange and
monster:isTargetPlayerInLineOfSight(monster.aggressionRange, true)
then -- an intruder! attaaack!
monster:setTargetPlayer(monster.__closestPlayer, monster.__closestHRP)
monster.manifest.BodyGyro.CFrame = CFrame.new(monster.manifest.Position, monster.__closestHRP.Position)
return "attacking"
end
end
end
end;
};
["attacking"] = {
transitionLevel = 5;
lockTimeForPreventStateTransition = 5;
doNotStopAnimation = true;
doNotLoopAnimation = true;
animationPriority = Enum.AnimationPriority.Action;
execute = function(player, targetAnimation, monsterData, clientMonsterContainer) -- throw that boi
print("throwing")
-- ripped out of spider queen, if it aint broke dont fix it
if not clientMonsterContainer or not clientMonsterContainer:FindFirstChild("clientHitboxToServerHitboxReference") then
return
end
local serverHitbox = clientMonsterContainer.clientHitboxToServerHitboxReference.Value
if not game:GetService("RunService"):IsClient() then
warn("attacking::execute can only be called on client")
return
elseif not serverHitbox then
return
elseif not serverHitbox:FindFirstChild("stateData") then
return
elseif not player.Character or not player.Character.PrimaryPart then
return
elseif not clientMonsterContainer:FindFirstChild("entity") then
return
elseif not clientMonsterContainer.entity:FindFirstChild("LeftLowerArm") then
return
end
local targetPlayerRootPart = serverHitbox.targetPlayerHRP.Value
if targetPlayerRootPart then
local golem = clientMonsterContainer.entity
local playerRenderCollection = placeSetup.getPlaceFolder("playerRenderCollection")
local monsterRenderCollection = placeSetup.getPlaceFolder("monsterRenderCollection")
local playerManifestCollection = placeSetup.getPlaceFolder("playerManifestCollection")
local monsterManifestCollection = placeSetup.getPlaceFolder("monsterManifestCollection")
targetAnimation:GetMarkerReachedSignal("pickup"):Wait()
local rockHandWeld = Instance.new("Weld") -- used to attach rock to hand
local rockProjectilePart = script.largeRockProjectile:Clone()
local targetPlayerRoot = serverHitbox.targetPlayerHRP.Value
rockProjectilePart.Parent = golem
rockHandWeld.Part0 = golem.LeftLowerArm
rockHandWeld.Part1 = rockProjectilePart
rockHandWeld.C0 = CFrame.new(0,-rockProjectilePart.Size.Y/2,0)
rockHandWeld.Parent = rockProjectilePart
rockProjectilePart.Parent = workspace
targetAnimation:GetMarkerReachedSignal("throw"):Wait()
rockHandWeld:Destroy()
local startPos = golem.LeftLowerArm.Position
local targetPos = targetPlayerRootPart.Position
local projectileSpeed = 60
local unitDirection, adjusted_targetPosition = projectile.getUnitVelocityToImpact_predictive(
startPos,
projectileSpeed,
serverHitbox.targetPlayerHRP.Value.Position, -- target pos,
serverHitbox.targetPlayerHRP.Value.Velocity -- target vel
)
projectile.createProjectile(
startPos,
unitDirection,
projectileSpeed,
rockProjectilePart,
function(hitPart,hitPosition)
if hitPart then
if player.Character and player.Character.PrimaryPart then
local characterHitbox = player.Character.PrimaryPart
local boxProjection_HRP = detection.projection_Box(
characterHitbox.CFrame,
characterHitbox.Size, hitPosition
)
if detection.spherecast_singleTarget(hitPosition, 6, boxProjection_HRP) then
print("big ol rock hit!")
network:fireServer(
"playerRequest_damageEntity",
serverHitbox,
boxProjection_HRP,
"monster"
)
end
end
end
end,
nil,
{clientMonsterContainer; serverHitbox; playerRenderCollection; monsterRenderCollection; playerManifestCollection; monsterManifestCollection}
)
end
end;
step = function(monster, canSwitchState)
local targetPlayerRootPart = monster.manifest.targetPlayerHRP.Value
monster.manifest.BodyGyro.CFrame = CFrame.new(monster.manifest.Position, targetPlayerRootPart.Position)
if canSwitchState then
return "idling" -- done throwing, go back to idle!
end
end
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment