本帖最后由 KA 于 2010-5-24 13:47 编辑
由于lua版本中50指令对话的效率实在是太低了(- -),于是本人写了一个lua的新对话指令,用法与50指令对话相同
效果图在此
代码
- function talk50(id1,id2,id3,id4)
- local namex,namey,headx,heady,talkx,talky;
- local talkwidth,talkheight;
- local txtnum,txtline;
- local talkaddr,headop,talkcolor;
- local s=ReadTALK(id2);
- local startup=1;local endup=string.len(s);
- talkcolor=math.modf(id4/100);
- headop=(id4%100)/10;
- talkaddr=id4%10;
- local fontsize=18;
- local color;
- local color0=28515;
- local color1=28421;
- local color2=28435;
- local color3=28563;
- local color4=28466;
- local color5=28450;
-
- if talkcolor==0 then
- color=ReadCol(color0%256);
- elseif talkcolor==1 then
- color=ReadCol(color1%256);
- elseif talkcolor==2 then
- color=ReadCol(color2%256);
- elseif talkcolor==3 then
- color=ReadCol(color3%256);
- elseif talkcolor==4 then
- color=ReadCol(color4%256);
- elseif talkcolor==5 then
- color=ReadCol(color5%256);
- end
- --const x,y with config Type
- while startup<endup do
- Cls();
- if CONFIG.Type==0 then
- namex=81;namey=139;
- talkwidth=224;talkheight=64;
- talkx=81;talky=164;
- headx=16;heady=166;
- txtnum=13;txtline=3;
- if talkaddr==1 then
- namex=158;
- talkx=16;headx=248;
- end
- else
- namex=167;namey=340
- talkwidth=438;talkheight=96;
- talkx=105;talky=372;
- headx=105;heady=306;
- txtnum=25;txtline=5;
- if talkaddr==1 then
- namex=398;
- headx=483;
- end
- end
-
-
- if headop==0 or id3~=0 then
- DrawBox(headx,heady,headx+60,heady+62,C_WHITE);
- lib.PicLoadCache(1,id1*2,headx+2,heady+59);
-
- local strname;
- if id3==-2 then
- strname=JY.Person[id1]['姓名'];
- elseif id3==0 then
- strname="";
- else
- strname=ReadTALK(id3);
- end
- --local strname=READTALK(id3);
- local strlong=string.len(strname);
- DrawBox(namex,namey,namex+82,namey+28,C_WHITE);
- DrawString(namex+44-(strlong*4.5),namey+5,strname,C_WHITE,fontsize);
- end
- local sx=0;local sy=0;
- local talkstr="";
- DrawBox(talkx,talky,talkx+talkwidth,talky+talkheight,C_WHITE);
-
- while sy < txtline do
- while sx < txtnum-1 do
- --lib.Debug("sx="..sx..",sy="..sy);
- talkstr=string.sub(s,startup,startup+1);
- if string.byte(talkstr,1) == 42 then
- --lib.Debug(string.byte(talkstr,1) );
- if string.byte(talkstr,2)==42 then --**
- sy=sy+1;
- sx=0;
- else
- startup=startup-1;
- end
- elseif string.byte(talkstr,1)==94 and string.byte(talkstr,2)==48 then --^0
- color=color0;
- color=ReadCol(color%256);
- elseif string.byte(talkstr,1)==94 and string.byte(talkstr,2)==49 then --^1
- color=color1;
- color=ReadCol(color%256);
- elseif string.byte(talkstr,1)==94 and string.byte(talkstr,2)==50 then --^2
- color=color2;
- color=ReadCol(color%256);
- elseif string.byte(talkstr,1)==94 and string.byte(talkstr,2)==51 then
- color=color3;
- color=ReadCol(color%256);
- elseif string.byte(talkstr,1)==94 and string.byte(talkstr,2)==52 then
- color=color4;
- color=ReadCol(color%256);
- elseif string.byte(talkstr,1)==94 and string.byte(talkstr,2)==53 then
- color=color5;
- color=ReadCol(color%256);
- elseif string.byte(talkstr,1)==38 and string.byte(talkstr,2)==38 then --&&
- local tmpname=JY.Person[0]['姓名'];
- DrawString(talkx+5+sx*fontsize,talky+5+sy*fontsize,tmpname,color,fontsize);
- sx=sx+string.len(tmpname)/2;
- elseif string.byte(talkstr,1)==64 and string.byte(talkstr,2)==64 then --@@
- ShowScreen();
- WaitKey();
- elseif string.byte(talkstr,1)==94 and string.byte(talkstr,2)==94 then --^^
- if talkcolor==0 then
- color=ReadCol(color0%256);
- elseif talkcolor==1 then
- color=ReadCol(color1%256);
- elseif talkcolor==2 then
- color=ReadCol(color2%256);
- elseif talkcolor==3 then
- color=ReadCol(color3%256);
- elseif talkcolor==4 then
- color=ReadCol(color4%256);
- elseif talkcolor==5 then
- color=ReadCol(color5%256);
- end
- else
- DrawString(talkx+5+sx*fontsize,talky+5+sy*fontsize,talkstr,color,fontsize);
- sx=sx+1;
- end
- startup=startup+2;
- end
- sy=sy+1;
- sx=0;
- end
- ShowScreen();
- WaitKey();
- end
- end
复制代码
- --其余用到的函数
- function ReadCol(id)
- local r,g,b,col;
- col=Byte.create(4);
- Byte.loadfile(col,CONFIG.DataPath..'mmap.col',id*3,3);
- b,g,r=GetRGB(Byte.get32(col,0));
- return RGB(r*4,g*4,b*4);
- end
- function ReadTALK(id,flag)
- local tidx=Byte.create(id*4+4)
- Byte.loadfile(tidx,CC.TDX,0,id*4+4)
- local idx1,idx2
- if id<1 then
- idx1=0
- else
- idx1=Byte.get32(tidx,(id-1)*4)
- end
- idx2=Byte.get32(tidx,id*4)
- local len=idx2-idx1
- local talk=Byte.create(len)
- Byte.loadfile(talk,CC.TRP,idx1,len)
- local str=''
- --str=Byte.getstr(talk,0,len)
-
- for i=0,len-2 do
- local byte=Byte.getu16(talk,i)
- byte=255-math.fmod(byte,256)
- --Byte.setu16(talk,i,byte)
- str=str..string.char(byte)
- end
- --str=lib.CharSet(Byte.getstr(talk,0,len),0)
- --lib.Debug(string.format('id=%d,idx1=%d,idx2=%d,len=%d,str=%s',id,idx1,idx2,len,str))
- if flag==nil then
- str=lib.CharSet(str,0)
- str=GenTalkString(str,12);
- end
- return str;
- end
复制代码 谢谢大家,谢谢 |