Page 2 of 3
Re: GMCP
Posted: Sun Nov 27, 2011 4:50 am
by Delrayne
I sort of just briefly ran through this thread but I made an AUTOBASHER(no user input except which area to go to) If this is what you are trying to accomplish I can try and package it for the forums, I won't post it on IRE's site cause....well your not suppose to autobash....anyway. Let me know if you guys would like to see it or if you were going a completely different direction with this.
Re: GMCP
Posted: Fri Dec 09, 2011 1:31 am
by Darmir
I am trying to use the function by getting only certain enemies from the list and getting a count of them. For some reason when I create a infunction that calls this one I loose the information from roomEnemies.get().
Re: GMCP
Posted: Sun Dec 11, 2011 12:24 am
by Caelic
Darmir, that'd be something I'd be interested in also.. I'd love an ability to pull room enemies list, and if those room enemies are on my list, it puts them in a list 1 through X, and then in that, I target 1, when it dies, I go down to X
Re: GMCP
Posted: Sun Dec 11, 2011 1:37 am
by Darmir
I got something partially written that I started from scratch. The issue I am having is the gmcp.Char.Items.Remove doesn't send the same as the gmcp.Char.Items.Add in Achaea. It is missing the name of the item in the table which is sent to the client. I reported it to Achaea which they replied and are sending the issue to the developers.
Re: GMCP
Posted: Sun Dec 11, 2011 2:18 am
by tsuujin
Here's the basis for my system for handling enemy recognition:
"areaEnemies" keeps a running list of known NPC enemies, based on your current area.
--[[ Area Enemies Tracker ]] --
require "dba"
require "messages"
module("areaEnemies",package.seeall)
-- Private Variables
local areaList = {}
local trigList = {}
local currentArea = nil
local enemyRegex = {}
function init()
dba.execute([[
CREATE TABLE IF NOT EXISTS npc_enemies (
name TEXT,
area TEXT,
priority INTEGER,
CONSTRAINT pk PRIMARY KEY(name, area) ON CONFLICT REPLACE
);
]])
dbLoad()
end
--[[ Database Manipulation Functions ]]--
function dbLoad()
-- Gain the list of areas first.
areaList = {}
local results = dba.query([[SELECT DISTINCT area FROM npc_enemies]])
for num,tbl in results:pairs() do areaList[tbl.area] = {} end
-- Requery once for each area, gaining a list of enemies by priority
for area,_ in pairs(areaList) do
results = dba.query(string.format([[SELECT * FROM npc_enemies WHERE area = "%s" ORDER BY priority DESC]],area))
for num,tbl in results:pairs() do table.insert(areaList[area],tbl.name) end
end
end
function dbSave()
if not dba.begin() then
tempTimer(1,[[areaEnemies.dbSave()]])
msg.print("delayed...")
return false
end
for area,enemies in pairs(areaList) do
for priority,enemy in pairs(enemies) do
dba.execute(string.format([[INSERT INTO npc_enemies VALUES ("%s","%s",%d)]],enemy,area,priority))
end
end
dba.commit()
end
--[[ Area Manipulation Functions ]]--
function addEnemy(enemy,priority,area)
area = area or gmcp.Room.Info.area
if not areaList[area] then areaList[area] = {} end
table.insert(areaList[area],priority,enemy)
end
function removeEnemy(enemy,area)
area = area or gmcp.Room.Info.area
if not areaList[area] then return end
for i,v in pairs(areaList[area]) do
if v:lower() == enemy:lower() then
table.remove(areaList[area],i)
return i
end
end
return false
end
function switchPriority(enemy,priority,area)
area = area or gmcp.Room.Info.area
if not areaList[area] then return end
if not removeEnemy(enemy,area) then return false end
table.insert(areaList[area],priority,enemy)
end
--[[ Basic Information Retrieval Functions]]--
function isEnemy(enemy,area)
area = area or gmcp.Room.Info.area
if not areaList[area] then return false end
for _,tar in pairs(areaList[area]) do
if not enemyRegex[tar] then enemyRegex[tar] = rex.new(string.format([[(?i:\b%s\b)]],tar)) end
if enemyRegex[tar]:match(enemy) then return tar end
end
return false
end
function getAreas()
local areas = {}
for area,_ in pairs(areaList) do table.insert(areas,area) end
return areas
end
function getAreaEnemies(area)
area = area or gmcp.Room.Info.area
return areaList[area] or {}
end
--[[ Display Functions ]]--
function listEnemies(area)
area = area or gmcp.Room.Info.area
msg.print(string.format("<yellow>%s <white>targets:",area))
if not areaList[area] then return end
for i,v in pairs(areaList[area]) do
msg.print(string.format("<cyan>%3d <white>%s",i,v))
end
end
--[[ Highlight Functions ]]--
function defineTargets(area)
area = area or gmcp.Room.Info.area
if area == currentArea then return end
for _,trig in pairs(trigList) do killTrigger(trig) end
currentArea = area
if not areaList[area] then return end
local sf = [[areaEnemies.highlight("%s")]]
for _,tar in pairs(areaList[area]) do
table.insert(trigList,tempTrigger(tar,sf:format(tar)))
end
end
function highlight(tar)
local i = 1
while selectString(tar,i) ~= -1 do
fg("coral")
setItalics(true)
i = i + 1
end
end
init()
"roomEnemies" tracks enemies currently in the room by referencing GMCP items against the list generated from areaEnemies:
-- [[ Room Enemies Tracker ]] --
require "mod_areaEnemies"
module("roomEnemies",package.seeall)
local current = {}
local roomTarget = ""
local oldlist = nil
function add(toadd)
if not toadd then return end
if toadd.item.name:find("the corpse of") then return end
if toadd.location ~= "room" then return end
current[tonumber(toadd.item.id)] = areaEnemies.isEnemy(toadd.item.name) or nil
end
function remove(tosub)
if not tosub then return end
if tosub.location ~= "room" then return end
local subID = tonumber(tosub.item) or 0
current[subID] = nil
end
function reset(newlist)
if not newlist then return end
if newlist.location ~= "room" then return end
if newlist == oldlist then return end
oldlist = newlist
current = {}
for i,v in pairs(newlist.items or {}) do
if not v.name:find("the corpse of") then
current[tonumber(v.id)] = areaEnemies.isEnemy(v.name) or nil
end
end
end
function get() return current end
function print()
msg.print("<yellow>Enemies currently tracked in room:")
for i,v in pairs(current) do
msg.print(string.format("%-15s%s",i,v))
end
end
Re: GMCP
Posted: Sun Dec 11, 2011 4:12 am
by Vadi
Nice script! We could use with a 'like' button on the forums...
Re: GMCP
Posted: Sun Dec 11, 2011 4:40 pm
by Darmir
tsuujin wrote:Here's the basis for my system for handling enemy recognition:
"areaEnemies" keeps a running list of known NPC enemies, based on your current area.
--[[ Area Enemies Tracker ]] --
require "dba"
require "messages"
module("areaEnemies",package.seeall)
-- Private Variables
local areaList = {}
local trigList = {}
local currentArea = nil
local enemyRegex = {}
function init()
dba.execute([[
CREATE TABLE IF NOT EXISTS npc_enemies (
name TEXT,
area TEXT,
priority INTEGER,
CONSTRAINT pk PRIMARY KEY(name, area) ON CONFLICT REPLACE
);
]])
dbLoad()
end
--[[ Database Manipulation Functions ]]--
function dbLoad()
-- Gain the list of areas first.
areaList = {}
local results = dba.query([[SELECT DISTINCT area FROM npc_enemies]])
for num,tbl in results:pairs() do areaList[tbl.area] = {} end
-- Requery once for each area, gaining a list of enemies by priority
for area,_ in pairs(areaList) do
results = dba.query(string.format([[SELECT * FROM npc_enemies WHERE area = "%s" ORDER BY priority DESC]],area))
for num,tbl in results:pairs() do table.insert(areaList[area],tbl.name) end
end
end
function dbSave()
if not dba.begin() then
tempTimer(1,[[areaEnemies.dbSave()]])
msg.print("delayed...")
return false
end
for area,enemies in pairs(areaList) do
for priority,enemy in pairs(enemies) do
dba.execute(string.format([[INSERT INTO npc_enemies VALUES ("%s","%s",%d)]],enemy,area,priority))
end
end
dba.commit()
end
--[[ Area Manipulation Functions ]]--
function addEnemy(enemy,priority,area)
area = area or gmcp.Room.Info.area
if not areaList[area] then areaList[area] = {} end
table.insert(areaList[area],priority,enemy)
end
function removeEnemy(enemy,area)
area = area or gmcp.Room.Info.area
if not areaList[area] then return end
for i,v in pairs(areaList[area]) do
if v:lower() == enemy:lower() then
table.remove(areaList[area],i)
return i
end
end
return false
end
function switchPriority(enemy,priority,area)
area = area or gmcp.Room.Info.area
if not areaList[area] then return end
if not removeEnemy(enemy,area) then return false end
table.insert(areaList[area],priority,enemy)
end
--[[ Basic Information Retrieval Functions]]--
function isEnemy(enemy,area)
area = area or gmcp.Room.Info.area
if not areaList[area] then return false end
for _,tar in pairs(areaList[area]) do
if not enemyRegex[tar] then enemyRegex[tar] = rex.new(string.format([[(?i:\b%s\b)]],tar)) end
if enemyRegex[tar]:match(enemy) then return tar end
end
return false
end
function getAreas()
local areas = {}
for area,_ in pairs(areaList) do table.insert(areas,area) end
return areas
end
function getAreaEnemies(area)
area = area or gmcp.Room.Info.area
return areaList[area] or {}
end
--[[ Display Functions ]]--
function listEnemies(area)
area = area or gmcp.Room.Info.area
msg.print(string.format("<yellow>%s <white>targets:",area))
if not areaList[area] then return end
for i,v in pairs(areaList[area]) do
msg.print(string.format("<cyan>%3d <white>%s",i,v))
end
end
--[[ Highlight Functions ]]--
function defineTargets(area)
area = area or gmcp.Room.Info.area
if area == currentArea then return end
for _,trig in pairs(trigList) do killTrigger(trig) end
currentArea = area
if not areaList[area] then return end
local sf = [[areaEnemies.highlight("%s")]]
for _,tar in pairs(areaList[area]) do
table.insert(trigList,tempTrigger(tar,sf:format(tar)))
end
end
function highlight(tar)
local i = 1
while selectString(tar,i) ~= -1 do
fg("coral")
setItalics(true)
i = i + 1
end
end
init()
"roomEnemies" tracks enemies currently in the room by referencing GMCP items against the list generated from areaEnemies:
-- [[ Room Enemies Tracker ]] --
require "mod_areaEnemies"
module("roomEnemies",package.seeall)
local current = {}
local roomTarget = ""
local oldlist = nil
function add(toadd)
if not toadd then return end
if toadd.item.name:find("the corpse of") then return end
if toadd.location ~= "room" then return end
current[tonumber(toadd.item.id)] = areaEnemies.isEnemy(toadd.item.name) or nil
end
function remove(tosub)
if not tosub then return end
if tosub.location ~= "room" then return end
local subID = tonumber(tosub.item) or 0
current[subID] = nil
end
function reset(newlist)
if not newlist then return end
if newlist.location ~= "room" then return end
if newlist == oldlist then return end
oldlist = newlist
current = {}
for i,v in pairs(newlist.items or {}) do
if not v.name:find("the corpse of") then
current[tonumber(v.id)] = areaEnemies.isEnemy(v.name) or nil
end
end
end
function get() return current end
function print()
msg.print("<yellow>Enemies currently tracked in room:")
for i,v in pairs(current) do
msg.print(string.format("%-15s%s",i,v))
end
end
Is that the whole script for tracking enemies? If not can you post the xml file?
Re: GMCP
Posted: Mon Dec 12, 2011 12:10 am
by Caelic
Yeah, I'm interested in all of this.. I have this uploaded, what is here, and I don't see anything happening. though I could be doing something wrong.. heh
Re: GMCP
Posted: Tue Dec 13, 2011 3:25 am
by tsuujin
Darmir wrote:
Is that the whole script for tracking enemies? If not can you post the xml file?
I did not post the required database or message printing functions, so this will not work by itself (it's essentially one module in my very large system). However, it is entirely complete in the way that it handles the GMCP requests, tracks enemies and responds.
Re: GMCP
Posted: Tue Dec 13, 2011 3:28 am
by tsuujin
Vadi wrote:Nice script! We could use with a 'like' button on the forums...
Thanks! It's one of my better utility scripts, I think. Really pulled it together with the database integration.