Permalink
Browse files

Merge pull request #551 from HandsomeMatt/remove_umsgs

Replace usermessages with net messages in base gamemode & undo module.
  • Loading branch information...
2 parents 6f22c36 + 067e786 commit af6a57ba200a3bb8f5bfac23e2f7024da4e837c0 @UnderscoreKilburn UnderscoreKilburn committed Jan 27, 2014
@@ -42,11 +42,11 @@ local function PlayerIDOrNameToString( var )
end
-local function RecvPlayerKilledByPlayer( message )
+local function RecvPlayerKilledByPlayer()
- local victim = message:ReadEntity();
- local inflictor = message:ReadString();
- local attacker = message:ReadEntity();
+ local victim = net.ReadEntity();
+ local inflictor = net.ReadString();
+ local attacker = net.ReadEntity();
if ( !IsValid( attacker ) ) then return end
if ( !IsValid( victim ) ) then return end
@@ -55,39 +55,38 @@ local function RecvPlayerKilledByPlayer( message )
end
-usermessage.Hook( "PlayerKilledByPlayer", RecvPlayerKilledByPlayer )
+net.Receive( "PlayerKilledByPlayer", RecvPlayerKilledByPlayer )
+local function RecvPlayerKilledSelf()
-local function RecvPlayerKilledSelf( message )
-
- local victim = message:ReadEntity();
+ local victim = net.ReadEntity();
if ( !IsValid( victim ) ) then return end
GAMEMODE:AddDeathNotice( nil, 0, "suicide", victim:Name(), victim:Team() )
end
-usermessage.Hook( "PlayerKilledSelf", RecvPlayerKilledSelf )
+net.Receive( "PlayerKilledSelf", RecvPlayerKilledSelf )
-local function RecvPlayerKilled( message )
+local function RecvPlayerKilled()
- local victim = message:ReadEntity();
+ local victim = net.ReadEntity();
if ( !IsValid( victim ) ) then return end
- local inflictor = message:ReadString();
- local attacker = "#" .. message:ReadString();
+ local inflictor = net.ReadString();
+ local attacker = "#" .. net.ReadString();
GAMEMODE:AddDeathNotice( attacker, -1, inflictor, victim:Name(), victim:Team() )
end
-usermessage.Hook( "PlayerKilled", RecvPlayerKilled )
+net.Receive( "PlayerKilled", RecvPlayerKilled )
-local function RecvPlayerKilledNPC( message )
+local function RecvPlayerKilledNPC()
- local victimtype = message:ReadString();
+ local victimtype = net.ReadString();
local victim = "#" .. victimtype;
- local inflictor = message:ReadString();
- local attacker = message:ReadEntity();
+ local inflictor = net.ReadString();
+ local attacker = net.ReadEntity();
--
-- For some reason the killer isn't known to us, so don't proceed.
@@ -115,20 +114,20 @@ local function RecvPlayerKilledNPC( message )
end
-usermessage.Hook( "PlayerKilledNPC", RecvPlayerKilledNPC )
+net.Receive( "PlayerKilledNPC", RecvPlayerKilledNPC )
-local function RecvNPCKilledNPC( message )
+local function RecvNPCKilledNPC()
- local victim = "#" .. message:ReadString();
- local inflictor = message:ReadString();
- local attacker = "#" .. message:ReadString();
+ local victim = "#" .. net.ReadString();
+ local inflictor = net.ReadString();
+ local attacker = "#" .. net.ReadString();
GAMEMODE:AddDeathNotice( attacker, -1, inflictor, victim, -1 )
end
-usermessage.Hook( "NPCKilledNPC", RecvNPCKilledNPC )
+net.Receive( "NPCKilledNPC", RecvNPCKilledNPC )
@@ -1,3 +1,6 @@
+-- Add Network Strings we use
+util.AddNetworkString( "PlayerKilledNPC" )
+util.AddNetworkString( "NPCKilledNPC" )
--[[---------------------------------------------------------
Name: gamemode:OnNPCKilled( entity, attacker, inflictor )
@@ -27,27 +30,27 @@ function GM:OnNPCKilled( ent, attacker, inflictor )
if ( attacker:IsPlayer() ) then
- umsg.Start( "PlayerKilledNPC" )
+ net.Start( "PlayerKilledNPC" )
- umsg.String( ent:GetClass() )
- umsg.String( InflictorClass )
- umsg.Entity( attacker )
+ net.WriteString( ent:GetClass() )
+ net.WriteString( InflictorClass )
+ net.WriteEntity( attacker )
- umsg.End()
+ net.Broadcast()
return
end
end
- umsg.Start( "NPCKilledNPC" )
+ net.Start( "NPCKilledNPC" )
- umsg.String( ent:GetClass() )
- umsg.String( InflictorClass )
- umsg.String( AttackerClass )
+ net.WriteString( ent:GetClass() )
+ net.WriteString( InflictorClass )
+ net.WriteString( AttackerClass )
- umsg.End()
+ net.Broadcast()
end
@@ -126,6 +126,11 @@ function GM:PlayerSilentDeath( Victim )
end
+-- Pool network strings used for PlayerDeaths.
+util.AddNetworkString("PlayerKilledSelf")
+util.AddNetworkString("PlayerKilledByPlayer")
+util.AddNetworkString("PlayerKilled")
+
--[[---------------------------------------------------------
Name: gamemode:PlayerDeath( )
Desc: Called when a player dies.
@@ -156,35 +161,35 @@ function GM:PlayerDeath( Victim, Inflictor, Attacker )
if (Attacker == Victim) then
- umsg.Start( "PlayerKilledSelf" )
- umsg.Entity( Victim )
- umsg.End()
+ net.Start( "PlayerKilledSelf" )
+ net.WriteEntity( Victim )
+ net.Broadcast()
MsgAll( Attacker:Nick() .. " suicided!\n" )
return end
if ( Attacker:IsPlayer() ) then
- umsg.Start( "PlayerKilledByPlayer" )
+ net.Start( "PlayerKilledByPlayer" )
- umsg.Entity( Victim )
- umsg.String( Inflictor:GetClass() )
- umsg.Entity( Attacker )
+ net.WriteEntity( Victim )
+ net.WriteString( Inflictor:GetClass() )
+ net.WriteEntity( Attacker )
- umsg.End()
+ net.Broadcast()
MsgAll( Attacker:Nick() .. " killed " .. Victim:Nick() .. " using " .. Inflictor:GetClass() .. "\n" )
return end
- umsg.Start( "PlayerKilled" )
+ net.Start( "PlayerKilled" )
- umsg.Entity( Victim )
- umsg.String( Inflictor:GetClass() )
- umsg.String( Attacker:GetClass() )
+ net.WriteEntity( Victim )
+ net.WriteString( Inflictor:GetClass() )
+ net.WriteString( Attacker:GetClass() )
- umsg.End()
+ net.Broadcast()
MsgAll( Victim:Nick() .. " was killed by " .. Attacker:GetClass() .. "\n" )
@@ -1,6 +1,6 @@
-require ( "usermessage" )
require ( "timer" )
+require ( "net" )
module( "undo", package.seeall )
@@ -58,18 +58,18 @@ if ( CLIENT ) then
AddUndo
Called from server. Adds a new undo to our UI
-----------------------------------------------------------]]
- local function AddUndo( message )
+ local function AddUndo()
- local k = message:ReadLong();
- local v = message:ReadString();
+ local k = net.ReadInt(16);
+ local v = net.ReadString();
table.insert( ClientUndos, 1, { Key = k, Name = v } )
MakeUIDirty()
end
- usermessage.Hook( "AddUndo", AddUndo )
+ net.Receive( "Undo_AddUndo", AddUndo )
--[[---------------------------------------------------------
@@ -78,9 +78,9 @@ if ( CLIENT ) then
has been undone or made redundant. We act by updating
out data (We wait until the UI is viewed until updating)
-----------------------------------------------------------]]
- local function Undone( message )
+ local function Undone()
- local key = message:ReadLong();
+ local key = net.ReadInt(16);
local NewUndo = {}
local i = 1
@@ -99,7 +99,7 @@ if ( CLIENT ) then
end
- usermessage.Hook( "Undone", Undone )
+ net.Receive( "Undo_Undone", Undone )
--[[---------------------------------------------------------
MakeUIDirty
@@ -166,6 +166,9 @@ local PlayerUndo = {}
local Current_Undo = nil
+util.AddNetworkString("Undo_Undone")
+util.AddNetworkString("Undo_AddUndo")
+
--[[---------------------------------------------------------
GetTable
Returns the undo table for whatever reason
@@ -294,9 +297,9 @@ local function SendUndoneMessage( ent, id, ply )
-- For further optimization we could queue up the ids and send them
-- in one batch ever 0.5 seconds or something along those lines.
- umsg.Start( "Undone", ply )
- umsg.Long( id )
- umsg.End()
+ net.Start( "Undo_Undone" )
+ net.WriteInt( id, 16 )
+ net.Send( ply )
end
@@ -316,10 +319,10 @@ function Finish( NiceText )
NiceText = NiceText or Current_Undo.Name
- umsg.Start( "AddUndo", Current_Undo.Owner )
- umsg.Long( id )
- umsg.String( NiceText )
- umsg.End()
+ net.Start( "Undo_AddUndo" )
+ net.WriteInt( id, 16 )
+ net.WriteString( NiceText )
+ net.Send( Current_Undo.Owner )
-- Have one of the entities in the undo tell us when it gets undone.
if ( Current_Undo.Entities[1] ) then
@@ -405,9 +408,9 @@ local function CC_UndoLast( pl, command, args )
local count = Do_Undo( last )
- umsg.Start( "Undone", pl )
- umsg.Long( lastk )
- umsg.End()
+ net.Start( "Undo_Undone" )
+ net.WriteInt( lastk, 16 )
+ net.Send( pl )
PlayerUndo[ index ][ lastk ] = nil

0 comments on commit af6a57b

Please sign in to comment.