AddCSLuaFile( 'cl_init.lua' )
AddCSLuaFile( 'cl_deathnotice.lua' )
include( 'shared.lua' )
include( 'player.lua' )
include( 'npc.lua' )
GM.PlayerSpawnTime = {}
/*---------------------------------------------------------
Name: gamemode:Initialize( )
Desc: Called immediately after starting the gamemode
---------------------------------------------------------*/
function GM:Initialize( )
end
function GM:PlayerInitialSpawn(ply)
local playe = player.GetByID(1)
ply:ChatPrint("Welcome to " .. tostring(playe:GetName()) .. "'s Mage Wars Server!")
local plays = player.GetAll()
for k, found in pairs(plays) do
found:ChatPrint(tostring(ply:GetName()) .. " has joined the battle!")
end
ply:SetNWString("MClass", "BasicMage")
ply:SetNWInt("MLevel", 1)
ply:SetNWInt("MExp", 0)
ply:SetNWInt("MInt", 1)
ply:SetNWInt("MSpir", 1)
ply:SetNWInt("MStam", 1)
ply.Classified = false
end
function GM:PlayerLoadout( pl )
pl:GiveAmmo( 256, "Pistol", true )
pl:SetHealth(100)
pl:SetArmor(100)
pl:Give("weapon_basemage")
// Set the player's speed
self.BaseClass:SetPlayerSpeed( pl, 300, 500 )
local cl_defaultweapon = pl:GetInfo( "cl_defaultweapon" )
if ( pl:HasWeapon( cl_defaultweapon ) ) then
pl:SelectWeapon( cl_defaultweapon )
end
end
/*---------------------------------------------------------
Name: gamemode:InitPostEntity( )
Desc: Called as soon as all map entities have been spawned
---------------------------------------------------------*/
function GM:InitPostEntity( )
end
/*---------------------------------------------------------
Name: gamemode:Think( )
Desc: Called every frame
---------------------------------------------------------*/
function GM:Think( )
end
/*---------------------------------------------------------
Name: gamemode:EntityKeyValue( ent, key, value )
Desc: Called when an entity has a keyvalue set
Returning a string it will override the value
---------------------------------------------------------*/
function GM:EntityKeyValue( ent, key, value )
end
/*---------------------------------------------------------
Name: gamemode:ShutDown( )
Desc: Called when the Lua system is about to shut down
---------------------------------------------------------*/
function GM:ShutDown( )
end
//////// PLAYER FUNCTIONS ////////
local Meta = FindMetaTable("Player")
function Meta:SetLevel(amt)
self.Level = amt
self:SetNWInt("MLevel", amt)
end
function Meta:SetClass(class)
self.Class = class
self:SetNWString("MClass", class)
end
function Meta:GetMageClass()
if SERVER then
return self:GetTable( ).Class
else
return self:GetNWString("MClass")
end
end
function Meta:GetLevel( )
if SERVER then
return self:GetTable( ).Level
else
return self:GetNWInt( "MLevel", 1 )
end
end
function Meta:SetStam(amt)
self.Stam = amt
self:SetNWInt("MStam", amt)
end
function Meta:GetStam( )
if SERVER then
return self:GetTable( ).Stam
else
return self:GetNWInt( "MStam", 1 )
end
end
function Meta:GetSpir( )
if SERVER then
return self:GetTable( ).Spirit
else
return self:GetNWInt( "MSpir", 1 )
end
end
function Meta:SetSpir(amt)
self.Spir = amt
self:SetNWInt("MSpir", amt)
end
function Meta:GetIntel( )
if SERVER then
return self:GetTable( ).Intel
else
return self:GetNWInt( "MInt", 1 )
end
end
function Meta:SetIntel(amt)
self.Intel = amt
self:SetNWInt("MInt", amt)
end
function Meta:EXPLVL(target)
local targetExp = 150 + math.floor( ( ( self:GetLevel( ) + 1 ) ^ 2 ) / 2 )
local curExp = self:GetNWInt("MExp")
local addExp = 50 + math.floor( ( target:GetLevel() + 5 ) * 2 )
if curExp + addExp >= targetExp then
self:SetLevel(self:GetLevel() + 1)
else
curExp = curExp + addExp
end
end
function Meta:ClassSelection()
if CLIENT then
ShowVGUI()
end
self:SetClass(self.Class)
self:ClassLoadOut(self.Class)
end
//////////////////////////////////
if CLIENT then
local MainPanel
local Wi = surface.ScreenWidth()
local He = surface.ScreenHeight()
local CenterPosX = Wi / 2.5
local CenterPosY = He
function MageSelect()
if LocalPlayer().Classified then return end
MainPanel = vgui.Create("Panel")
MainPanel:SetPos( CenterPosX / 1.68, CenterPosY / 3.5 )
MainPanel:SetSize(Wi / 2, He / 8)
MainPanel:SetName("ClassPanel")
MainPanel:SetKeyboardInputEnabled(true)
MainPanel:SetVisible(false)
MainPanel.Button = {}
local deltaLen = ((Wi / 2.65) / 6)
for i = 1, 4 do
local BoxPos = ( deltaLen * i )
MainPanel.Button[i] = vgui.Create("SelectClassButton", MainPanel)
MainPanel.Button[i]:SetName("Button." .. i )
MainPanel.Button[i]:SetPos(BoxPos, 3)
MainPanel.Button[i]:SetSize(Wi / 20, He / 30)
end
if MainPanel.ButtonPanels[4] then
MainPanel.Button[1]:SetText("Fire Mage")
MainPanel.Button[1]:SetName("Fire Mage")
MainPanel.Button[2]:SetText("Ice Mage")
MainPanel.Button[2]:SetName("Ice Mage")
MainPanel.Button[3]:SetText("Lightning Mage")
MainPanel.Button[3]:SetName("Lightning Mage")
MainPanel.Button[4]:SetText("Holy Mage")
MainPanel.Button[4]:SetName("Holy Mage")
end
end
hook.Add("Initialize", "MageVGUI", MageSelect)
vgui.Register("MageWarsSelection", MainPanel)
local Class = {}
function Class:DoClick()
LocalPlayer():SetNWString("MClass", self:GetName())
LocalPlayer().Class = self:GetName()
LocalPlayer().Classified = true
MainPanel:SetVisible(!MainPanel:SetVisible())
end
vgui.Register("SelectClassButton",Class,"Button")
function ShowVGUI()
MainPanel:SetVisible(!MainPanel:SetVisible())
end
end
/*---------------------------------------------------------
Name: gamemode:DoPlayerDeath( )
Desc: Carries out actions when the player dies
---------------------------------------------------------*/
function GM:DoPlayerDeath( ply, attacker, dmginfo )
ply:CreateRagdoll()
ply:AddDeaths( 1 )
if ( attacker:IsValid() && attacker:IsPlayer() ) then
if ( attacker == ply ) then
attacker:AddFrags( -1 )
else
attacker:AddFrags( 1 )
attacker:EXPLVL()
if attacker.Classified == false then
if attacker:GetLevel() == 10 then
attacker:ClassSelection()
end
end
end
end
end
/*---------------------------------------------------------
Name: gamemode:EntityTakeDamage( entity, inflictor, attacker, amount )
Desc: The entity has received damage
---------------------------------------------------------*/
function GM:EntityTakeDamage( ent, inflictor, attacker, amount )
end
function GM:PlayerDeath( ply, weapon, attacker )
self.BaseClass:PlayerDeath( ply, weapon, attacker )
end
function GM:OnNPCKilled( victim, killer, weapon )
self.BaseClass:OnNPCKilled( victim, killer, weapon )
end
function GM:ScalePlayerDamage( ply, hitgroup, dmginfo )
if ( hitgroup == HITGROUP_HEAD ) then
dmginfo:ScaleDamage( 3 )
elseif( hitgroup == HITGROUP_CHEST ) then
dmginfo:ScaleDamage( 1.5 )
elseif( hitgroup == HITGROUP_LEFTARM or hitgroup == HITGROUP_RIGHTARM ) then
dmginfo:ScaleDamage( 0.5 )
elseif( hitgroup == HITGROUP_LEFTLEG or hitgroup == HITGROUP_RIGHTLEG ) then
dmginfo:ScaleDamage( 0.3 )
end
end
// Set the ServerName every 2 seconds in case it changes..
local function HostnameThink()
SetGlobalString( "ServerName", GetConVarString( "hostname" ) )
end
timer.Create( "HostnameThink", 2, 0, HostnameThink )