Initial commit
This commit is contained in:
53
addons/mc_quests/lua/entities/mqs_ent/cl_init.lua
Normal file
53
addons/mc_quests/lua/entities/mqs_ent/cl_init.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
include("shared.lua")
|
||||
|
||||
function ENT:Initialize()
|
||||
if self:GetEnablePhys() then return end
|
||||
self:InitRenderModel()
|
||||
end
|
||||
|
||||
function ENT:InitRenderModel()
|
||||
self.RenderModel = ClientsideModel(self:GetCModel())
|
||||
self.RenderModel:SetPos(self:GetPos())
|
||||
self.RenderModel:SetParent(self)
|
||||
self.RenderModel:SetMaterial(self:GetMaterial())
|
||||
self.RenderModel:SetColor(self:GetColor())
|
||||
self:CallOnRemove("RenderModel", function()
|
||||
SafeRemoveEntity(self.RenderModel)
|
||||
end)
|
||||
end
|
||||
|
||||
function ENT:Draw()
|
||||
local Pos = self:GetPos()
|
||||
local Ang = self:GetAngles()
|
||||
local eyepos = EyePos()
|
||||
local planeNormal = Ang:Up()
|
||||
if Pos:DistToSqr(LocalPlayer():GetPos()) > MQS.Config.QuestEntDrawDist ^ 2 then return end
|
||||
|
||||
if self:GetEnablePhys() then
|
||||
self:DrawModel()
|
||||
else
|
||||
local sysTime = SysTime()
|
||||
local rotAng = Angle(Ang)
|
||||
self.rotationOffset = sysTime % 360 * 130
|
||||
rotAng:RotateAroundAxis(planeNormal, self.rotationOffset)
|
||||
|
||||
if not IsValid(self.RenderModel) then
|
||||
self:InitCsInitRenderModelModel()
|
||||
end
|
||||
|
||||
self.RenderModel:SetPos(Pos)
|
||||
self.RenderModel:SetAngles(rotAng)
|
||||
end
|
||||
|
||||
if self:GetTPly() ~= LocalPlayer() then return end
|
||||
if not self:GetShowPointer() then return end
|
||||
Ang:RotateAroundAxis(Ang:Forward(), 90)
|
||||
local relativeEye = eyepos - Pos
|
||||
local relativeEyeOnPlane = relativeEye - planeNormal * relativeEye:Dot(planeNormal)
|
||||
local textAng = relativeEyeOnPlane:AngleEx(planeNormal)
|
||||
textAng:RotateAroundAxis(textAng:Up(), 90)
|
||||
textAng:RotateAroundAxis(textAng:Forward(), 90)
|
||||
cam.Start3D2D(Pos - Ang:Right() * (50 + math.sin(CurTime() * 2) * 5), textAng, 0.2)
|
||||
MSD.DrawTexturedRect(-23, -23, 48, 64, MSD.Icons48.arrow_down_color, color_white)
|
||||
cam.End3D2D()
|
||||
end
|
||||
84
addons/mc_quests/lua/entities/mqs_ent/init.lua
Normal file
84
addons/mc_quests/lua/entities/mqs_ent/init.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
AddCSLuaFile("cl_init.lua")
|
||||
AddCSLuaFile("shared.lua")
|
||||
include("shared.lua")
|
||||
|
||||
function ENT:Initialize()
|
||||
if not self.model then
|
||||
self.model = "models/props_junk/garbage_newspaper001a.mdl"
|
||||
end
|
||||
|
||||
self:SetModel(self.model)
|
||||
self:SetCModel(self.model)
|
||||
self:SetTPly(self.task_ply)
|
||||
self:SetShowPointer(self.pointer)
|
||||
self:SetEnablePhys(self.enablephys)
|
||||
self:SetMoveType(MOVETYPE_VPHYSICS)
|
||||
self:SetUseType(SIMPLE_USE)
|
||||
self:SetSolid(SOLID_VPHYSICS)
|
||||
self:Activate()
|
||||
end
|
||||
|
||||
function ENT:PickUP(ply)
|
||||
MQS.SetSelfNWdata(ply, "quest_colected", MQS.GetSelfNWdata(ply, "quest_colected") + 1)
|
||||
|
||||
if MQS.GetSelfNWdata(ply, "quest_colected") >= MQS.GetSelfNWdata(ply, "quest_ent") then
|
||||
MQS.UpdateObjective(ply)
|
||||
end
|
||||
|
||||
self.save_remove = true
|
||||
SafeRemoveEntity(self)
|
||||
|
||||
end
|
||||
|
||||
function ENT:Use(ply)
|
||||
if ply ~= self.task_ply then return end
|
||||
|
||||
if self:GetUseHold() then
|
||||
if not self.StartPicking then
|
||||
self.StartPicking = CurTime()
|
||||
self.pickply = ply
|
||||
end
|
||||
return
|
||||
end
|
||||
self:PickUP(ply)
|
||||
end
|
||||
|
||||
function ENT:Think()
|
||||
self:NextThink(CurTime())
|
||||
|
||||
if self.StartPicking and self:GetUseHold() and IsValid(self.pickply) and self.pickply:KeyDown(IN_USE) then
|
||||
local progress = (self.StartPicking + self:GetUseHold() - CurTime()) / self:GetUseHold()
|
||||
progress = 1 - progress
|
||||
if progress >= 1 then
|
||||
self:PickUP(self.pickply)
|
||||
self.StartPicking = nil
|
||||
self:SetPickProgress(0)
|
||||
self.pickply = nil
|
||||
return true
|
||||
end
|
||||
self:SetPickProgress(progress)
|
||||
else
|
||||
self.StartPicking = nil
|
||||
self:SetPickProgress(0)
|
||||
self.pickply = nil
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function ENT:OnRemove()
|
||||
if MQS.ActiveTask[self.task_id] then
|
||||
table.RemoveByValue(MQS.ActiveTask[self.task_id].ents, self:EntIndex())
|
||||
end
|
||||
|
||||
if not self.save_remove and IsValid(self.task_ply) then
|
||||
MQS.SetSelfNWdata(self.task_ply, "quest_ent", MQS.GetSelfNWdata(self.task_ply, "quest_ent") - 1)
|
||||
|
||||
if MQS.GetSelfNWdata(self.task_ply, "quest_colected") >= MQS.GetSelfNWdata(self.task_ply, "quest_ent") then
|
||||
MQS.UpdateObjective(self.task_ply)
|
||||
end
|
||||
end
|
||||
|
||||
if self.task_ply then
|
||||
MQS.ActiveDataShare(self.task_ply)
|
||||
end
|
||||
end
|
||||
14
addons/mc_quests/lua/entities/mqs_ent/shared.lua
Normal file
14
addons/mc_quests/lua/entities/mqs_ent/shared.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
ENT.Type = "anim"
|
||||
ENT.Base = "base_gmodentity"
|
||||
ENT.PrintName = "Quest Item"
|
||||
ENT.Author = "Mactavish"
|
||||
|
||||
function ENT:SetupDataTables()
|
||||
self:NetworkVar("String", 0, "CModel")
|
||||
self:NetworkVar("Entity", 0, "TPly")
|
||||
self:NetworkVar("Bool", 0, "Distractible")
|
||||
self:NetworkVar("Bool", 1, "EnablePhys")
|
||||
self:NetworkVar("Bool", 2, "ShowPointer")
|
||||
self:NetworkVar("Int", 0, "UseHold")
|
||||
self:NetworkVar("Float", 0, "PickProgress")
|
||||
end
|
||||
Reference in New Issue
Block a user