Name Highlighter v3

Share your scripts and packages with other Mudlet users.
User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Name Highlighter v3

Post by Rakon »

Denex, I have a modified version of Heiko's that works very well. Here's the base code for it

Script - hi-lighter:
Code: [show] | [select all] lua

function loadHL()
 if enemy_list == nil then enemy_list = {} end
 if friend_list == nil then  friend_list = {} end

 -- add in more lists here, if you feel like it. IE shallam_list, mhaldor_list

 if hl_nums == nil then 
  hl_nums = {}

  for i,v in ipairs(enemy_list) do
   if not hl_nums[v] then
    hl_nums[v] = tempTrigger( v ,[[hlEnemy(matches[1]) ]] )
   end
  end

  for i,v in ipairs(friend_list) do
   if not hl_nums[v] then
    hl_nums[v] = tempTrigger( v ,[[hlFriend(matches[1]) ]] )
   end 
  end

 --[[ For each list you create, you'll need a function that is like the following 
       list_name is the name of the list from above
       hlList is the actual COLOURING function for the list

  for i,v in ipairs(list_name) do
   if not hl_nums[v] then
    hl_nums[v] = tempTrigger( v ,[[hlList(matches[1]) ]] )
   end 
  end
 --]]
 end -- if hl_nums
end -- function

function hlFriend(who)
 local c = 1;
 local k = 1;
 while k > 0 do
  if c > 3 then break; end;
  k = string.find( line, who, k )
  if k == nil then return; end
  local nC = '';
  nC = string.match( line, '.',k+string.len(who) )
  if nC == '.' or nC == ',' or nC == ';' or nC == ':' or nC == ' ' or nC == "'" then
   k = selectString(who, c) 
   if k > -1 then
    c = c + 1;
    setFgColor(0,255,127);
    resetFormat();
   else
    return;	
   end
  end
  k = k + string.len(who);
 end
end


function hlEnemy( who )
 local c = 1;
 local k = 1;
 while k > 0 do
  if c > 3 then break; end;
  k = string.find( line, who, k )
  if k == nil then return; end
  local nC = '';
  nC = string.match( line, '.',k+string.len(who) )
  if nC == '.' or nC == ',' or nC == ';' or nC == ':' or nC == ' '  or nC == "'"  then
   k = selectString(who, c) 
   if k > -1 then
    c = c + 1;
    setFgColor(255,0,0);
	setItalics(true);
    resetFormat();
   else
    return;	
   end
  end
  k = k + string.len(who);
 end
end

--[[ Copy the above function, and change the 'setFgColor' and ' function  hl<your function/list name>'
Aliases :
Match, RegEx: ^(add|remove) (\w+) (from|to) (friends|enemies| <other cities/lists you create here>)$
Code:
Code: [show] | [select all] lua
local action = matches[2]
local who = matches[3]:title()
local where = matches[5]

-- Look below, and for each 'action', add in the lists/cities you made functions/lists for. IE, if where = 'mhaldor, if where = 'shallam'

if action == 'add' then
 if where == 'friends' then
  if not friend_list then friend_list = {} end
  if table.contains(friend_list,who) == false then
   table.insert(friend_list,who)
   hl_nums[who] = tempTrigger( who ,[[hlFriend(matches[1]) ]] )
   al_alert(string.format('%s added to %s!', who, where))
  else -- if
   al_alert(string.format('%s already in %s!', who, where))
  end -- if
 elseif where == 'enemies' then
  if not enemy_list then enemy_list = {} end
  if table.contains(enemy_list,who) == false then
   table.insert(enemy_list,who)
   hl_nums[who] = tempTrigger( who ,[[hlEnemy(matches[1]) ]] )
   al_alert(string.format('%s added to %s!', who, where))
  else -- if
   al_alert(string.format('%s already in %s!', who, where))
  end -- if
 end -- if
end -- if


if action == 'remove' then
 if where == 'friends' then
  if table.contains(friend_list,who) then
   table.remove(friend_list,tfind(friend_list,who))
   if hl_nums[who] then killTrigger(hl_nums[who])end
   al_alert(string.format('%s removed from %s!', who, where))
  else
   al_alert(string.format('%s not in %s!', who, where))
  end -- if

 elseif where == 'enemies' then
  if table.contains(enemy_list, who) == true then
   table.remove(enemy_list, tfind(enemy_list,who))
   if hl_nums[who] then killTrigger(hl_nums[who])end
   al_alert(string.format('%s removed from %s!', who, where))
  else
   al_alert(string.format('%s not in %s!', who, where))
  end -- if
 end -- if
end -- if

You'll need to call the function loadHL() when you start your profile
Hope that helps!

Malicia
Posts: 1
Joined: Wed Jan 05, 2011 6:20 pm

Re: Name Highlighter v3

Post by Malicia »

This is a great script. My only question is- how do I change the highlight colours in the script? Thanks!

Parnakra
Posts: 35
Joined: Tue Apr 21, 2009 10:48 am

Re: Name Highlighter v3

Post by Parnakra »

You should look for calls to setFgColor(R,G,B) in the script (there's one in the hlEnemy and hlFriend functions if you're using the above script).

csmall
Posts: 20
Joined: Wed Jan 12, 2011 9:36 pm

For the tree huggers

Post by csmall »

If you live in the communes then you don't have any of those nasty city commands but instead "communeenemies" and "members" for enemies and friends respectively. The script works with a few modifications. The main problem is there is no Total: line so you need to trigger off the isPrompt() and of course the commands are different.

In LMTS I had a similiar setup but it used the cwho and gwho commands and also the Aethers.I'll have a crack at it later.

rolly
Posts: 27
Joined: Sat Jul 03, 2010 9:51 pm

Re: Name Highlighter v3

Post by rolly »

The hi-lighter script won't compile and gives the message:


Lua syntax error:["string_________________..."]:34: nesting of[[...]] is deprecated near '['

Any Ideas?

rolly
Posts: 27
Joined: Sat Jul 03, 2010 9:51 pm

Re: Name Highlighter v3

Post by rolly »

This error comes with the Script hi-lighter that Rakon posted here

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Name Highlighter v3

Post by Rakon »

Try this one:
Code: [show] | [select all] lua

function loadHL()
 if enemy_list == nil then enemy_list = {} end
 if friend_list == nil then  friend_list = {} end

 -- add in more lists here, if you feel like it. IE shallam_list, mhaldor_list

 if hl_nums == nil then 
  hl_nums = {}

  for i,v in ipairs(enemy_list) do
   if not hl_nums[v] then
    hl_nums[v] = tempTrigger( v ,[[hlEnemy(matches[1]) ]] )
   end
  end

  for i,v in ipairs(friend_list) do
   if not hl_nums[v] then
    hl_nums[v] = tempTrigger( v ,[[hlFriend(matches[1]) ]] )
   end 
  end
 end -- if hl_nums
end -- function

function hlFriend(who)
 local c = 1;
 local k = 1;
 while k > 0 do
  if c > 3 then break; end;
  k = string.find( line, who, k )
  if k == nil then return; end
  local nC = '';
  nC = string.match( line, '.',k+string.len(who) )
  if nC == '.' or nC == ',' or nC == ';' or nC == ':' or nC == ' ' or nC == "'" then
   k = selectString(who, c) 
   if k > -1 then
    c = c + 1;
    setFgColor(0,255,127);
    resetFormat();
   else
    return;     
   end
  end
  k = k + string.len(who);
 end
end


function hlEnemy( who )
 local c = 1;
 local k = 1;
 while k > 0 do
  if c > 3 then break; end;
  k = string.find( line, who, k )
  if k == nil then return; end
  local nC = '';
  nC = string.match( line, '.',k+string.len(who) )
  if nC == '.' or nC == ',' or nC == ';' or nC == ':' or nC == ' '  or nC == "'"  then
   k = selectString(who, c) 
   if k > -1 then
    c = c + 1;
    setFgColor(255,0,0);
        setItalics(true);
    resetFormat();
   else
    return;     
   end
  end
  k = k + string.len(who);
 end
end

-- Copy the above function, and change the 'setFgColor' and ' function  hl<your function/list name>'


uti
Posts: 10
Joined: Thu Feb 03, 2011 6:16 pm

Re: Name Highlighter v3

Post by uti »

Works perfect, Rakon. Except.. Remove alias does not work. I try remove name from enemies, and the name is still highlighted.

Manni
Posts: 116
Joined: Tue May 31, 2011 9:00 pm

Re: Name Highlighter v3

Post by Manni »

So I've been playing with this a bit and I wound up adding quite a bit to the script, luckily enough it's simple enough to copy and modify the existing code. So this is what I came up with.

Additions:
  • Expanded punctuation recognition.
  • Will now highlight house enemies, city allies and citizens.
  • Renamed hl.isEnemy() to hl.isCityEnemy()
  • Added hl.isAlly(), hl.isCitizen(), and hl.isHouseEnemy()
  • ES <arena> will now disable highlighting for the ES command, and append CE, CA, HE or CI as necessary.
To-do list:
  • Highlighting for Divine orders
  • Highlighting for personal enemy/ally list
  • Improved table handling
  • ??Silent updating on login??
Attachments
Name Highlighter.xml.zip
(5.01 KiB) Downloaded 578 times
QW.jpg
QW.jpg (45.01 KiB) Viewed 8742 times
Event status.jpg
Event status.jpg (25.57 KiB) Viewed 8742 times

Lezard
Posts: 36
Joined: Wed Aug 29, 2012 6:47 pm

Re: Name Highlighter v3

Post by Lezard »

Manni wrote:So I've been playing with this a bit and I wound up adding quite a bit to the script, luckily enough it's simple enough to copy and modify the existing code. So this is what I came up with.
I like it! Thanks for doing this :)

Post Reply