Posted by
| Faux
United Kingdom (77 posts) Bio
|
Message
| Partial solution (because I just worked out that gmatch exists and I can't be btohered to re-write it :p):
Trigger:
<triggers>
<trigger
enabled="y"
match="^ ? ?Obvious exits\: (.*)$"
omit_from_output="y"
regexp="y"
script="OnObviousExits"
sequence="95"
>
</trigger>
</triggers>
Scriptfile:
function explode(d,p)
--p="abcd defg hijk lmnp"
t={}
ll=0
while true do
l=string.find(p,d,ll+1,true)
if l~=nil then
table.insert(t, string.sub(p,ll,l-1))
ll=l+string.len(d)
else
table.insert(t, string.sub(p,ll))
break
end
end
--print_r(t)
return t
end
function preg_replace(pat,with,p)
while true do
a=rex.new(pat) -- compile regexp
x,y,t=a:match(p) -- match regexp
if (x~=nil and y~=nil) then -- if we matched then
p=string.sub(p,0,x-1).. with .. string.sub(p,y+1) -- rebuild the string
else
break
end
end
return p
end
function table_contains(t,p)
for a,v in pairs(t) do if v==p then return true end end
return false
end
function OnObviousExits (name, trig_line, wildcards)
a=wildcards[1]
ss="Obvious exits: "
a=preg_replace("\(.*?\)","", a) -- Remove the ()ed terms.
t=explode(" ",a)
if (table_contains(t,"sw")) then ss = ss .. "sw " end
if (table_contains(t,"nw")) then ss = ss .. "nw " end
if (table_contains(t,"w")) then ss = ss .. "w " end
if (table_contains(t,"n")) then ss = ss .. "n " end
if (table_contains(t,"s")) then ss = ss .. "s " end
if (table_contains(t,"e")) then ss = ss .. "e " end
if (table_contains(t,"ne")) then ss = ss .. "ne " end
if (table_contains(t,"se")) then ss = ss .. "se " end
a=preg_replace("\b(?:n|e|s|w|nw|ne|se|sw)\b","", a)
ss = ss .. a
Note(preg_replace("[ ][ ]+"," ",ss))
end
|
Faux, from Discworld. Feel free to come talk to me =)
http://faux.servebeer.com/ | Top |
|