Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////////////////
- //New .add dialog version 1.4
- //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 .add1
- //To 'reset' data, type .f_add_clear and then .f_add_setup again
- //
- //Note: As it is reading items/chars placed and no placed in the world, you may get some errors in console regarding to these items/chars
- ////////////////////////////////////////////////////////////////////////////////////////////
- //v1.1 Lists modified to use numbers instead of names, so there are not needed the functions to fix their names and thei are now seen 100% like in the scripts
- //WARNING: To update the script you must type f_add_update otherwise the dialog wont show anything if you dont update the lists or you will have useless lists if you do not clear the old ones.
- //
- //v1.2 Removed tilepics from items/chars and placed a button that adds a new block with information about them, also a 'spawner' for chars.
- //
- //v1.3 Using tags instead of args to create the lists, so categories,etc with commas doesn't get fucked up in the proccess (This fixes some categories wrong sorted).
- // Now each block is showing 1 entry less so it shows a header of the menu you are on and a count of entry/total entries and page/totalpages in the items/chars section, also removed this from the top of the dialog in preparation for search box
- //
- //v1.4 Added search function, it's heavy so not recommended to use with players in the server since it will stop sphere for 3 seconds aprox. (It comes with a def so you can disable it via script and any staff member use it)
- //Fixed Create button from item's show box not working in pages > 0
- //Added a bypass for .add i_whatever/c_whatever while using f_oncommand override.
- [DEFNAME adddef]
- adddialog_search=1 //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) //old .add i_whatever behaviour.
- return 0
- elseif (STRMATCH("add","<args>")==1)
- add1
- return 1
- endif
- [function add1]
- if !(<ldb.connected>)
- ldb.connect adddialog.db
- // serv.log Connecting to table adddialog
- endif
- dialogclose d_add
- dialog d_add
- ldb.close
- [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 'items.category'
- // ldb.EXECUTE DROP TABLE IF EXISTS 'items.subsection'
- // ldb.EXECUTE DROP TABLE IF EXISTS 'items.description'
- ldb.EXECUTE DROP TABLE IF EXISTS 'chars'
- // ldb.EXECUTE DROP TABLE IF EXISTS 'chars.category'
- // ldb.EXECUTE DROP TABLE IF EXISTS 'chars.subsection'
- // ldb.EXECUTE DROP TABLE IF EXISTS 'chars.description'
- if (<ldb.connected>)
- ldb.execute CREATE TABLE 'items' ('id' VARCHAR(128) PRIMARY KEY NOT NULL,'defname' WORD, 'name' VARCHAR(32),'category' VARCHAR(32),'subsection' VARCHAR(32),'description' VARCHAR(32))
- // ldb.execute CREATE TABLE 'items.category' ('id' VARCHAR(32) UNIQUE)
- // ldb.execute CREATE TABLE 'items.subsection' ('id' VARCHAR(32) UNIQUE)
- // ldb.execute CREATE TABLE 'items.desccription' ('id' VARCHAR(32) UNIQUE)
- ldb.execute CREATE TABLE 'chars' ('id' VARCHAR(128) PRIMARY KEY NOT NULL,'defname' WORD, 'name' VARCHAR(32))
- // ldb.execute CREATE TABLE 'chars.category' ('id' VARCHAR(32) UNIQUE)
- // ldb.execute CREATE TABLE 'chars.subsection' ('id' VARCHAR(32) UNIQUE)
- // ldb.execute CREATE TABLE 'chars.desccription' ('id' VARCHAR(32) UNIQUE)
- local.hour=<serv.rticks>
- LDB.EXECUTE BEGIN
- for 0 500//<eval <serv.deflist.itemdef.count>-1>
- local.item=<serv.deflist.itemdef.<dlocal._for>>
- local.name=<serv.itemdef.<local.item>.name>
- local.defname=<qval <isempty <serv.itemdef.<local.item>.defname>>?NULL:<serv.itemdef.<local.item>.defname>>
- 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>>?Uncategorized:<serv.itemdef.<local.item>.description>>
- // serv.log Query items = ('id','defname','name') VALUES ('<local.item>','<local.defname>','<local.name>')
- // serv.log Query info[<local.item>] = <local.category> , <local.subsection> , <local.description>
- // ldb.QUERY INSERT INTO 'items' ('id','defname','name') VALUES ('<local.item>','<local.defname>','<local.name>')
- ldb.QUERY INSERT INTO 'items' ('id','defname','name','category','subsection','description') VALUES ('<local.item>','<local.defname>','<db.escapedata <local.name>>','<db.escapedata <local.category>>','<db.escapedata <local.subsection>>','<db.escapedata <local.description>>')
- // if !(<local.category.<local.category>>)
- // ldb.QUERY INSERT INTO 'items.category' ('id') VALUES ('<local.category>')
- // local.category.<local.category>=1
- // else
- // serv.log duplicate cat
- // endif
- // if !(<local.subsection.<local.subsection>>)
- // ldb.QUERY INSERT INTO 'items.subsection' ('id') VALUES ('<local.subsection>')
- // local.subsection.<local.subsection>=1
- // else
- // serv.log duplicate sun
- // endif
- // if !(<local.description.<local.description>>)
- // ldb.QUERY INSERT INTO 'items.description' ('id') VALUES ('<local.description>')
- // local.description.<local.description>=1
- // else
- // serv.log duplicate desc
- // endif
- 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]
- [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
- button 50 30 4005 4007 <qval <isempty <serv.list.items.count>>?0:1> 0 1 //No references in list? no click on buttons
- dtext 90 90 0480 Npcs
- button 50 90 4005 4007 <qval <isempty <serv.list.chars.count>>?0:1> 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]
- local.cx=41 //Category X
- local.cy=70 //Category Y
- local.header=<serv.list.<ctag.add_mode>.<dctag.add_cat>>
- if (<eval STRLEN(<local.header>)>>25)
- local.header=<strsub 0 25 <local.header>>
- endif
- ldb.close
- ldb.connect adddialog.db
- dtext 10 45 0480 <qval <isempty <ctag.add_cat>>==0?<local.header> (<dctag.add_cat>/<eval <serv.list.<ctag.add_mode>.count>-1>):>
- local.list=<ctag.add_mode> //To avoid confusion, its better to store 'list structure' in one local and then get it out
- local.index=<eval 14*<ctag0.adddialog_page>>//We get FOR data from items_per_page*page_number
- LDB.query "SELECT category FROM <local.list> WHERE ROWID >= <dlocal.index> AND ROWID <= <eval <local.index>+14>"
- sysmessage=total= <ldb.row.numrows> ("SELECT * FROM <local.list> WHERE ROWID >= <dlocal.index> AND ROWID <= <eval <local.index>+14>")
- for 0 13
- local.num=<local.index>+<local._for>
- if !(<isempty <serv.list.<local.list>.<dlocal.num>>>)
- 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 <serv.list.<local.list>.count> //I check this alone first to avoid console errors
- IF (<serv.list.<local.list>.count> > <eval <local.index>+15>)
- button 200 400 4005 4007 1 0 4
- dtext 130 400 0480 Next Page
- endif
- endif
- if (<ctag0.adddialog_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
- local.header=<serv.list.<ctag.add_mode>_<dctag.add_cat>.<dctag.add_sub>>
- dtext 236 45 0480 <qval <isempty <ctag.add_sub>>==0?<local.header> (<dctag.add_sub>/<eval <serv.list.<ctag.add_mode>_<dctag.add_cat>.count>-1>):>
- local.index=<eval 14*<ctag.add_cat_page>>
- local.list=<ctag.add_mode>_<dctag.add_cat>
- for 0 13
- local.num=<local.index>+<local._for>
- if <dlocal.num>< <serv.list.<local.list>.count>
- local.text=<serv.list.<local.list>.<dlocal.num>>
- 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 <serv.list.<local.list>.count>
- IF (<serv.list.<local.list>.count> > <eval <local.index>+13>)
- button 480 400 4005 4007 1 0 6
- dtext 410 400 0480 Next Page
- endif
- endif
- if (<ctag0.adddialog_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.adddialog_sub_page>)
- local.index=<eval 14*<ctag.add_sub_page>>
- else
- local.index=0
- endif
- local.header=<serv.list.<ctag.add_mode>_<dctag.add_cat>.<dctag.add_sub>>
- dtext 516 45 0480 Page (<dctag.add_sub_page>/<eval <serv.list.<ctag.add_mode>_<dctag.add_cat>_<dctag.add_sub>.count>/14>)
- local.list=<ctag.add_mode>_<dctag.add_cat>_<dctag.add_sub>
- for 0 13
- local.num=<local.index>+<local._for>
- local.id=<serv.list.<local.list>.<dlocal.num>>
- IF (STRMATCH("items","<ctag.add_mode>")==1)
- local.pic <serv.itemdef.<local.id>.id>
- if (<isempty <serv.itemdef.<local.id>.description>>)
- local.desc=<serv.itemdef.<local.id>.name>
- else
- local.desc=<serv.itemdef.<local.id>.description>
- endif
- else
- local.pic <serv.itemdef.<serv.chardef.<local.id>.icon>.id>
- local.char=1
- if (<isempty <serv.chardef.<local.id>.description>>)
- local.desc=<serv.chardef.<local.id>.name>
- else
- local.desc=<serv.chardef.<local.id>.description>
- endif
- endif
- if !(<isempty <serv.list.<local.list>.<dlocal.num>>>)
- 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 <serv.list.<local.list>.count>
- IF (<serv.list.<local.list>.count> > <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.adddialog_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>+<ctag.add_show>>>
- // local.id=<serv.list.<ctag.add_mode>_<dctag.add_cat>_<dctag.add_sub>.<dctag.add_show>>
- 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
- 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
- ldb.close
- [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.adddialog_page +=1
- dialog d_add
- ON=5
- ctag0.adddialog_page -=1
- dialog d_add
- ON=6
- ctag0.adddialog_cat_page +=1
- dialog d_add
- ON=7
- ctag0.adddialog_cat_page -=1
- dialog d_add
- ON=8
- ctag0.adddialog_sub_page +=1
- dialog d_add
- ON=9
- ctag0.adddialog_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.adddialog_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.adddialog_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.adddialog_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.adddialog_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.adddialog_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
- [EOF]
Advertisement
Add Comment
Please, Sign In to add comment