From ffe67db5e4b773d02b269d561426e51860222456 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 30 Nov 2014 17:01:58 +0000 Subject: [PATCH] Added new entity info_custommessage Allows map editors to concatenate a sequence of strings and then displays it using one of the pre-existing messaging entities, useful for A = B/C messages. Keys: displayentity(targetname) : The entity used to display the message, can be a targetname of a class game_text, point_worldhint or point_zsmessage zsmessagemode(choices) : If using a point_zsmessage, select the method of display with this key "0" : "Centred HUD Message" "1" : "Corner Human HUD Message" "2" : "Corner Zombie HUD Message" string01(string) : Part 01 of the full string string##(string) : Part ## of the full string, there can be up to 99 of these. Inputs: displaystrings(string): Concatenates and displays the full string using the attached entity setstring##(string) : Sets part ## of the full string, there can be up to 99 of these. Outputs: OnDisplayed : Called when the message has successfully displayed. --- .../entities/info_custommessage/init.lua | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 gamemodes/zombiesurvival/entities/entities/info_custommessage/init.lua diff --git a/gamemodes/zombiesurvival/entities/entities/info_custommessage/init.lua b/gamemodes/zombiesurvival/entities/entities/info_custommessage/init.lua new file mode 100644 index 0000000..6b55e56 --- /dev/null +++ b/gamemodes/zombiesurvival/entities/entities/info_custommessage/init.lua @@ -0,0 +1,69 @@ +ENT.Type = "point" + +function ENT:Initialize() + if not self.Initialized then -- Why is KeyValue() called before Initialize()? + self.PartStrings = {} + self.Initialized = true + self.DisplayTarget = self.DisplayTarget or "" + self.ZSMessageMode = self.ZSMessageMode or 0 + end +end + +function ENT:Think() +end + +function ENT:DisplayStrings() + local FullString = "" + for k,v in pairs(self.PartStrings) do + FullString = FullString .. v + end + for k,v in pairs(ents.FindByName(self.DisplayTarget)) do + local EntityClass = v:GetClass() + if EntityClass == "game_text" then + v:Input("AddOutput", self, self, "message "..FullString) + v:Input("Display", self, self, FullString) + elseif EntityClass == "point_zsmessage" then + if self.ZSMessageMode == "1" then + v:Input("sethumanhudmessage", self, self, FullString) + elseif self.ZSMessageMode == "2" then + v:Input("setzombiehudmessage", self, self, FullString) + else + v:Input("message", self, self, FullString) + end + elseif EntityClass == "point_worldhint" then + v:Input("sethint", self, self, FullString) + end + end + self:Input("OnDisplayed", self, self, FullString) +end + +function ENT:AcceptInput(name, activator, caller, args) + name = string.lower(name) + if string.sub(name, 1, 2) == "on" then + self:FireOutput(name, activator, caller, args) + elseif string.sub(name, 1, 9) == "setstring" then + self:KeyValue(string.sub(name, 4,11),args) + elseif name == "displaystrings" then + self:DisplayStrings() + end +end + +function ENT:KeyValue(key, value) + key = string.lower(key) + if string.sub(key, 1, 6) == "string" then + if not self.Initialized then + self.PartStrings = {} + self.Initialized = true + end + local part = tonumber(string.sub(key,7,8)) + if part ~= nil then + self.PartStrings[part] = value + end + elseif key == "displayentity" then + self.DisplayTarget = value + elseif key == "zsmessagemode" then + self.ZSMessageMode = value + elseif string.sub(key, 1, 2) == "on" then + self:AddOnOutput(key, value) + end +end \ No newline at end of file