Page 1 of 1

Execution of actions when a message

Posted: Thu Aug 29, 2013 9:49 pm
by jester
Please help with the code:

Code: Select all

function AutoAutoUse_OnLoad(this)
this:RegisterEvent("CHAT_MSG_WHISPER");
DEFAULT_CHAT_FRAME:AddMessage("Addon loaded: AutoUse",0,255,255);
end; 

function AutoAutoUse_OnEvent(this, event) 
if event == "CHAT_MSG_WHISPER" then 
s = arg1; if(string.find( s, "UseIt") ) then arg1=arg1 .. "|cffff0000 *UseIt*"; UseSkill(1,1);
end; 
end;
end;
The purpose of this message is received, the character must perform a certain action, but he does not want to do: (
Does anyone have thoughts on this?

Re: Execution of actions when a message

Posted: Thu Aug 29, 2013 11:23 pm
by lisa
ok firstly moved.

function AutoAutoUse_OnEvent(this, event)
if event == "CHAT_MSG_WHISPER" then
s = arg1; if(string.find( s, "UseIt") ) then arg1=arg1 .. "|cffff0000 *UseIt*"; UseSkill(1,1);
end;
end;
end;

s = arg1?
since there is no "arg1", s would always be nil.

"this" is actually your first agument.

If in doubt about anything add in prints, it willo help you work out any issues, in terms of an addon you can just use

Code: Select all

SendSystemChat("msg")
in terms of bot you can use

Code: Select all

print("msg")
Try something like this

Code: Select all

function AutoAutoUse_OnEvent(this, event) 
if event == "CHAT_MSG_WHISPER" then 
SendSystemChat(this)
if(string.find( this, "UseIt") ) then UseSkill(1,1) SendSystemChat("Using skill 1") end 
end
end
Although I don't understand why you want to change the texted value of the first argument and not use it.

Re: Execution of actions when a message

Posted: Fri Aug 30, 2013 12:15 am
by jester
Whisper is visible in the message box, but UseSkill(1,1) fails and the message "Using skill 1" does not appear ...

Re: Execution of actions when a message

Posted: Fri Aug 30, 2013 5:22 pm
by lisa
Ok I had a closer look at your code, you need to replace the _ with . in the function name.
Basically it is a table for the Addon and the OnLoad and OnEvent are part of the table.

Code: Select all

function AutoAutoUse.OnLoad(this)

function AutoAutoUse.OnEvent(this, event) 
Here is my madman addon you can use as a template.

Notice the
madman = {};
and then everything else is
madman.

You also need to make sure you have a .xml file that initiates the actual event code.

Code: Select all


--=== madman by Lisa ===--


-----------Initialize Variables-----------
madman = {};
madman_Settings = {};
madman.ismadmanInitialized = false;
madman.playerName = "";      
madman.TotalCount = 150;
madman.CountDown = TotalCount;
madman.EndCount = 1;
madman.DeciTime = 0;
madman.Reset = false;
madman.Time = 0
mm_once = false

-----------Constants-----------
madman.PLUGIN_NAME 	= "madman";
madman.PLUGIN_VERSION	= 1.2;
madman.PLUGIN_CREDIT	= "Lisa";
madman.PLUGIN_TITLE 	= madman.PLUGIN_NAME .. " " .. madman.PLUGIN_VERSION .. " (by " ..madman.PLUGIN_CREDIT .. ")";

-----------read language file-----------
madman.curLocal = string.sub(GetLanguage():upper(), 1,2);
local localeFileName = "Interface/AddOns/madman/Locales/madman."..string.upper(madman.curLocal)..".lua";
local func, err = loadfile(localeFileName);
if (err) then
	dofile("Interface/AddOns/madman/Locales/madman.EN.lua");
else
	dofile(localeFileName);
end 

-----------Minimap Buttons-----------
function madman.MinimapButton_OnClick(this)
	if ( madmanConfig:IsVisible() ) then
		HideUIPanel(madmanConfig);
	else
		ShowUIPanel(madmanConfig);
	end
end

function madman.MinimapButton_OnEnter(this)
    GameTooltip:SetOwner(this, "ANCHOR_LEFT", 4, 0);
	GameTooltip:SetText(PLUGIN_TITLE, 1, 1, 1);
	GameTooltip:AddLine(UI_MINIMAPBUTTON_MOVE, 0, 0.75, 0.95);
	GameTooltip:Show();
end

-----------Register Events-----------
function madman.OnLoad(this)
    SaveVariables("madman_Settings");
	this:RegisterEvent("CHAT_MSG_SAY");
    this:RegisterEvent("VARIABLES_LOADED");
	this:RegisterEvent("UNIT_PORTRAIT_UPDATE"); --used, if it was for some reason impossible to get the playername after variables loaded 
end

--------- <OnEvent> ---------
function madman.OnEvent(event, this)
	if (event == "VARIABLES_LOADED") then
  		madman.CheckSettingsLoaded();
		if (AddonManager) then
			local addon = {
							name = madman.PLUGIN_NAME,
							version = madman.PLUGIN_VERSION,
							author = madman.PLUGIN_CREDIT,
							description = madman_Locales["DESCRIPTION"],
							icon = "Interface/AddOns/madman/Textures/cm_normal.tga",
							category = "Information",
							configFrame = madmanConfig,
							slashCommands = "/mm",
							miniButton = madman_AOMButton
			};
			if (AddonManager.RegisterAddonTable) then
				AddonManager.RegisterAddonTable(addon);
			else
				AddonManager.RegisterAddon(addon.name, addon.description, addon.icon, addon.category, addon.configFrame, addon.slashCommands, addon.miniButton, addon.version, addon.author);
			end;
			HideUIPanel(madman_MinimapButton);
		else
        	DEFAULT_CHAT_FRAME:AddMessage(string.format(madman_Locales["PLUGINLOADED"], madman.PLUGIN_TITLE), 0.5, 0.7, 1.0);
		end;
	elseif ( event == "UNIT_PORTRAIT_UPDATE" and arg1 == "player" ) then
		if ( madman.ismadmanInitialized ~= true ) then
			madman.CheckSettingsLoaded();
		end
	elseif  event == "CHAT_MSG_SAY" then
		madman.Chat(event,this);
	end
end

--------- <Default Settings> ---------
function madman.CheckSettingsLoaded()
    if ( madman.ismadmanInitialized == true ) then
      return;
    end
         
	madman.playerName = UnitName("player");
	if ( madman.playerName == nil or madman.playerName == "" ) then
		return;
	end
	
	local DefaultSettings = {
    	["KeyWordCheck1"] = true,
    	["KeyWord1"] = "crush you",
	};
	
	if(madman_Settings[madman.playerName] == nil) then
      madman_Settings[madman.playerName] = {};
	end

	for k,v in pairs(DefaultSettings) do
		if (madman_Settings[madman.playerName][k] == nil) then
      		madman_Settings[madman.playerName][k] = v;
		end
	end
	madman.ismadmanInitialized = true;
	DEFAULT_CHAT_FRAME:AddMessage(string.format(madman_Locales["SETTINGSLOADED"], madman.PLUGIN_TITLE, madman.playerName), 0.5, 0.7, 1.0);
end


-----------Show Config Window-----------
function madman.OnShow()
  --fill window with current settings.
	
    madmanConfigTitleFrame_Title:SetText(madman.PLUGIN_TITLE);  
	madmanConfig_Save:SetText(madman_Locales["SAVE"]);
    madmanConfigBackdropFrame_SettingsInfo:SetText(string.format(madman_Locales["SETTINGSFORCHAR"], madman.playerName));
    madmanConfigBackdropFrame_TitleKeywords:SetText(madman_Locales["KEYWORDS"]);
    
	madmanConfig_KeyWordCheck1:SetChecked(madman_Settings[madman.playerName]["KeyWordCheck1"]);
	madmanConfig_KeyWord1:SetText(madman_Settings[madman.playerName]["KeyWord1"]);

end

-----------SaveSettings-----------
function madman.SaveSettings() 
	local NewSettings = {
    	["KeyWordCheck1"] = madmanConfig_KeyWordCheck1:IsChecked(),
    	["KeyWord1"] = madmanConfig_KeyWord1:GetText(),

	};

	for k,v in pairs(NewSettings) do
      	madman_Settings[madman.playerName][k] = v;
	end
	
	DEFAULT_CHAT_FRAME:AddMessage(string.format(madman_Locales["SETTINGSSAVED"], madman.PLUGIN_TITLE, madman.playerName), 0.5, 0.7, 1.0);
end

-----------Handle Tooltips-----------
function madman.Tooltip(this, type)
    GameTooltip:SetOwner(this, "ANCHOR_RIGHT", 4, 0);
	if(type=="checkbox") then
		GameTooltip:SetText(madman_Locales["CHECKBOXTOOLTIP"], 0, 0.75, 0.95);
	elseif(type=="keyword") then
		GameTooltip:SetText(madman_Locales["KEYWORDTOOLTIP"], 0, 0.75, 0.95);
	elseif(type=="save") then
		GameTooltip:SetText(madman_Locales["SAVETOOLTIP"], 0, 0.75, 0.95);
	end
	GameTooltip:Show();
end


-----------Check Chat ------------------
function madman.Chat(event,this)
	if(madman.ismadmanInitialized) then
		local docheck = false;
		if(event == "CHAT_MSG_SAY")then
			docheck = true;                                                             
		end
		
		if (docheck) then
			local var = string.lower(arg1);

  			if(madman_Settings[madman.playerName]["KeyWordCheck1"] and (madman_Settings[madman.playerName]["KeyWord1"] ~= nil or madman_Settings[madman.playerName]["KeyWord1"] ~= "")) then
  				if(string.find(var,string.lower(madman_Settings[madman.playerName]["KeyWord1"])) ~= nil) then
 					if arg4 ~= madman.playerName then
						madman.Time = 1
						SendSystemChat("moving forward")
						MoveForwardStart(); 
						madman.WarningText(madman_Settings[madman.playerName]["KeyWord1"]);
					end
  				end
  			end 
  		end
  	end
end
  

-----------show WarningText-----------
function madman.WarningText(warningtext)
	if(madman_Settings[madman.playerName]["ShowTextCheck"]) then
		madman_WarningText:SetText("|cffff9900"..warningtext);
		madman.FadeFired = true;
		madman.Reset = true;
		madman_WarningFrame:SetAlpha(1);
	end
end

-----------fade WarningText-----------
function madman.Warning_Tick()
	if madman.CountDown >= madman.EndCount then
		madman.DeciTime = madman.CountDown/madman.TotalCount;
		if madman.DeciTime <= 0.5 then
			madman.DeciTime = madman.DeciTime*2;
			madman_WarningFrame:SetAlpha(madman.DeciTime);
		end
	else
		madman.FadeFired = false;
		madman.CountDown = madman.TotalCount;
		madman_WarningFrame:SetAlpha(0);
	end
	if madman.Reset then
		madman.CountDown = madman.TotalCount;
		madman_WarningFrame:SetAlpha(1);
		madman.Reset = false;
	else
		madman.CountDown = madman.CountDown - 1;
	end
end

function mm_OnUpdate(frame, elapsedTime)
	if madman.Time >= 1 then
		madman.Time = madman.Time + elapsedTime
	end
	if madman.Time >= 5 and mm_once == false then
		MoveForwardStop();
		mm_once = true
	end
	if madman.Time >= 7 and mm_once == true then
		madman.Time = 0
		mm_once = false
	end
end


Re: Execution of actions when a message

Posted: Mon Sep 02, 2013 6:10 am
by jester
Lisa, Your addon works flawlessly!
Here's what I changed it to monitor messages in the group:

Code: Select all

-----------Register Events-----------
function madman.OnLoad(this)
    SaveVariables("madman_Settings");
	this:RegisterEvent("CHAT_MSG_PARTY");
           this:RegisterEvent("VARIABLES_LOADED");
	this:RegisterEvent("UNIT_PORTRAIT_UPDATE");
end
This works. But the following change notraatyvaet not all actions ...

Code: Select all

-----------Check Chat ------------------
function madman.Chat(event,this)
	if(madman.ismadmanInitialized) then
		local docheck = false;
		if(event == "CHAT_MSG_PARTY")then
			docheck = true;                                                             
		end
		
		if (docheck) then
			local var = string.lower(arg1);

  			if(madman_Settings[madman.playerName]["KeyWordCheck1"] and (madman_Settings[madman.playerName]["KeyWord1"] ~= nil or madman_Settings[madman.playerName]["KeyWord1"] ~= "")) then
  				if(string.find(var,string.lower(madman_Settings[madman.playerName]["KeyWord1"])) ~= nil) then
 					if arg4 ~= madman.playerName then
						madman.Time = 1
--						SendSystemChat("moving forward")
						TargetNearestFriend();
--						UseSkill(1,1);      
						--ExecuteMacroLine("/cast Attack")
						--dofile('test.lua')

						local icnum,name,body=GetMacroInfo(43)
						if string.find(body,"^/") then -- Should be slash command
							ExecuteMacroLine(body)
						madman.WarningText(madman_Settings[madman.playerName]["KeyWord1"]);
					end
  				end
  			end 
  		end
  	end
end
TargetNearestFriend(); - as befits the NPC takes to the Target
But UseSkill(1,1); still does not and does not give the error ... I even tried to use

Code: Select all

ExecuteMacroLine("/cast Attack")
dofile('test.lua')
which prescribed the use of all possible skill Attack and is located in the cell 34 (in the game, the macro runs when manually pressed)
can tell the future direction or where I admit a mistake?

Re: Execution of actions when a message

Posted: Mon Sep 02, 2013 6:30 am
by Cindy
you realize your Useskill line is commented out, right?

Re: Execution of actions when a message

Posted: Mon Sep 02, 2013 7:11 am
by jester
Yeah, right. Just this last code after a series of experiments, and is currently trying to run code from an external file by calling its function dofile ()

Re: Execution of actions when a message

Posted: Mon Sep 02, 2013 7:17 am
by rock5
I'm not 100% sure how it works, but I think UseSkill will only work if a button is pressed. The bot can execute it because it simulates a keypress to run macros. You can't simulate keypresses from a game addon.

Re: Execution of actions when a message

Posted: Mon Sep 02, 2013 8:05 am
by jester
Then what is the difference with the Russian servermo? there I used to pass the quest script from dofile

Code: Select all

CastSpellByName("Атаковать")  <--("Attack")
OnClick_QuestListButton(1, 1)
AcceptQuest()
CompleteQuest();
OnClick_QuestListButton(1, 1)
CastSpellByName("Атаковать") <--("Attack")
AcceptQuest()
CompleteQuest();
though ... There I used the autoclicker ... so my idea will fail at 100%?

Re: Execution of actions when a message

Posted: Mon Sep 02, 2013 6:56 pm
by lisa
yeah you need a "click" or "press" in order to make macros/addons use skills.

Re: Execution of actions when a message

Posted: Mon Sep 02, 2013 8:43 pm
by jester
lisa wrote:yeah you need a "click" or "press" in order to make macros/addons use skills.
but really make such addon?

Re: Execution of actions when a message

Posted: Fri Sep 06, 2013 3:31 am
by jester
On today found a unique solution - an open window with the NPC to do:

Code: Select all

OnClick_QuestListButton(3, 1)
AcceptQuest()
CompleteQuest()
OnClick_QuestListButton(2, 1)
AcceptQuest()
CompleteQuest()
OnClick_QuestListButton(1, 1)
AcceptQuest()
CompleteQuest()

Re: Execution of actions when a message

Posted: Fri Sep 06, 2013 4:43 am
by rock5
Yes, but the problem is you can't open a dialog with an npc via an addon.

Anyway, you are not understanding 'OnClick_QuestListButton'. The first number is the type of quest (not accepted, accepted but not complete and complete). So if you want to accept the first unaccepted quest you do.

Code: Select all

OnClick_QuestListButton(1,1)
AcceptQuest()
I you want to complete the first completed quest then you do

Code: Select all

OnClick_QuestListButton(3,1)
CompleteQuest()
For more information check out http://runesofmagic.gamepedia.com/API:O ... ListButton

Re: Execution of actions when a message

Posted: Mon Sep 23, 2013 11:56 pm
by jester
Prompt please even such a thing - as of the addon to get a message to the chat group on the number of daily quest?