Hébergeur de fichiers indépendant

MountSafe.lua

À propos du fichier

Type de fichier
Fichier LUA de 15 Ko (text/plain)
Confidentialité
Fichier public, envoyé le 26 octobre 2014 à 13:38, depuis l'adresse IP 86.214.x.x (France)
Sécurité
Ne contient aucun Virus ou Malware connus - Dernière vérification: 21 heures
Statistiques
La présente page de téléchargement a été vue 1075 fois depuis l'envoi du fichier
Page de téléchargement

Aperçu du fichier


--[[---------------------------------------------------------------------------------------------
MountSafe Emotes

Wildstar has many animated emotes. Like other MMOs, these both animate the character and display 
some emote text in the chat log. Like many other MMOs, Wildstar cannot display the animations 
when the character is mounted. Unlike other MMOs, Wildstar doesn't even bother to output the chat
text if the character is mounted. This means, for example, that typing /wave (or using a hotkey
bound to a macro that says "/wave") will do *nothing* if you're on a ground mount or hoverboard,
even though the emote text would work fine (and, in the case of /wave, the upper body animation 
would work fine on a hoverboard).

MountSafe Emotes introduces a new command "/mountsafe" (and its shorter alias, "/ms"), which 
takes one argument: the name of an animated emote. If the character is not mounted, the emote
is deferred to the standard command interpreter, which causes the whole shebang of animating
and displaying text to happen. If the character *is* mounted, MountSafe spits out some emote
text which is very similar to what the command interpreter would do. 

Why "very similar"? The built-in command interpreter (ChatSystemLib, a hosting API whose details 
are not visible to us in the scripting world) can do at least two things we can't: It can display 
emote text with arbitrary syntax, whereas we have to use the form "<character name> <arbitrary text>",
and it can display different text to other people ("Reys waves.") than it does to the emoting 
character ("You wave."). Consequently, MountSafe can only approximate the output.

The output text needs to vary in two ways: If the user has a target, many of the emotes use the 
target name, and some emotes need the emoting character's gender to form appropriate pronouns.
It is possible that some emotes would need the target's gender, but none of the existing emotes
as of 1.0.9.6780 require this.

Since the character's gender is used, Chua present some problems. The two obvious answers are 
to use the neuter possessive pronoun ("its") or (and this is my preference) the singular neuter 
plural("their"). However, Wildstar's buit-in emotes use the masculine ("his"), so that's what
MountSafe does.

-----------------------------------------------------------------------------------------------
Changelog
	* 1.1.fr 2014.10.26 - French adaptation (hardcoded)
	* 1.1 - 2014.09.28 - First release version. 
					   - Name changed from "MountSafe" to "MountSafe Emotes"
					   - General prettying up so I can make changes later if I haven't seen the 
						 code in a while.
	* 1.0 - 2014.07.27 - Initial beta upload, accidentally tagged as 1.0 instead of 0.9
----------------------------------------------------------------------------------------------- --]]

require "ChatSystemLib"
 
-----------------------------------------------------------------------------------------------
-- MountSafe Module Definition
-----------------------------------------------------------------------------------------------
local MountSafe = {} 
 
-----------------------------------------------------------------------------------------------
-- Constants
local kVersion = "1.1"

-- GameLib.GetPlayerUnit():GetGender() returns kGender.Male or kGender.Female
local kGender = {Male = 0, Female = 1, Chua = 2}

-- Magic number for Chua for GetRaceId()
local kRaceChua = 13

local kPronouns = {Possessive = {[kGender.Male] = "his", [kGender.Female] = "her", [kGender.Chua] = "their"}}

local kMessages = 
{
	-- Tagline   = "MountSafe Emotes: Emotes that work even when you're mounted. Version "..kVersion,
	-- Usageline = "Use '/ms <emote>'. Use '/ms' by itself for a list of supported emotes."
	-- FR description and usage
	Tagline   = "MountSafe Emotes: des emotes qui fonctionnent même sur votre monture ! Version "..kVersion,
	Usageline = "Utilisation : '/ms <emote>'. Lancez '/ms' sans paramètres pour obtenir la liste des emotes supportés."
}

-- Constants for replacement strings make the string literals longer, but easier to read.
local kRep = 
{
	nl  = "\n",	-- Newline constant
	tar = "$t", -- Target name
	pos = "$p", -- Possessive pronoun replacement token
}

--[[
	An emote is:
		name			(string)
		mountedtext 	(table)
			targeted	(string)
			untargeted	(string)
			
	Replacements:
		$t 	Target name
		$p 	Player's possessive pronoun (his/her/their/its)
--]]

-- FR ktEmotes translation
local ktEmotes = 
{
	non      = {targeted = "secoue la tête en regardant "..kRep.tar..". Non !",         untargeted = "secoue la tête. Non !"},
	oui      = {targeted = "hoche la tête en regardant "..kRep.tar..". Oui !",          untargeted = "hoche la tête. Oui !"},
	
	applaudir = {targeted = "applaudit "..kRep.tar..".",                                untargeted = "applaudit"},
	clap = {targeted = "applaudit "..kRep.tar..".",                                     untargeted = "applaudit"},
	
	acclamer = {targeted = "acclame "..kRep.tar.." !",                                  untargeted = "pousse une acclamation !"},
	hourra   = {targeted = "acclame "..kRep.tar.." !",                                  untargeted = "pousse une acclamation !"},
	
	pleurer  = {targeted = "pleure en regardant "..kRep.tar.."",                        untargeted = "pleure."},
	triste   = {targeted = "fait une pause pour se remettre de ses émotions.",          untargeted = "fait une pause pour se remettre de ses émotions."},
	
	danser   = {targeted = "danse allègrement pour "..kRep.tar..".",                    untargeted = "danse allègrement."},
	danser3  = {targeted = "danse allègrement pour "..kRep.tar..".",                    untargeted = "danse allègrement."},
	danser2  = {targeted = "danse frénétiquement pour "..kRep.tar..".",                 untargeted = "danse frénétiquement."},
	
	trembler = {targeted = "tremble de peur devant "..kRep.tar..".",                    untargeted = "tremble de peur."},
	peur     = {targeted = "tremble de peur devant "..kRep.tar..".",                    untargeted = "tremble de peur."},

	adieu    = {targeted = "fait un signe d'adieu à "..kRep.tar..".",                   untargeted = "fait un signe d'adieu."},
	salut    = {targeted = "salue "..kRep.tar.." de la main.",                          untargeted = "salue de la main."},
	aurevoir = {targeted = "salue "..kRep.tar.." de la main.",                          untargeted = "salue de la main."},
	
	-- shout    = {targeted = "shouts at "..kRep.tar..".",                                 untargeted = "shouts with vigor."},
	discuter = {targeted = "discute avec "..kRep.tar..".",                              untargeted = "discute avec tout le monde."},
	frimer   = {targeted = "roule des mécaniques devant "..kRep.tar..".",               untargeted = "roule des mécaniques devant tout le monde."},
	genoux   = {targeted = "s'agenouille devant "..kRep.tar..".",                       untargeted = "s'agenouille respectueusement."},
	montrer  = {targeted = "montre "..kRep.tar.." du doigt.",                           untargeted = "pointe le doigt vers l'horizon."},
	epaules  = {targeted = "hausse les épaules en regardant "..kRep.tar..".",           untargeted = "hausse les épaules."},
	salut    = {targeted = "salue "..kRep.tar.." de la main.",                          untargeted = "salue de la main."},
	signe    = {targeted = "fait signe à "..kRep.tar..". Par ici !",                    untargeted = "fait signe à tout le monde. Par ici !"},
	s_incliner = {targeted = "s'incline devant "..kRep.tar..".",                        untargeted = "s'incline."},
	rire     = {targeted = "éclate de rire en regardant "..kRep.tar..".",               untargeted = "rit."},
	saluer   = {targeted = "salue "..kRep.tar..".",                                     untargeted = "salue."},
	dormir   = {targeted = "s'ennuie tellement avec "..kRep.tar.." qu'il s'endort.",    untargeted = "fait un somme."},
	boire    = {targeted = "lève son verre pour "..kRep.tar..". Santé !",               untargeted = "lève son verre pour tout le monde. Santé !"},
	manger   = {targeted = "tente "..kRep.tar.." avec sa nourriture délicieuse.",       untargeted = "prend une grande bouchée de nourriture succulente. Miam !"},
	debout   = {targeted = "se lève devant "..kRep.tar..".",                            untargeted = "se lève."},
	assis    = {targeted = "s'assoit devant "..kRep.tar..".",                           untargeted = "s'assoit."},
	hocher   = {targeted = "hoche la tête en regardant "..kRep.tar..".",               untargeted = "hoche la tête."},

	souillure = {targeted   = "supplie "..kRep.tar.." de l'aider alors qu'une créature de la souillure jaillit violement de sa poitrine !", 
				untargeted = "appelle à l'aide alors qu'une créature de la souillure jaillit violement de sa poitrine !"},
}
 
-----------------------------------------------------------------------------------------------
-- Initialization
-----------------------------------------------------------------------------------------------
function MountSafe:new(o)
    o = o or {}
    setmetatable(o, self)
    self.__index = self 

    return o
end

function MountSafe:Init()
	local bHasConfigureFunction = false
	local strConfigureButtonText = ""
	local tDependencies = {}
    Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies)
end
 

-----------------------------------------------------------------------------------------------
-- MountSafe OnLoad, called by Apollo after RegisterAddon.
-----------------------------------------------------------------------------------------------
function MountSafe:OnLoad()
	-- Register handlers for events, slash commands and timer, etc.
	-- e.g. Apollo.RegisterEventHandler("KeyDown", "OnKeyDown", self)
	Apollo.RegisterSlashCommand("mountsafe", "OnSlashMountSafe", self)
	Apollo.RegisterSlashCommand("ms",        "OnSlashMountSafe", self)
	Apollo.RegisterEventHandler("InterfaceMenuListHasLoaded", "OnInterfaceMenuListHasLoaded", self)
end

-----------------------------------------------------------------------------------------------
-- OnInterfaceMenuListHasLoaded
--TODO: Why are we using this event? Is there a better way to make sure the chat system is up and running?
-- Chose this event because it's what EntSpy uses and that always seems to work for me, but it is kind of 
-- messy to have this just for the one line.
-----------------------------------------------------------------------------------------------
function MountSafe:OnInterfaceMenuListHasLoaded()
	-- On load (logging in only, sadly, not after a /reloadui), send a message to the chat log 
	-- letting the user know it's running and reminding them what the syntax is. Nothing too spammy.
	self:MessageOut(kMessages.Tagline..kRep.nl..kMessages.Usageline)
end

-----------------------------------------------------------------------------------------------
-- MountSafe Command Line
-- Slash Command: "/mountsafe" or "/ms"
-----------------------------------------------------------------------------------------------
function MountSafe:OnSlashMountSafe(strCommand, strEmote)
	-- If the user entered just "/ms", show some help and bail out.
	if strEmote == nil or strEmote == "" then
		self:ShowHelp()
		return
	end

	-- Okay, get the rest of the command tail. First, clean it up so "/ms wave " works (trim trailing whitespace)
	strEmote = self:Trim(strEmote)
	strEmote = string.gsub(strEmote,"\'","_") -- FR quote taken into account
	
	-- The emotes table (ktEmotes) is keyed on the emote name.
	local emote = ktEmotes[strEmote]
	if emote ~= nil then
		if GameLib.GetPlayerUnit():IsMounted() then
			-- Mounted
			if GameLib.GetPlayerUnit():GetTarget() == nil then
				-- Mounted and Targeted
				strEmote = self:DecodeString(emote.untargeted)
			else
				-- Mounted and Untargeted
				strEmote = self:DecodeString(emote.targeted)
			end
		else
			-- Not mounted, so pass the command on to the chat interpreter as a command. Let it handle any errors
			-- Note that this means that, for now, the emote key (the part you type) has to be exactly the same as the built-in emote
			strEmote = "/"..strEmote -- There is a call to get the forward slash from Apollo. Maybe should use it?
		end
		ChatSystemLib.Command(strEmote)
	else
		-- Error. They passed some text we don't understand
		self:ErrorOut("Unknown MountSafe emote '"..strEmote.."'")
	end
end

-----------------------------------------------------------------------------------------------
-- Internal methods
-----------------------------------------------------------------------------------------------
-- Using Realm messages for general info to the user
function MountSafe:MessageOut(str)
	ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Realm, str)
end

-- Debug channel for errors
function MountSafe:ErrorOut(str)
	ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Debug, "MountSafe: "..str)
end

-- Replaces substitution tokens with appropriate ones based on character target and gender
-- Also prepends "/emote " to make it a legal command. This also makes the character name
-- come out in a different color, be context-clickable, etc.
function MountSafe:DecodeString(strSource)
	local strRet = strSource
	
	-- Replace $t with the target name (if any)
	local target = GameLib.GetPlayerUnit():GetTarget()
	if target ~= nil then
		strRet = string.gsub(strRet, kRep.tar, target:GetName())
	end
	
	
	
	-- Get the possessive pronoun.
	local gender = GameLib.GetPlayerUnit():GetGender()
	
	--[[ Disabled for now. The game treats all Chua as male for the purpose of emotes, so sticking with that until I think of something better :-(
	-- Handle Chua as a special case.
	local race   = GameLib.GetPlayerUnit():GetRaceId()
	if race == kRaceChua then
		gender = kGender.Chua
	end
	--]]
	
	-- Replace $p with the possessive pronoun
	strRet = string.gsub(strRet, kRep.pos, kPronouns.Possessive[gender])
	
	-- Prepend the emote command so it comes out as as close to what we want as we know how to get
	return "/émote "..strRet -- FR slash command /emote
end

-- Whitespace trimming function copied from Programming in Lua. It's a touch overkill since we "know" that left whitespace has been trimmed
-- by the command interpreter and it's a little odd because we aren't worrying about spaces within the parameters ("/ms wave at joe"), but it's passable.
function MountSafe:Trim(s)
  return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end

function MountSafe:ShowHelp()
	-- Concat a list of emotes together. There is probably a much easier way to do this. Doesn't Lua have a specific command for it?
	local strEmotes = ""
	for k, _ in pairs(ktEmotes) do
		if string.len(strEmotes) > 0 then
			strEmotes = strEmotes..", "
		end
		strEmotes = string.gsub(strEmotes,"_","\'") -- FR quote
		strEmotes = strEmotes..k
	end
	
	self:MessageOut(kMessages.Tagline..kRep.nl..kMessages.Usageline..kRep.nl.."Supported emotes: "..strEmotes)
end

-----------------------------------------------------------------------------------------------
-- MountSafe Instance
-----------------------------------------------------------------------------------------------
local MountSafeInst = MountSafe:new()
MountSafeInst:Init()


Partager le fichier MountSafe.lua sur le Web et les réseaux sociaux:


Télécharger le fichier MountSafe.lua


Télécharger MountSafe.lua