|
capnknives Newbie
Joined: 09 Aug 2008 Posts: 1
|
Posted: Sat Aug 09, 2008 6:19 am
Question about CMUD triggers.... |
Alright I have an old Script from ZMUD for a mud I avidly play that I cannot seem to add As i've never been good at scripting muchless a new program. it is as follows. from the zmud scripting area.
Cargo Trade Price checker script by Lightbulb
(appears to be for LOTJ)
Originally posted by LightBulb
This should work. I've tested it, repeatedly, as best I can. I provided another set of display aliases at the end, they should provide a more useful display. After doing sales, just type bestroutes. If you decide to continue using it, it would probably be helpful to shorten the name.
#TRIGGER {Planet: (*)} {planetlow = {%1}} "getlowprices"
#TRIGGER {(%w)*~( Price per unit: (%d).(%d) ~)} {#MATH templow ((%2 * 100) + %3);#IF (%ismember( %1, @lowlist)) {#IF (@templow < %db( @%1low, price)) {#VARIABLE %1low "";#ADDKEY %1low {price=@templow|planet=@planetlow}}} {#ADDITEM lowlist "%1";#VARIABLE %1low "";#ADDKEY %1low {price=@templow|planet=@planetlow}}} "getlowprices"
#ALIAS lowprices {#FORALL @lowlist {showlow %{i}}}
#ALIAS showlow {#SHOW lowest price for %1: %expanddb( @{%1low}, " on the ", ": ")}
#TRIGGER {--Planet Data-} {#T+ getlowprices}
#TRIGGER {Planet: (*)} {planet = {%1}} "getprices"
#TRIGGER {(%w)*~( Price per unit: (%d).(%d) ~)} {#MATH temp ((%2 * 100) + %3);#IF (%ismember( %1, @profitlist)) {#IF (@temp > %db( @%1, price)) {#VARIABLE %1 "";#ADDKEY %1 {price=@temp|planet=@planet}}} {#ADDITEM profitlist "%1";#VARIABLE %1 "";#ADDKEY %1 {price=@temp|planet=@planet}}} "getprices"
#ALIAS bestprices {#FORALL @profitlist {showgood %i}}
#ALIAS showgood {#SHOW Best price for %1: %expanddb( @{%1}, " on the ", ": ")}
#TRIGGER {--Planet Data} {#T+ getprices}
#AL sales {#FORALL @lowlist {#VAR temp1 %{i}low;#UNVAR @temp1};#UNVAR lowlist;#FORALL @profitlist {#VAR temp2 %{i};#UNVAR @temp2};#UNVAR profitlist;Showplanet Byss resources;Showplanet Coruscant resources;Showplanet Yavin resources;Showplanet Corellia resources;Showplanet Ryloth resources;Showplanet Gamorr resources;Showplanet Tatooine resources;Showplanet Kashyyyk resources;Showplanet Wroona resources;Showplanet Roche resources;Showplanet 'Nal hutta' resources;showplanet 'Nim Drovis' resources;Showplanet 'Ord Mantell' resources}
#AL bestroutes {#FORALL @lowlist {showbest %{i}}}
#AL showbest {#SHOW lowest price for %1: %expanddb( @{%1low}, " on the ", ": ");#SHOW Best price for %1: %expanddb( @{%1}, " on the ", ": ");#CR}
A database still might be better... but i'm not good with all of this....
as well as, I'd like to have a few smaller windows for different channels, How would I go about making these? |
|
|
|
TonDiening GURU
Joined: 26 Jul 2001 Posts: 1958 Location: Canada
|
Posted: Mon Aug 11, 2008 12:11 am Re: Question about CMUD triggers.... |
A quick glance and I see that you try and capture "%1" which would give you %1 and not the parameter.
For the @ variable expansion use the {}
#TRIGGER {Planet: (*)} {planetlow = {%1}} "getlowprices"
#TRIGGER {(%w)*~( Price per unit: (%d).(%d) ~)} {#MATH templow ((%2 * 100) + %3);#IF (%ismember( %1, @lowlist)) {#IF (@templow < %db( @{%1low}, price)) {#VARIABLE %1low "";#ADDKEY %1low {price=@templow|planet=@planetlow}}} {#ADDITEM lowlist %1;#VARIABLE %1low "";#ADDKEY %1low {price=@templow|planet=@planetlow}}} "getlowprices"
#ALIAS lowprices {#FORALL @lowlist {showlow %i}}
#ALIAS showlow {#SHOW lowest price for %1: %expanddb( @{%1low}, " on the ", ": ")}
#TRIGGER {--Planet Data-} {#T+ getlowprices}
#TRIGGER {Planet: (*)} {planet = {%1}} "getprices"
#TRIGGER {(%w)*~( Price per unit: (%d).(%d) ~)} {#MATH temp ((%2 * 100) + %3);#IF (%ismember( %1, @profitlist)) {#IF (@temp > %db( @{%1}, price)) {#VARIABLE %1 "";#ADDKEY %1 {price=@temp|planet=@planet}}} {#ADDITEM profitlist %1;#VARIABLE %1 "";#ADDKEY %1 {price=@temp|planet=@planet}}} "getprices"
#ALIAS bestprices {#FORALL @profitlist {showgood %i}}
#ALIAS showgood {#SHOW Best price for %1: %expanddb( @{%1}, " on the ", ": ")}
#TRIGGER {--Planet Data} {#T+ getprices}
#AL sales {#FORALL @lowlist {#VAR temp1 %concat(%i,"low");#UNVAR @temp1};#UNVAR lowlist;#FORALL @profitlist {#VAR temp2 %i;#UNVAR @temp2};#UNVAR profitlist;Showplanet Byss resources;Showplanet Coruscant resources;Showplanet Yavin resources;Showplanet Corellia resources;Showplanet Ryloth resources;Showplanet Gamorr resources;Showplanet Tatooine resources;Showplanet Kashyyyk resources;Showplanet Wroona resources;Showplanet Roche resources;Showplanet 'Nal hutta' resources;showplanet 'Nim Drovis' resources;Showplanet 'Ord Mantell' resources}
#AL bestroutes {#FORALL @lowlist {showbest %i}}
#AL showbest {#SHOW lowest price for %1: %expanddb( @{%1low}, " on the ", ": ");#SHOW Best price for %1: %expanddb( @{%1}, " on the ", ": ");#CR}
I'll crank you out a xml file with some clean up shortly.
Quote: |
as well as, I'd like to have a few smaller windows for different channels, How would I go about making these? |
Try something like this:
#TRIGGER {^~({newbie|ooc|rpc|imm}~)} {:ooc:#SAYP %time(hh:mm)%char(32);#CAP OOC;#GAG}
You might have to redo the value part of the trigger as I am not sure if :ooc: will go through the parser correctly. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Tue Aug 12, 2008 5:42 am |
I was looking at this and probably something like the HashSet function Arminas came up with would be better suited to store all this info.
Here's an example of what I came up with if this is the same thing as this page.
Code: |
<class name="PlanetPricing" id="1">
<trigger name="price_toggle" priority="120" regex="true" id="12">
<pattern>^\-\-Planet Data\: \-+</pattern>
<value>#T+ planet_check trigger
#T+ price_check trigger</value>
<trigger regex="true">
<pattern>^HP\:\d+\/\d+ MV\:\d+\/\d+ </pattern>
<value>#T- planet_check trigger
#T- price_check trigger
planet=%null</value>
</trigger>
</trigger>
<var name="highPrices" type="Record" id="17">Electronics=8.95|Uranium=9.8|Medicalsupplies=9.14|Food=9.29|Chemicals=6.56|Commonmetals=9.88|Explosives=8.54|Livestock=6.74|Constructionparts=8.27|Goods=9.86|Ammunition=9.31|Quantum=9.96|Textiles=6.87|Weapons=9.21|Water=9.46|Lumber=7.74|Durelium=6.17|Fuel=9.27|Ardanium=9.84|Spice=9.51|Lomite=9.66|Preciousmetals=6.85</var>
<var name="planet" id="22"/>
<trigger name="price_check" priority="230" regex="true" enabled="false" id="23">
<pattern>^([\w ]+)\s\( Price per unit\: (\d*\.{0,1}\d+) \)</pattern>
<value>$planet=@planet
$item=%1
$price=%float( %2)
#if (%numwords($item,2)) {$item=%concat(%word($item,1),%word($item,2))}
#call @HashSet(Planets, $planet, $item, $price)</value>
</trigger>
<trigger name="planet_check" priority="240" regex="true" enabled="false" id="24">
<pattern>^Planet\: ([\w ]+)</pattern>
<value>planet=%1</value>
<trigger type="Within Lines" param="1" regex="true" enabled="false">
<pattern>^Starsystem: ([\w ]+)</pattern>
<value>$planet=@planet
$sys=%1
#call @HashSet(Planets, $planet, system, $sys)</value>
</trigger>
<trigger type="Within Lines" param="1" regex="true" enabled="false">
<pattern>^Governed By: ([\w ]+)</pattern>
<value>$planet=@planet
$gov=%1
#call @HashSet(Planets, $planet, government, $gov)</value>
</trigger>
<trigger regex="true" enabled="false">
<pattern>Planet Funds: (\d+)</pattern>
<value>#T+ price_check trigger
$planet=@planet
$funds=%1
#call @HashSet(Planets, $planet, funds, $funds)</value>
</trigger>
</trigger>
<func name="HashSet" language="Lua" id="32">
<value>local nparams, var
nparams=zs.numparam
if nparams < 3 then
print("HashSet requires at least three arguments. \n Arg1:=varName Agr2:=key Agr3:=value")
do return end
end
var=zs.param("1")
tvar=zs.var[var]
if zs.func.vartype(var) == -1 then
zs.cmd.var(var,{})
zs.func.vartype(var,5)
tvar=zs.var[var]
elseif not (vart == 5) then
zs.func.vartype(var,5)
tvar=zs.var[var]
end
local key, val, tstring, vtype
tstring="tvar"
val = zs.param(nparams)
key = zs.param(nparams-1)
local function fset(s1,s2) assert(loadstring(s1..s2))() end
local function ftest() return assert(loadstring("return type(" .. tstring .. ")"))() end
if nparams > 3 then
local list = {}
for i=2,nparams-1 do
list[(i-1)]=zs.param(i)
end
for i,v in ipairs(list) do
tstring=tstring .. "['" .. v .. "']"
vtype=ftest(tstring)
if vtype == 'table' then
-- tstring leads to a table.
else
fset(tstring,'={""}')
-- tstring does Not lead to a table, one must be crerated.
-- For a hash table to remain it must contain at least two values.
-- Creating table key for second value.
fset(tstring,"={table='" .. v .."'}")
end
end
if val == 'nil' then
fset(tstring,"=nil")
else
fset(tstring,'={"' .. val .. '"}')
end
else
if val == 'nil' then
fset(tstring.."['"..key.."']","=nil")
else
fset(tstring.."['"..key.."']",'={"' .. val .. '"}')
end
end
zs.var[var]=tvar</value>
<notes>Function provided by Arminas and can be found in the library.
The syntax is as follows.
#call @HashSet("varname","key","key","key","value")
You can use from one to as many keys as you like. If you do not use at least one key it prints an error to the screen.
HashSet requires at least three arguments.
Arg1:=varName Agr2:=key Agr3:=value
If you wanted to get rid of a key altogether you would send a nil value at the end.
#call @HashSet("varname","key","key","key","nil")
This is roughly equivilant to the way you would expect #delkey to work. Which it doesn't on hash tables. Of course if you are using a standard Data record #delkey still works just fine.
HashSet will create a variable if one by the given name does not already exist.
HashSet will create a key if one does not already exist.
Quotes are only required around arguments if the argument contains spaces or commas.
#call @HashSet("varname","key","key","key","value")
Is equivilant to.
#call @HashSet(varname, key, key, key, value)</notes>
</func>
<var name="Planets" type="Record" id="35">Kashyyyk="government=The New Republic|system=Kashyyyk|table=Kashyyyk|Commonmetals=2.4|funds=833969|Ammunition=7.29|Weapons=7.29|Lumber=7.46|Preciousmetals=4.62"|Gamorr="government=The Empire|system=Gamorr|Food=4.29|table=Gamorr|Chemicals=2.47|Livestock=6.34|funds=772638|Textiles=6.76|Weapons=5.76|Lumber=5.57"|Corellia="Electronics=6.95|Medicalsupplies=9.09|government=The Empire|system=Corellian|table=Corellia|Food=7.11|Chemicals=6.56|Commonmetals=8.11|Explosives=2.22|Constructionparts=3.83|Goods=6.24|funds=1109137|Ammunition=3.46|Textiles=5.92|Weapons=5.87|Fuel=8.44|Ardanium=9.56|Lomite=5.21|Preciousmetals=6.46"|Roche="Uranium=4.6|government=The New Republic|system=Roche Sector|table=Roche|Food=4.81|Chemicals=2.42|Commonmetals=4.14|Explosives=7.51|funds=1118897|Ammunition=1.55|Quantum=3.99|Weapons=7.16|Water=5.54|Durelium=3.66|Fuel=5.48|Lomite=2.36|Preciousmetals=4.84"|Nim Drovis="government=The Empire|system=Drovian|table=Nim Drovis|funds=1234567"|Byss="Electronics=4.06|Uranium=8.33|government=The Empire|system=Byss|table=Byss|Food=7.78|Commonmetals=4|Explosives=7.39|Constructionparts=8.27|Goods=5.27|funds=579703|Quantum=9.96|Textiles=6.87|Weapons=2.76|Durelium=6.17|Fuel=9.27|Spice=7.92|Lomite=9.66|Preciousmetals=6.85"|Tatooine="Electronics=8.95|Medicalsupplies=7.12|government=The Empire|system=Tatoo|table=Tatooine|Food=9.29|Commonmetals=5.56|Explosives=5.37|Goods=7.04|funds=822608|Ammunition=9.31|Quantum=6.96|Weapons=7.12|Water=9.46|Fuel=9.19|Spice=4.61|Lomite=5.08"|Yavin="government=Neutral|system=Yavin|table=Yavin|Food=5.53|Livestock=6.74|Goods=9.86|funds=1020124|Lumber=5.87"|Coruscant="Electronics=4.92|Uranium=9.8|Medicalsupplies=9.14|government=The Empire|system=Coruscant|table=Coruscant|Food=7.94|Chemicals=4.64|Commonmetals=9.88|Constructionparts=3.87|Goods=3.47|funds=1851111201|Ammunition=5.45|Quantum=6.45|Textiles=3.1|Weapons=2.75|Water=8.8|Fuel=7.81|Ardanium=9.84|Spice=9.51|Lomite=6.39|Preciousmetals=4.37"|Ord Mantell="government=The Empire|system=Bright Jewel|table=Ord Mantell|funds=0"|Wroona="Medicalsupplies=5.88|government=The New Republic|system=Wroona|table=Wroona|Food=3.2|Goods=6.24|funds=1003443|Textiles=4.77|Weapons=7.12|Water=3.31|Lumber=7.74|Fuel=3.47"|Nal Hutta="government=Neutral|system=Hutt Space|Food=4.97|table=Nal Hutta|Commonmetals=5.88|Explosives=8.54|Constructionparts=8.01|Goods=4.63|funds=1078639|Weapons=3.45|Spice=4.3"|Ryloth="government=The Empire|system=Ryloth|Food=4.52|table=Ryloth|Goods=4.63|funds=983014|Weapons=9.21|Fuel=6.69|Spice=5.54|Preciousmetals=3.6"</var>
<func name="checkPrices" id="40">
<value>#local $price $itemList
$itemList="Electronics|Uranium|Food|Chemicals|Explosives|Livestock|Goods|Ammunition|Medicalsupplies|Quantum|Textiles|Constructionparts|Weapons|Water|Durelium|Lumber|Fuel|Ardanium|Spice|Lomite|Commonmetals|Preciousmetals"
#loopdb @Planets {
#forall $itemList {
$price=@Planets.%key.%i
#if (!%null($price)) {
#if (!%db(@lowPrices,%i)) {#addkey lowPrices %i $price}
#if (!%db(@highPrices,%i)) {#addkey highPrices %i $price}
#if (%db(@lowPrices,%i) > $price) {#addkey lowPrices %i $price}
#if (%db(@highPrices, %i) < $price) {#addkey highPrices %i $price}
}
}
}</value>
</func>
<var name="lowPrices" type="Record" id="42">Electronics=4.06|Uranium=4.6|Medicalsupplies=5.88|Food=3.2|Chemicals=2.42|Commonmetals=2.4|Explosives=2.22|Livestock=6.34|Constructionparts=3.83|Goods=3.47|Ammunition=1.55|Quantum=3.99|Textiles=3.1|Weapons=2.75|Water=3.31|Lumber=5.57|Durelium=3.66|Fuel=3.47|Ardanium=9.56|Spice=4.3|Lomite=2.36|Preciousmetals=3.6</var>
<alias name="showlows" id="46">
<value>#local $temp
#loopdb @Planets {#additem $temp %key}
#if (%null(@lowPrices)) {#call @checkPrices()}
#loopdb @lowPrices {
#forall $temp {
#if (@Planets.%i.%key == %val) {#print {Lowest price for %key: Planet %i at %val}}
}
}</value>
</alias>
<alias name="showhighs" id="47">
<value>#local $temp
#loopdb @Planets {#additem $temp %key}
#if (%null(@highPrices)) {#call @checkPrices()}
#loopdb @highPrices {
#forall $temp {
#if (@Planets.%i.%key == %val) {#print {Best price for %key: Planet %i at %val}}
}
}</value>
</alias>
<alias name="showallprices" id="48">
<value>#local $temp
#loopdb @Planets {#additem $temp %key}
#if (%null(@highPrices) || %null(@lowPrices)) {#call @checkPrices()}
#loopdb @highPrices {
#forall $temp {
#if (!%null(@Planets.%i.%key)) {#print {Planet %i: %key at @Planets.%i.%key}}
}
}</value>
</alias>
</class> |
Not sure how much info you even want, but this captures the starsystem of the planet, the goverment, how much funds it has, the prices of all the planet's goods etc. You can "showlows" to see the lowest prices and what planet they are on, or "showhighs" and see the highest prices and what planet they are on. Of course you can "showallprices" to see all prices by planet. I ran a test using all the data off that other post and it seemed to work just fine. Although I am not sure how you would look up the planet's government info and so on when the name is two words. Maybe someone else can say? Obviously you don't have to use this. It was just for an idea and I was bored. [/url] |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|