Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////////////////
- //New .add dialog (SQLite version) version 1.0
- //The first you have to check is that you have this in your sphere.ini:
- //
- //[RESOURCELIST]
- // ITEMDEF
- // CHARDEF
- //
- //To install it type .f_add_setup
- //To see the dialog type .add
- //To 'reset' data, type .f_add_clear and then .f_add_setup again
- //
- //Note: As it is reading items/chars placed not even placed in the world, you may get some errors in console regarding to these items/chars and script issues related to them.
- ////////////////////////////////////////////////////////////////////////////////////////////
- [DEFNAME adddef]
- //Search disabled ATM, not converted to SQLite
- adddialog_search=0 //Set this to 0 if you do not want the dialog to be able to search items.
- [FUNCTION f_oncommand]
- if (STRMATCH("add","<args>")==1)
- dialogclose d_add
- dialog d_add
- add1
- return 1
- elseif (STRMATCH("add *","<args>")==1) //old .add i_whatever behaviour.
- return 0
- endif
- [function add1]
- dialogclose d_add
- dialog d_add
- [function f_add_setup]
- if !(<ldb.connected>)
- ldb.connect "adddialog.db"
- // serv.log Connecting to table adddialog
- endif
- ldb.EXECUTE DROP TABLE IF EXISTS 'items'
- ldb.EXECUTE DROP TABLE IF EXISTS 'chars'
- ref1=<uid>
- if (<ldb.connected>)
- ldb.execute CREATE TABLE 'items' ('id' TEXT PRIMARY KEY NOT NULL,'defname' TEXT, 'name' TEXT,'category' TEXT,'subsection' TEXT,'description' TEXT)
- ldb.execute CREATE TABLE 'chars' ('id' TEXT PRIMARY KEY NOT NULL,'defname' TEXT, 'name' TEXT)
- local.hour=<serv.rticks>
- LDB.EXECUTE BEGIN
- if !(<db.connected>)
- serv.log Error, DB (MySQL) must be connected to use the <db.escapedata > function.
- return 0
- endif
- for 0 100//<eval <serv.deflist.itemdef.count>-1>
- local.item=<serv.deflist.itemdef.<dlocal._for>>
- if (<local.item>) //All code placed here to avoid problems with serv.deflist.itemdef.1029 (in my case) wich leads to itemdef.0 and empty data
- local.name=<serv.itemdef.<local.item>.name>
- local.defname=<qval <isempty <serv.itemdef.<local.item>.defname>>?NULL:<serv.itemdef.<local.item>.defname>>
- if (<isempty <serv.itemdef.<local.item>.category>>)
- local.category=Uncategorized
- else
- // local.category=<serv.itemdef.<local.item>.category>
- local.category=<EscapeData <serv.itemdef.<local.item>.category>>
- endif
- // local.category=<qval <isempty <serv.itemdef.<local.item>.category>>?Uncategorized:<serv.itemdef.<local.item>.category>>
- local.subsection=<qval <isempty <serv.itemdef.<local.item>.subsection>>?Uncategorized:<serv.itemdef.<local.item>.subsection>>
- local.description=<qval <isempty <serv.itemdef.<local.item>.description>>?Undefined:<serv.itemdef.<local.item>.description>>
- serv.log ldb.QUERY INSERT INTO 'items' ('id','defname','name','category','subsection','description') VALUES ("<local.item>","<local.defname>","<local.name>","<local.category>","<local.subsection>","<local.description>")
- endif
- endfor
- for 0 <eval <serv.deflist.chardef.count>-1>
- local.char=<serv.deflist.chardef.<dlocal._for>>
- local.name=<serv.chardef.<local.char>.name>
- local.defname=<qval <isempty <serv.chardef.<local.item>.defname>>?NULL:<serv.chardef.<local.item>.defname>>
- local.category=<qval <isempty <serv.chardef.<local.item>.category>>?Uncategorized:<serv.chardef.<local.item>.category>>
- local.subsection=<qval <isempty <serv.chardef.<local.item>.subsection>>?Uncategorized:<serv.chardef.<local.item>.subsection>>
- local.description=<qval <isempty <serv.chardef.<local.item>.description>>?Uncategorized:<serv.chardef.<local.item>.description>>
- endfor
- LDB.EXECUTE COMMIT
- serv.log Output done in <eval <serv.rticks>-<local.hour>> seconds.
- endfor
- ldb.close
- [function f_add_clear]
- ldb.EXECUTE DROP TABLE IF EXISTS 'items'
- ldb.EXECUTE DROP TABLE IF EXISTS 'chars'
- [function f_add_search]
- local.items=itemdef
- local.chars=chardef
- local.list=<local.<ctag.adddialog_mode>>
- if (<isnum <args>>)
- local.id=<argn>
- args=<ctag.adddialog_search>
- local.obj=<argv[<dlocal.id>]>
- if <local.obj>
- ctag.adddialog_search_id=<local.id>
- local.cat=<serv.list.<ctag.adddialog_mode>.findelem "<serv.<local.list>.<local.obj>.category>">
- ctag.adddialog_page=<eval <local.cat>/14>
- ctag.adddialog_cat=<local.cat>
- local.sub=<serv.list.<ctag.adddialog_mode>_<dlocal.cat>.findelem "<serv.<local.list>.<local.obj>.subsection>">
- ctag.adddialog_cat_page=<eval <local.sub>/14>
- ctag.adddialog_sub=<local.sub>
- local.desc=<serv.list.<ctag.adddialog_mode>_<dlocal.cat>_<dlocal.sub>.findelem <local.obj>>
- ctag.adddialog_sub_page=<eval <local.desc>/14>
- ctag.adddialog_show=<local.desc>
- if (<ctag.adddialog_page>==0)
- ctag.adddialog_page
- endif
- if (<ctag.adddialog_cat_page>==0)
- ctag.adddialog_cat_page
- endif
- if (<ctag.adddialog_sub_page>==0)
- ctag.adddialog_sub_page
- endif
- dialogclose d_Add
- dialog d_add
- endif
- else
- local.string=<args>
- local.ret=0
- local.count=0
- for 0 <eval <deflist.<local.list>.count>-1>
- local.item=<deflist.<local.list>.<dlocal._for>>
- // serv.log <local.item> (<serv.<local.list>.<local.item>.name>) == STRMATCH("<serv.<local.list>.<local.item>.name>","<local.string>")
- if (STRMATCH("<serv.<local.list>.<local.item>.name>","<local.string>")==1)
- local.ret=<local.ret>,<local.item>
- local.count ++
- endif
- endfor
- if (<local.count>>0)
- ctag.adddialog_search=<streat <local.ret>>
- f_add_search 0
- endif
- dialogclose d_Add
- dialog d_add
- endif
- [function f_add_generate_main]
- //Img
- resizepic 0 0 9200 230 137 // background border
- gumppictiled 10 10 210 117 2624 // darker background
- checkertrans 10 10 210 117 // transparency layer
- //Modes
- dtext 90 30 0480 Items
- LDB.Query "SELECT id from items WHERE ROWID = 1"
- button 50 30 4005 4007 <qval <LDB.Row.NumRows>?1:0> 0 1 //No references in list? no click on buttons
- dtext 90 90 0480 Npcs
- LDB.Query "SELECT id from chars WHERE ROWID = 1"
- button 50 90 4005 4007 <qval <LDB.Row.NumRows>?1:0> 0 2
- [function f_add_generate_background]
- //img
- if !(<isempty <ctag.add_show>>)
- resizepic 0 0 9200 800 587 // background border
- gumppictiled 10 10 780 567 2624 // darker background
- gumppictiled 10 32 780 5 5058 // 1 grey separators - start here
- gumppictiled 230 37 5 400 5058 // 1
- gumppictiled 510 37 5 400 5058 // 2
- gumppictiled 10 32 510 5 5058 // 4
- gumppictiled 10 432 780 5 5058 // 5
- gumppictiled 120 432 5 150 5058 // 5
- checkertrans 10 10 780 567 // transparency layer
- elseif !(<isempty <ctag.add_sub>>) //Dynamic gump, more info = more gump, no modules, no different dialogs for the same.
- resizepic 0 0 9200 800 437 // background border
- gumppictiled 10 10 780 417 2624 // darker background
- gumppictiled 10 32 780 5 5058 // 1 grey separators - start here
- gumppictiled 230 37 5 400 5058 // 1
- gumppictiled 510 37 5 400 5058 // 2
- gumppictiled 10 32 510 5 5058 // 4
- checkertrans 10 10 780 417 // transparency layer
- elseif !(<isempty <ctag.add_cat>>)
- resizepic 0 0 9200 530 437 // background/border
- gumppictiled 10 10 510 417 2624 // darker background
- gumppictiled 10 32 510 5 5058 // 1 grey separators - start here
- gumppictiled 230 37 5 400 5058 // 2
- checkertrans 10 10 510 417 // transparency layer
- else
- resizepic 0 0 9200 250 437 // background/border
- gumppictiled 10 10 230 417 2624 // darker background
- gumppictiled 10 32 230 5 5058 // 1 grey separators - start here
- checkertrans 10 10 230 417 // transparency layer
- endif
- [function f_Add_generate_topbar]
- dtext 40 10 0480 <ctag.add_mode>
- button 10 10 4014 4045 1 0 3 //Change between items/npcs
- if (<def.adddialog_search>==1)
- dtext 170 10 0480 Search
- button 140 10 4011 4012 1 0 10 //Change between items/npcs
- endif
- if !(<isempty <ctag.add_search>>)
- local.max=<eval <f_argv <ctag.add_search>>-1>
- if (<ctag.add_search_id><<local.max>)
- dtext 480 10 0480 Search Next
- button 555 10 4005 4007 1 0 11
- endif
- if (<ctag.add_search_id>>0)
- dtext 350 10 0480 Search Previous
- button 310 10 4014 4045 1 0 12
- endif
- endif
- [function f_add_generate_categories]
- LDB.Query "SELECT category FROM <ctag.add_mode> GROUP BY category"
- local.cat=<LDB.Row.<dctag.add_cat>.category>
- local.cx=41 //Category X
- local.cy=70 //Category Y
- local.header=<local.cat>
- if (<eval STRLEN(<local.header>)>>25)
- local.header=<strsub 0 25 <local.header>>
- endif
- dtext 10 45 0480 <qval <isempty <ctag.add_cat>>==0?<local.cat> (<eval <ctag0.add_cat>+1>/<dLDB.Row.Numrows>):>
- local.index=<eval 14*<ctag0.add_page>>//We get FOR data from items_per_page*page_number
- for 0 13
- local.num=<local.index>+<local._for>
- if !(<isempty <LDB.ROW.<dlocal.num>.category>>)
- local.text=<ldb.row.<dlocal.num>.category>
- if (<eval STRLEN(<local.text>)>>28)
- local.text=<strsub 0 28 <local.text>>
- endif
- dtext <dlocal.cx> <dlocal.cy> 0480 <local.text>
- button <eval <local.cx>-30> <dlocal.cy> 4005 4007 1 0 <eval 100+<dlocal._for>>
- local.cy +=23
- endif
- endfor
- if <LDB.Row.Numrows> //I check this alone first to avoid console errors
- IF (<LDB.Row.Numrows> > <eval <local.index>+13>)
- button 200 400 4005 4007 1 0 4
- dtext 130 400 0480 Next Page
- endif
- endif
- if (<ctag0.add_page>> 0)
- button 10 400 4014 4045 1 0 5
- dtext 40 400 0480 Previous Page
- endif
- [function f_add_generate_subsections]
- IF !(<isempty <ctag.add_cat>>)
- local.sx=266 //Subsection X
- local.sy=70 //Subsection Y
- // LDB.Query "SELECT category FROM <ctag.add_mode> GROUP BY category"
- local.cat=<LDB.Row.<dctag.add_cat>.category>
- LDB.query "SELECT subsection FROM <ctag.add_mode> WHERE category = '<local.cat>' GROUP BY subsection"
- local.header=<LDB.Row.<dctag.add_sub>.subsection>
- dtext 236 45 0480 <qval <isempty <ctag.add_sub>>==0?<local.header> (<eval <ctag0.add_sub>+1>/<dLDB.Row.NumRows>):>
- local.index=<eval 14*<ctag.add_cat_page>>
- for 0 13
- local.num=<local.index>+<local._for>
- if !(<isempty <LDB.ROW.<dlocal.num>.subsection>>)
- local.text=<ldb.row.<dlocal.num>.subsection>
- if (<eval STRLEN(<local.text>)>>38)
- local.text=<strsub 0 38 <local.text>>
- endif
- dtext <dlocal.sx> <dlocal.sy> 0480 <local.text>
- button <eval <dlocal.sx>-30> <dlocal.sy> 4005 4007 1 0 <eval 200+<dlocal._for>> //boton aceptar
- local.sy +=23
- endif
- endfor
- if <LDB.Row.Numrows>
- IF (<LDB.Row.Numrows> > <eval <local.index>+13>)
- button 480 400 4005 4007 1 0 6
- dtext 410 400 0480 Next Page
- endif
- endif
- if (<ctag0.add_cat_page>> 0)
- button 236 400 4014 4045 1 0 7
- dtext 271 400 0480 Previous Page
- endif
- endif
- [function f_Add_generate_descriptions]
- IF !(<isempty <ctag.add_sub>>)
- local.dx=546 //Subsection X
- local.dy=70 //Subsection Y
- if (<ctag0.add_sub_page>)
- local.index=<eval 14*<ctag.add_sub_page>>
- else
- local.index=0
- endif
- // LDB.Query "SELECT category FROM <ctag.add_mode> GROUP BY category"
- // local.cat=<LDB.Row.<dctag.add_cat>.category>
- // LDB.query "SELECT subsection FROM <ctag.add_mode> WHERE category = '<local.cat>' GROUP BY subsection"
- local.sub=<LDB.Row.<dctag.add_sub>.subsection>
- LDB.query "SELECT id,description FROM <ctag.add_mode> WHERE subsection = '<local.sub>' GROUP BY description"
- dtext 516 45 0480 Page (<eval <ctag0.add_sub_page>+1>/<eval (<ldb.row.numrows>/14)+1>)
- for 0 13
- local.num=<local.index>+<local._for>
- local.id=<LDB.row.<dlocal.num>.id>
- IF (STRMATCH("items","<ctag.add_mode>")==1)
- local.pic <serv.itemdef.<local.id>.id>
- else
- local.pic <serv.itemdef.<serv.chardef.<local.id>.icon>.id>
- local.char=1
- endif
- local.desc=<ldb.row.<dlocal.num>.description>
- if (<dlocal.num>< <ldb.row.numrows>)
- dtext <dlocal.dx> <dlocal.dy> 0480 <local.desc>
- button 760 <dlocal.dy> 4005 4007 1 0 <eval 1000+<dlocal._for>>
- button 516 <dlocal.dy> 4011 4012 1 0 <eval 1100+<dlocal._for>>
- local.dy +=23
- endif
- endfor
- if (<ldb.row.numrows>)
- IF (<ldb.row.numrows> > <eval <local.index>+14>)
- button 760 400 4005 4007 1 0 8
- dtext 690 400 0480 Next Page
- endif
- endif
- if !(<isempty <ctag.add_sub_page>>)
- button 515 400 4014 4045 1 0 9
- dtext 550 400 0480 Previous page
- endif
- endif
- [function f_add_generate_views]
- IF !(<isempty <ctag.add_show>>)
- if (<ctag0.add_sub_page>)
- local.index=<eval 14*<ctag.add_sub_page>>
- else
- local.index=0
- endif
- local.id=<ldb.row.<dctag.add_show>.id>
- if (STRMATCH("<ctag.add_mode>","items")==1)
- dtext 126 440 0480 ID: <local.id> <qval <serv.itemdef.<local.id>.defname>?(<serv.itemdef.<local.id>.defname>):>
- dtext 126 460 0480 Name: <serv.itemdef.<local.id>.name>
- dtext 126 480 0480 Type: <serv.itemdef.<local.id>.type>
- if !(<isempty <serv.itemdef.<local.id>.tevents>>)
- dtext 126 500 0480 Tevents: <serv.itemdef.<local.id>.tevents>
- endif
- local.y=440
- if !(<isempty <serv.itemdef.<local.id>.skillmake>>)
- dtext 366 <dlocal.y> 0480 Skillmake: <serv.itemdef.<local.id>.skillmake>
- local.y +=20
- endif
- if !(<isempty <serv.itemdef.<local.id>.resources>>)
- dtext 366 <dlocal.y> 0480 Resources: <serv.itemdef.<local.id>.resources>
- local.y +=20
- endif
- if (<serv.itemdef.<local.id>.tag0.GargoyleOnly>==1)
- dtext 366 <dlocal.y> 0480 Gargoyle Item
- local.y +=20
- endif
- tilepic 30 440 <serv.itemdef.<local.id>.id>
- button 126 554 4005 4007 1 0 <eval 1000+<ctag.add_show>>
- dtext 156 554 0480 Create
- else
- dtext 126 440 0480 ID: <local.id>
- dtext 126 460 0480 Name: <serv.chardef.<local.id>.name>
- dtext 126 480 0480 //Tevents: <serv.chardef.<local.id>.tevents>
- dtext 126 500 0480
- local.y=440
- tilepic 30 440 <serv.chardef.<local.id>.icon>
- button 126 554 4005 4007 1 0 <eval 1000+<ctag.add_show>>
- dtext 156 554 0480 Create
- dtext 626 440 0480 Create spawn
- dtext 600 460 0480 Amount
- dtextentry 680 460 20 20 33 1 1
- dtext 600 480 0480 Min Time
- dtextentry 680 480 20 20 33 2 5
- dtext 600 500 0480 Max Time
- dtextentry 680 500 20 20 33 3 15
- dtext 600 520 0480 Max Distance
- dtextentry 680 520 20 20 33 4 15
- button 600 554 4005 4007 1 0 <eval 1200+<ctag.add_show>>
- dtext 630 554 0480 Create Spawn
- endif
- endif
- [dialog d_add]
- 6,32
- ldb.close
- ldb.connect adddialog.db
- IF (<isempty <ctag.add_mode>>)
- f_add_generate_main //Dialog shown when no item or npc view is selected yet.
- else
- f_add_generate_background //Dynamic background increasing/decreasing according to the amount of menus we are seeing.
- f_add_generate_topbar //Displaying top bar
- f_add_generate_categories //Filling categories menu (if selected items or npcs)
- f_add_generate_subsections //Filling subsections menu (if looking into any)
- f_add_generate_descriptions //Final list of items or npcs of the selected category+subsection
- f_add_generate_views //Showing detailed information about the selected item or npc
- endif
- [DIALOG d_add BUTTON]
- ON=1
- ctag.add_mode=items
- dialog d_add
- ON=2
- ctag.add_mode=chars
- dialog d_Add
- ON=3
- ctag.add_show
- ctag.add_page
- ctag.add_mode
- ctag.add_cat
- ctag.add_sub
- ctag.add_cat_page
- ctag.add_sub_page
- ctag.add_search
- ctag.add_search_id
- dialog d_add
- ON=4
- ctag0.add_page +=1
- dialog d_add
- ON=5
- ctag0.add_page -=1
- dialog d_add
- ON=6
- ctag0.add_cat_page +=1
- dialog d_add
- ON=7
- ctag0.add_cat_page -=1
- dialog d_add
- ON=8
- ctag0.add_sub_page +=1
- dialog d_add
- ON=9
- ctag0.add_sub_page -=1
- dialog d_add
- ON=10
- sysmessage=Type the text to search.
- promptconsole f_add_search
- ON=11
- f_add_search <eval <ctag.add_search_id>+1>
- ON=12
- f_add_search <eval <ctag.add_search_id>-1>
- ON=100 115 //categories
- if (<ctag0.add_page>)
- local.index=<eval 14*<ctag.add_page>>
- else
- local.index=0
- endif
- local.num=<eval (<argn>-100)+<local.index>>
- ctag.add_cat=<local.num>
- ctag.add_cat_page
- ctag.add_sub
- ctag.add_sub_page
- ctag.add_show
- ctag.add_search
- ctag.add_search_id
- dialog d_Add
- ON=200 215
- if (<ctag0.add_cat_page>)
- local.index=<eval 14*<ctag.add_cat_page>>
- else
- local.index=0
- endif
- local.num=<eval (<argn>-200)+<local.index>>
- ctag.add_sub=<local.num>
- ctag.add_sub_page
- ctag.add_show
- ctag.add_search
- ctag.add_search_id
- dialog d_Add
- ON=1000 1015
- if (<ctag0.add_sub_page>)
- local.index=<eval 14*<ctag.add_sub_page>>
- else
- local.index=0
- endif
- local.listid=<ctag.add_mode>_<dctag.add_cat>_<dctag.add_sub>
- local.id=<serv.list.<local.listid>.<eval <local.index>+(<argn>-1000)>>
- if (STRMATCH("ITEMS","<ctag.add_mode>")==1)
- if (<serv.itemdef.<local.id>.id>)
- add <local.id>
- endif
- elseif (STRMATCH("chars","<ctag.add_mode>")==1)
- if (<serv.chardef.<local.id>>)
- addnpc <local.id>
- endif
- endif
- ON=1100 1115
- if (<ctag0.add_sub_page>)
- local.index=<eval 14*<ctag.add_sub_page>>
- else
- local.index=0
- endif
- ctag.add_show=<eval <argn>-1100>
- dialog d_add
- ON=1200 1215
- if (<ctag0.add_sub_page>)
- local.index=<eval 14*<ctag.add_sub_page>>
- else
- local.index=0
- endif
- local.listid=<ctag.add_mode>_<dctag.add_cat>_<dctag.add_sub>
- local.id=<serv.list.<local.listid>.<eval <local.index>+(<argn>-1200)>>
- targetfg f_createspawn <local.id>,<argtxt[1]>,<argtxt[2]>,<argtxt[3]>,<argtxt[4]>
- sysmessage=Where do you want to place the spawn?
- [FUNCTION f_argv]
- RETURN <ARGV>
- [function f_createspawn]
- serv.newitem=i_worldgem_bit
- new.more=<argv[0]>
- new.amount=<argv[1]>
- new.morep=<argv[2]>,<argv[3]>,<argv[4]>
- new.p=<p>
- new.p=<targp>
- new.dclick
- [function EscapeData]
- local.text=<args>
- local.text=<asciireplace 40,[,<local.text>> //Replacing ( for [
- local.text=<asciireplace 41,],<local.text>> //Replacing ) for ]
- return <local.text>
- [function asciireplace]
- local.ascii=<argv[0]>
- local.new=<argv[1]>
- local.text=<streat <streat <args>>>
- local.a=<strpos 0 <dlocal.ascii> <args>>
- while <local.a>>0
- local.len=<eval STRLEN(<local.text>)>
- local.pos=<strpos 0 <dlocal.ascii> <local.text>>
- if (<local.pos>==0)
- local.text=<local.new><strsub <eval <local.pos>+1> <local.len> <local.text>>
- else
- local.text=<strsub 0 <local.pos> <local.text>><local.new><strsub <eval <local.pos>+1> <local.len> <local.text>>
- endif
- if (<strpos 0 <dlocal.ascii> <local.text>>==-1)
- local.a=0
- endif
- endwhile
- return <local.text>
- [EOF]
Advertisement
Add Comment
Please, Sign In to add comment