lua:scripting:examples:olcscripts
This is an old revision of the document!
Table of Contents
Log of changes affecting lua scripting API including changes to prog triggers.
Edit all wands and staffs to have 50/50 charges
do for _,area in pairs(getarealist()) do for _,op in pairs(area.objprotos) do if op.otype=="wand" or op.otype=="wand" then if not(op.chargesleft==50) or not(op.chargestotal==50) then mdo("oedit "..op.vnum) olc("v1 50") olc("v2 50") olc("done") end end end end end
Shop wands/staffs have 50/50 charges, otherwise set to -1/50
-1 makes the # of charges randomize then item pops.
do local cnter=0 local reset_check = {} for _,area in pairs(getarealist()) do for _,room in pairs(area.rooms) do local shop=false for i,reset in ipairs(room.resets) do clearloopcount() local cmd=reset.command if cmd == "M" then if getmobproto(reset.arg1).shop then shop=true else shop=false end elseif cmd == "G" then if shop==true then reset_check[reset.arg1]=true elseif reset_check[reset.arg1]==nil then reset_check[reset.arg1]=false end end end end end for _,area in pairs(getarealist()) do for _,op in pairs(area.objprotos) do if op.otype=="wand" or op.otype=="staff" then local chargesleft_target local chargestotal_target if reset_check[op.vnum]==true then chargesleft_target=50 chargestotal_target=50 else chargesleft_target=-1 chargestotal_target=50 end if not(op.chargesleft==chargesleft_target) or not(op.chargestotal==chargestotal_target) then mdo("oedit "..op.vnum) olc("v1 "..chargestotal_target) olc("v2 "..chargesleft_target) olc("done") end end end end end
<geshi lua>
<font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>do</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>local area=getroom(2031).area</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>for _,room in pairs(area.rooms) do</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>local edited=false</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>clearloopcount()</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>local finished</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>while not finished do</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>finished=true</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>local num_resets=#room.resets</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit></font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>for i,reset in ipairs(room.resets) do</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>if reset.command=="M" then</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>goto(room.vnum)</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>local rmax=reset.arg4</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>local amax=reset.arg2</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>local mvnum=reset.arg1</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit></font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>if amax>25 then</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>local newmax=25</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>rmax=math.min(rmax,newmax)</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>--local newmax=math.max(20, amax/2)</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>--newmax=math.min(amax, 50)</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>edited=true</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>mdo("reset "..i.." delete")</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>mdo("reset "..num_resets.." mob "..mvnum.." "..newmax.." "..rmax)</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>finished=false</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>break</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>end</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>end</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>end</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>end</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>if edited then mdo('reset') end</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>end</font> <font 11.6999998092651px line-height: 15.210000038147px;/Monaco, ;;rgb(46, 139, 87) font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; font-size: 11.6999998092651px; line-height: 15.210000038147px;;;inherit>end</font>
lua/scripting/examples/olcscripts.1426462887.txt.gz · Last modified: 2015/03/15 23:41 by vodur