-- DESCRIPTION: This is a custom behavior, and can be configured with [customvalue1=0(0,100)], [customvalue2=0(0,100)] and [customvalue3=0(0,100)]. master_interpreter_core = require "scriptbank\\masterinterpreter" ---------- patrol or what ever default activity ------ g_patrol = {} g_patrol_behavior = {} g_patrol_behavior_count = 0 g_stand_and_speak = {} g_stand_and_speak_behavior = {} g_stand_and_speak_behavior_count = 0 ------------------- end ---------------- g_npc_conversation1 = {} g_npc_conversation1_behavior = {} g_npc_conversation1_behavior_count = 0 -- LUA Script - precede every function and global member with lowercase name of script + '_main' -- Branching NPC Conv script add to NPC action 1.1.1 -- Define flags to communicate with other scripts FLAG_DIALOG = 1 -- Define the constants TALK_DISTANCE = 150 StringNPC = {} NumStringsN = {} FlagGenericN = {} ConversationPhase = {} TextTime = {} EntityName = {} local pressed = 0; local hud_on = 0; local convo = {} local timer = {} local timed = {} local started = {} local response = {} local my_object_name = {} local parsejob local parsefunction local parsename local parsescript local parsetalking local parseMSG local parseRSP = {} local parseAction = {} local rgb1 local rgb2 local rgb3 local tbl2 = {} local tblIDX2 -------------------------------------------------- local varName = "" local varValue = "" local msgflag = "" local msgNBR = 1 local lastval = 0 local speakerIDX local responseIDX local actionIDX local speaker = {} local response = {} local action = {} npcknown = {} knownmax = 0 local printline local msgnbr local speakerMAX local responseMAX local actionMAX local TableLoad local actionTRG = 0 -------------------------------------------------- function npc_conversation1_init(e) --g_npc_conversation1[e] = {} --g_npc_conversation1[e]["bycfilename"] = "scriptbank\\user\\npc_conversation1.byc" --g_npc_conversation1_behavior_count = master_interpreter_core.masterinterpreter_load (g_npc_conversation1[e], --g_npc_conversation1_behavior ) --npc_conversation1_properties(e,0,0,0) ------------ patrol or default activity --------------------- g_patrol[e] = {} g_patrol[e]["bycfilename"] = "scriptbank\\people\\patrol.byc" g_patrol_behavior_count = master_interpreter_core.masterinterpreter_load (g_patrol[e], g_patrol_behavior ) patrol_properties(e,1) g_stand_and_speak[e] = {} g_stand_and_speak[e]["bycfilename"] = "scriptbank\\people\\stand_and_speak.byc" g_stand_and_speak_behavior_count = master_interpreter_core.masterinterpreter_load (g_stand_and_speak[e], g_stand_and_speak_behavior ) stand_and_speak_properties(e,300,"") --------------------------------------------------------------- EntityName[e] = name -- Initiate the shop and menu state ShopActive = 0 MenuActive = 0 -- Init the text ConversationPhase[e] = 1 TextTime[e] = 0 FlagGenericN[e] = 0 -- new --Include("ai_cover.lua") convo = 0 timer[e] = 0 timed[e] = 0 started[e] = 0 response[e] = 0 -- HUD Code HideHuds() HUD1=0 HUD2=0 keycheck=0 respawned=0 talkingto=" " engaged = 0 --- HUD code strIDX = {} parsejob=" " parseprime=" " parsename=" " parsescript=" " parsefunction=" " parsetalking =" " parseMSG=" " parseRSP[e] = 0 parseAction[e] = 0 knowspeaker = 0 -- new TableLoad = 0 Maction = "" msgNBR = 1 menu=0 emousex = 0 emousey = 0 mouseOn = 0 emousex = 0 emousey = 0 talkdist = 150 loopCNV =0 talktome = 1 ------- move this section to main to reload origional conversation ------- if you do not want the progression of the previous talk to ------- still be the active one with prior results active if TableLoad == 0 then -- Pick up entitys name or id for file location speakerMAX = GetEntityName ( e ) parseNPC(speakerMAX) npc_conversation1_loadchat(parsename) TableLoad = 1 msgNBR=1 menu=0 end ------- move this section to main to reload origional conversation end ---------------------- patrol or default function patrol_properties(e,allowheadshot) g_patrol[e]['allowheadshot'] = allowheadshot master_interpreter_core.masterinterpreter_restart (g_patrol[e], g_Entity[e]) end function stand_and_speak_properties(e, range, speech1) g_stand_and_speak[e]['range'] = range g_stand_and_speak[e]['speech1'] = speech1 master_interpreter_core.masterinterpreter_restart (g_stand_and_speak[e], g_Entity[e]) end -------------------------------------------- function npc_conversation1_properties(e, customvalue1, customvalue2, customvalue3) g_npc_conversation1[e]['customvalue1'] = customvalue1 g_npc_conversation1[e]['customvalue2'] = customvalue2 g_npc_conversation1[e]['customvalue3'] = customvalue3 master_interpreter_core.masterinterpreter_restart (g_npc_conversation1[e], g_Entity[e]) end function npc_conversation1_main(e) if g_npc_conversation1[e] ~= nil and g_npc_conversation1_behavior_count > 0 then g_npc_conversation1_behavior_count = master_interpreter_core.masterinterpreter (g_npc_conversation1_behavior, g_npc_conversation1_behavior_count, e, g_npc_conversation1[e], g_Entity[e]) end ----------------------------------------------------- PlayerDist = GetPlayerDistance(e) if PlayerDist < talkdist and talktome == 1 then RotateToPlayer(e) HideHuds() SetPlayerWeapons(0) engaged = 1 ---------------------- stand there --------- if g_stand_and_speak[e] ~= nil and g_stand_and_speak_behavior_count > 0 then g_stand_and_speak_behavior_count = master_interpreter_core.masterinterpreter (g_stand_and_speak_behavior, g_stand_and_speak_behavior_count, e, g_stand_and_speak[e], g_Entity[e]) -- debug - report default action takeing place action -- PromptDuration(" Im talking here no talk flag "..talktome.." ",2000) -- debug line above only for testing end ------------------- if mouseOn == 1 then SetSpritePosition ( pointerSprite , g_MouseX , g_MouseY ) elseif menu == 1 then SetSpritePosition ( pointerSprite , 200 , 200 ) end ------------------------- etotalk image if HUD1 == 0 and keycheck == 0 and talktome == 1 then cursor_im=LoadImage ( "imagebank\\user\\etotalk.png" ) cursor_sp=CreateSprite (cursor_im ) SetSpritePosition ( cursor_sp , 45 , 45 ) SetSpriteSize( cursor_sp,9,9) PromptDuration(" Hello, You need help?",2000) HUD1=1 keycheck=1 menu=0 end if HUD1 == 1 and keycheck ==1 and talktome == 1 then convo = 9999 if g_KeyPressE == 1 then convo = 0 DeleteSprite(cursor_sp) keycheck = 2 HUD1=0 pointerImage = LoadImage ( "imagebank\\user\\arrow1.png" ) pointerSprite = CreateSprite ( pointerImage ) SetSpriteSize ( pointerSprite , 5 , -1 ) SetSpriteOffset ( pointerSprite , 2, 0) SetSpritePosition ( pointerSprite , 200 , 200) HUD2=1 responTRG = nil if menu==0 then emousex = g_MouseX emousey = g_MouseY SetSpriteSize ( pointerSprite , 5 , -1 ) SetSpriteOffset ( pointerSprite , 2, 0) --Text(50,80,6,"Freeze display at "..emousex.." g_mouseY " ..emousey) menu=1 emousex = g_MouseX emousey = g_MouseY SetSpritePosition ( pointerSprite , 70 , 48 ) ActivateMouse() mouseOn = 1 convo=0 TableLoad=0 msgNBR=1 end end end if convo == 0 and talktome == 1 then if responTRG ~= nil then npc_conversation1_respond(responTRG) -- do test for clicked response varName = response[responTRG] [4] [1] varValue = response[responTRG] [4] [2] if tonumber(actionTRG) > 0 then -- process this action from a previous response npc_conversation1_effect_adjust(e) end if varName=="s" then responTRG = nil msgNBR=varValue loopCNV=0 elseif varName=="e" then talktome = 0 varName = "x" --- check for exit request end end if responTRG == nil then npc_conversation1_ai(e,msgNBR) end end else -- When player moves away, reset the conversation npc_conversation1_endconvo(e) if PlayerDist > talkdist and talktome == 0 then talktome = 1 end if PlayerDist > talkdist and engaged == 1 then engaged = 0 -------------- reset patrol or other action ---------------- patrol_properties(e,allowheadshot) stand_and_speak_properties(e, range, speech1) ------------------------------------------------------------ end end -------------------- if PlayerDist > talkdist then --------- process non talking default -------- if g_patrol[e] ~= nil and g_patrol_behavior_count > 0 then g_patrol_behavior_count = master_interpreter_core.masterinterpreter (g_patrol_behavior, g_patrol_behavior_count, e, g_patrol[e], g_Entity[e]) -- debug - report default action takeing place action PromptDuration(" Im walking here no talk flag "..talktome.." ",2000) -- debug line above only for testing --talktome = 0 end end ------------------ end function npc_conversation1_endconvo(e) ConversationPhase[e] = 1 TextTime[e] = 0 responTRG = nil convo=999 npc_conversation1_clearhud(e) HUD1=0 HUD2=0 mouseOn=0 keycheck=0 menu=0 end function npc_conversation1_clearhud(e) if HUD1 == 1 then DeleteSprite(cursor_sp) HUD1=0 end if mouseOn == 1 then DeleteSprite(pointerSprite) DeactivateMouse() mouseOn = 0 end g_KeyPressE = 0 keycheck=0 SetPlayerWeapons(1) ShowHuds() end function npc_conversation1_action(Maction) -- if Maction == "a1" then -- ConversationPhase[e] = 2 --end --if Maction == "a2" then -- SwitchScript(e,"scripbank\\ai_cover") --end end -- Origional CODE BY !nullptr (aka SisterMatic) - please credit - not fussed - :) -- Major modified for this usage. function parseNPC(s) ---------- break out the entity name field ex: " Burt",GateGuard,faction -------- ---------- script = script reference to run if wanted no spaces .. faction for NPC VS NPC fights -- set array local tbl = {} -- set array index local tblIDX = 1 local y = 10 for i in string.gmatch(s, "%w+") do tbl[tblIDX] = i tblIDX=tblIDX+1 end tblIDX = tblIDX - 1 -- **************** -- debug - display the strings we have --TextCenterOnX(50,y,1,"We have "..tblIDX.." var strings derived from the entity name of "..s) for i=1, tblIDX, 1 do y=y+3 --TextCenterOnX(50,y,1,tbl[i]) if i==1 then parsename= tbl[i] end if parsename == nil then parsename = "Resident" end if i==2 then parsejob= tbl[i] end if parsejob == nil then parsejob = "Local" end if i==3 then parseprime= tbl[i] end if i==4 then parsefaction= tbl[i] end end end function parsemessage(text) ------------------ break out the speach text is in data file first "text" -------- ------------------ ex: "What the heck are you doing here and what is that",s1,p1,p8,p10,q5 y=10 local e = 0 while true do -------------------- identify the quoted text first local b = e+1 b = text:find("%S",b) if b==nil then break end if text:sub(b,b)=="'" then e = text:find("'",b+1) b = b+1 elseif text:sub(b,b)=='"' then e = text:find('"',b+1) b = b+1 else e = text:find("%s",b+1) end if e==nil then e=#text+1 end if y==10 then parseMSG = text:sub(b,e-1) end ---------------- break down speaker and results -------- if y > 10 then tbl2 = {} -- set array index tblIDX2 = 1 for i in string.gmatch(text:sub(b,e-1), "%w+") do tbl2[tblIDX2] = i tblIDX2=tblIDX2+1 end tblIDX2 = tblIDX2 - 1 -- **************** -- debug - display the strings we have --TextCenterOnX(50,y,1,"We have "..tblIDX2.." var strings derived from the entity name of "..text:sub(b,e-1)) for i=1, tblIDX2, 1 do y=y+3 --TextCenterOnX(50,y,1,tbl2[i]) if i==1 then parsetalking = tbl2[i] end if i>1 then parseRSP[i-1] = tbl2[i] end end end y=y+3 end end function npc_conversation1_loadchat(parsename) ------------- new load from file --------------- if TextSize == nil then TextSize = 1 end NumStringsN[parsename] = 0 local NFile NFile = nil -- Read NPC string from a file parsename -- debug - display the strings we have -- debug - report default action takeing place action -- PromptDuration(" Looking for "..parsename.."'s speach file",2000) -- debug line above only for testing if parsename ~= nil then NFile = io.open("databank\\user\\"..parsename..".txt", "r") if NFile ~= nil then -- If there is a File, read it and store it to StringNP table -- debug - report default action takeing place action --PromptDuration(" Im reading "..parsename.."'s speach file ",2000) -- debug line above only for testing local NLine = 1 while true do StringNPC[NLine] = NFile:read("*l") if StringNPC[NLine] == nil then break end NumStringsN[parsename] = NLine -- debug - report default action takeing place action --PromptDuration("Speach line "..StringNPC[NLine].." "..NumStringsN[parsename].." line "..parsename.." ",6000) -- debug line above only for testing NLine = NLine + 1 end NFile:close() end end ------------- end load from file if TextSize == nil then TextSize = 1 end if NumStringsN[parsename] <= 1 then -- if no file for the NPC is found then load a default script --- -- debug - report default action takeing place action --PromptDuration("Load default Speach ",6000) -- debug line above only for testing -- How this works ":What is said goes here:,s for speaker p for player conv #, where the conversatioon goes next -- s for speaker line to say p for player line to say, then if speaker all the responses that the player can give" -- branching conversation string s# is speaker says p# is player says rep# is change in rep if selected -- can currently use rep for peputation adj, act for action to perform on response. -- abbility to add more functionsality is endless -- rep starts at a 200 = 0 change - the rep change 150 = -50 rep loss 210 = 10 rep gain -- order is not limited to anything use p# s# for follow up speach and reply -- What NPC says FlagGenericN[parsename] = 1 -- NPC says this is a sample default conversation see NPC speach file for custom speach StringNPC[1] = ":What do you want?:,s1,p1,p2,p3,p4,p5,p6,p7,p99" StringNPC[2] = ":Down by the docks:,s2,p2,p3,p4,p5,p6,p7,p99" StringNPC[3] = ":There is a jobs board in the square:,s3,p1,p3,p4,p5,p6,p7,p99" StringNPC[4] = ":My name is " .. parsename.. " :,s4,p1,p2,p4,p5,p6,p7,p99" StringNPC[5] = ":I see you carry a journal,Let me update your map.:,s5,p1,p2,p3,p4,p6,p7,p99" StringNPC[6] = ":No one really it is a free town:,s6,p1,p2,p3,p4,p6,p7,p99" StringNPC[7] = ":Let me check the schedule.I will update your journal:,s7,p1,p2,p3,p4,p5,p7,p99" StringNPC[16] = ":That will cost you:,s8,p1,p2,p3,p4,p5,p99" StringNPC[17] = ":Betty runs the market:,s9,p2,p5,p6,p7,p99" -- Player possible response StringNPC[8] = ":Is there a place I can crash.:,p1,s2,adj1" -- adjust the conversation change this line once it has been asked to new question StringNPC[9] = ":Anything you need done!:,p2,s3" StringNPC[10] = ":Do I know you.:,p3,s4,adj2" -- action 2 used to add info to charicter knowledge StringNPC[11] = ":What is this place.:,p4,s5" StringNPC[12] = ":Who runs the town?:,p5,s6" StringNPC[13] = ":Is there anything going on?:,p6,s7" StringNPC[14] = ":Reply hello monkey reduce your rep:,p7,s8,rep140" -- rep reduced by 60 for responding StringNPC[15] = ":Exit:,p99,e1" end -------------------------- walk thru the speach and table it NLine =1 speakerIDX =1 responseIDX =1 printline =10 printleft = 15 cutstring = "" y=1 while true do if StringNPC[NLine] == nil then break end --TextCenterOnX(50,printline,1," "..StringNPC[NLine]) --printline=printline+3 ------------------ break out the speach text is in data file first "text" -------- ------------------ ex: "What the heck are you doing here and what is that",s1,p1,p8,p10,q5 text = StringNPC[NLine] local e = 0 while true do -------------------- identify the quoted text first local b = e+1 b = text:find("%S",b) if b==nil then break end if text:sub(b,b)=="'" then e = text:find("'",b+1) b = b+1 elseif text:sub(b,b)==':' then e = text:find(':',b+1) b = b+1 else e = text:find("%s",b+1) end if e==nil then e=#text+1 end -------------------- text:sub(b,e-1) is the ouoted text speakerIDX = 1 responseIDX = 1 --TextCenterOnX(printleft,printline,3,"Message #"..NLine.." ["..text:sub(b,e-1).."]") --printline=printline+3 parseMSG = text:sub(b,e-1) --TextCenterOnX(printleft,printline,3,"Message #"..NLine.." ["..parseMSG.."]") b=string.len(text) cutstring = text:sub(e+2,b) --TextCenterOnX(printleft,printline,1,"Past forward Line Info: "..text) --printline=printline+3 --speaker [NLine] = {} --response [NLine] = {} ---------------- break down speaker and results -------- -- capture all sub parts of the string seperated by **NON** alphanumeric - eg: spaces or punctuation etc can be used as delimiters -- tested with colon (:) and space ( ) and hyphen (-) and works fine s=cutstring i=1 -- set array local tbl = {} -- set array index local tblIDX = 1 local tblIDX = 1 for i in string.gmatch(s, "%w+") do --Where "%w+" is the alphanumeric string pattern. tbl[tblIDX] = i tblIDX=tblIDX+1 end -- IMPORTANT NOTE: tblIDX is 1 more than it should be due to last call in loop. Decrement to avoid confusion tblIDX = tblIDX - 1 -- **************** -- debug - display the strings we have --TextCenterOnX(printleft,printline,1,"We have "..tblIDX.." var strings derived from the entity name of "..s) --printline=printline+3 for i=1, tblIDX, 1 do --TextCenterOnX(printleft,printline,1,tbl[i]) --printline=printline+3 end -- debug display -- **************** -- set these in case we do not get a return from string.match -- set these in case we do not get a return from string.match local varName = "" local varValue = "" local msgflag = "" local msgNBR = 1 local lastval = 0 for i=1, tblIDX, 1 do -- debug - report default action takeing place action -- PromptDuration("Line "..parseMSG.." ",6000) -- debug line above only for testing --TextCenterOnX(printleft,printline,3,"Break down sub "..i.." Line read: "..tbl[i]) --printline=printline+3 varName = string.match(tbl[i], "%a+") -- capture the alpha varValue = string.match(tbl[i], "%d+") -- capture the numeric varData = varName..varValue -- THE EXAMPLE PART NOW WE HAVE THE STRING SUBSETS if varName~=nil and varValue~= nil then --TextCenterOnX(printleft,printline,1,"#" ..i.."Line read: "..varName.." It's number is "..varValue.." data: " ..varData) -- printline=printline+3 end --**************** THE PLAY AREA ****************** if i == 1 then if varName == "s" then speaker[varValue] = {} speaker[varValue] [1] = {} speaker[varValue] [1] [1] = parseMSG speaker[varValue] [1] [2] = 0 speaker[varValue] [2] = {} speaker[varValue] [2] [1]= varName speaker[varValue] [2] [2]= varValue lastval = 0 msgflag = "s" msgNBR = varValue speakerIDX= 2 --TextCenterOnX(printleft,printline,1,"Speach #"..varValue.. " Message ["..speaker[varValue] [1].."] ") --printline=printline+3 -- move it to speaker table -- make an example function call for this entity --y=y+3 elseif varName == "p" then --TextCenterOnX(printleft,printline,3,"Response Message #"..NLine.." ["..parseMSG.."]") --printline=printline+3 response[varValue] = {} response[varValue] [1] = parseMSG response[varValue] [2] = {} response[varValue] [2] [1] = varName response[varValue] [2] [2] = varValue response[varValue] [3] = {} response[varValue] [3] [1] = "rep" response[varValue] [3] [2] = 200 lastval = 0 msgflag = "p" msgNBR = varValue responseIDX = 3 --TextCenterOnX(printleft,printline,1,"This is a player option. It's number is "..varValue) --printline=printline+3 -- move it to player table end elseif i >= 1 and varData~= nil then --TextCenterOnX(printleft,printline,1,"Pure Response: "..varData.." Flag "..msgflag) --printline=printline+3 if varData ~= nil then if msgflag == "s" then speakerIDX = speakerIDX +1 speaker[msgNBR] [speakerIDX] = {} speaker[msgNBR] [speakerIDX] [1] = varName speaker[msgNBR] [speakerIDX] [2] = varValue lastval=lastval+1 tblVar=tostring(lastval) speaker[msgNBR] [1] [2]= tblVar --TextCenterOnX(printleft,printline,1,"Add To Speaker table "..speaker[NLine][speakerIDX]) end if msgflag == "p" then responseIDX = responseIDX +1 response[msgNBR] [responseIDX] = {} response[msgNBR] [responseIDX] [1] = varName response[msgNBR] [responseIDX] [2] = varValue lastval = 0 end if msgflag == "p" and varName == "rep" or varName == "act" or varName == "adj" then response[msgNBR] [3] [1] = varName response[msgNBR] [3] [2] = varValue lastval = 0 end --TextCenterOnX(printleft,printline,1,"Response line for message "..tbl[i]) --printline=printline+3 end -- end message type test end end -- for ---------------- break down speaker and results -------- end NLine = NLine + 1 --------------------------------------- if printline> 70 then printline=10 printleft=printleft+20 end end end function npc_conversation1_ai(e,msgNBR) ------------------------------ start convo ------------- local tblIDX3 --i=1 --local n = 0 --for k, v in pairs(response) do -- n = n + 1 --end -- TextCenterOnX(30,printline,3,"Message count = "..n) -- printline=printline+3 StartTimer(e) tblIDX=1 speakerIDX=1 if msgNBR == nil then msgNBR = 1 end --PromptDuration ("Mouse over X "..g_MouseX.."and "..g_MouseY.." ",3000) mouseOver=0 responTRG=nil reprintTRG=nil varValue = tostring(msgNBR) -- response panel resize if needed Panel(25,58,75,90) -- This makes the panel around the response text for i=1, tblIDX, 1 do varValue = tostring(msgNBR) -- debug -- TextCenterOnXColor(50,printline+6,3,"Speaker Message " ..varValue ,0,89,179) -- speakers line with name ect if knowspeaker == 1 then displaymsg = (" " .. parsejob .. " " .. parsename ..": " .. speaker[varValue][1][1] ) else displaymsg = (" Stranger : " .. speaker[varValue][1][1] ) end displaytext(e) -- display speaker / NPC name job text in panel printline=58 -- find speaker message and all player entry responses responseIDX = 3 tblIDX2=speaker[varValue][1][2] buttonOver = 0 for x=1, tblIDX2, 1 do tblIDX3=speaker[varValue][responseIDX][2] varResponse = tostring(tblIDX3) VarKey=speaker[varValue][responseIDX][1] if VarKey == "p" and (response[varResponse][3][1]) ~= "del" then -- check if ignore line printline=printline+3 Wlen = string.len(response[varResponse][1]) if g_MouseX > 50-(Wlen/3.8) and g_MouseX < 50+(Wlen/3.8) and g_MouseY > printline-1 and g_MouseY < printline+1 then if (response[varResponse][3][1]) == "rep" then -- process rep first to get line color to display npc_conversation1_rep(e) else TextCenterOnXColor(50,printline,3,response[varResponse][1],0,89,179) end mouseOver=1 --varName = response[responTRG] [4] [1] --varValue = response[responTRG] [4] [2] --TextCenterOnX(45,20,3,"Process varName 4.1 "..varName) --TextCenterOnX(45,23,3,"Process varValue 4.2 #"..varValue) --TextCenterOnX(50,printline,3," Over Message "..response[varResponse][1]) if g_MouseClick == 1 then -- debug --TextCenterOnXColor(50,printline+7,3,"Next Message " ..varResponse ,0,89,179) if (response[varResponse][3][1]) == "rep" then -- process rep if line picked to do adjustment npc_conversation1_effect_rep(e) end responTRG=varResponse if (response[varResponse][3][1]) == "adj" then -- process this action after the next response actionTRG = varResponse end if (response[varResponse][3][1]) == "act" then -- process this action before the next response actionTRG = varResponse npc_conversation1_effect_action(e) end end else TextCenterOnXColor(50,printline,3,response[varResponse][1] ,255,255,255) end elseif VarKey == "e" then talktome = 0 -- do exit stuff elseif VarKey == "a" then -- just a possible use for flag -- do attack stuff elseif VarKey == "t" then -- another possible flag -- do triggerr stuff end responseIDX=responseIDX+1 end end ------ timeing to keep from spinning past responses if msgNBR==1 then loopCNV=loopCNV+2 end if loopCNV < 12 and g_MouseClick == 1 then responTRG=nil loopCNV=loopCNV+1 end end function npc_conversation1_parseObj(s) ----- parse entity ex: "Burt",GateGuard,faction -------- ----- name in quotes can have first and second name .. faction for NPC VS NPC fights -- set array local tbl = {} -- set array index local tblIDX = 1 local e = 0 local y = 10 i=1 -------------------- identify the quoted text first local b = e+1 b = s:find("%S",b) if b~=nil then if s:sub(b,b)=="'" then e = s:find("'",b+1) b = b+1 elseif s:sub(b,b)=='"' then e = s:find('"',b+1) b = b+1 else e = s:find("%s",b+1) end if e==nil then e=#s+1 end if b~=nil then tbl[1] = s:sub(b,e-1) parsename = s:sub(b,e-1) b=string.len(s) text = s:sub(e+2,b) s=text y=y+3 --TextCenterOnX(50,y,1,"Found name "..tbl[1].." past forward "..s) y=y+3 end end for i in string.gmatch(s, "%w+") do tbl2[tblIDX] = i tblIDX=tblIDX+1 end tblIDX = tblIDX - 1 -- **************** -- debug - display the strings we have --y=y+3 --TextCenterOnX(50,y,1,"We have "..tblIDX.." var strings derived from the entity name of "..s) for i=1, tblIDX, 1 do y=y+3 if i==1 then tbl[2] = tbl2[i] parsejob= tbl[2] end if i==2 then --TextCenterOnX(50,y,1," i 3 We have "..tbl2[i]) tbl[3] = tbl2[i] parsefaction= tbl[3] y=y+3 --TextCenterOnX(50,y,1," tbl[3]= "..tbl[3].." "..parsefaction) end end end function npc_conversation1_respond(responTRG) if varName == "e" then talktome = 0 else TextCenterOnX(45,68,3," Parsing Message "..response[responTRG][1]) local varName = response[responTRG] [3] [1] local varValue = response[responTRG] [3] [2] TextCenterOnX(45,70,3,"Value 3.1 #"..varName) TextCenterOnX(45,73,3,"Value 3.2 #"..varValue) -- can do specials check here end end function npc_conversation1_rep(e) if tonumber(response[varResponse][3][2]) > 200 then TextCenterOnXColor(50,printline,3,response[varResponse][1],230,153,0) elseif tonumber(response[varResponse][3][2]) < 150 then TextCenterOnXColor(50,printline,3,response[varResponse][1],175,0,42) elseif tonumber(response[varResponse][3][2]) < 190 then TextCenterOnXColor(50,printline,3,response[varResponse][1]) else TextCenterOnXColor(50,printline,3,response[varResponse][1],0,89,179) end end function npc_conversation1_effect_action(e) -- Take what ever action you want to happen actionNBR = response[actionTRG][3][2] --displaymsg = (" In action process " .. actionTRG .. " " ..response[actionTRG][3][2] ) --displaytext(e) if tonumber(actionNBR) == 2 then actionTRG = 0 end end function npc_conversation1_effect_adjust(e) -- Take what ever action you want to happen actionNBR = response[actionTRG][3][2] --displaymsg = (" In action process " .. actionTRG .. " " ..response[actionTRG][3][2] ) --displaytext(e) if tonumber(actionNBR) == 1 then response[actionTRG] = {} response[actionTRG] [1] = "What items can I find in the market?" response[actionTRG] [2] = {} response[actionTRG] [2] [1] = "p" response[actionTRG] [2] [2] = 1 response[actionTRG] [3] = {} response[actionTRG] [3] [1] = " " response[actionTRG] [3] [2] = 0 response[actionTRG] [4] = {} response[actionTRG] [4] [1] = "s" response[actionTRG] [4] [2] = 9 actionTRG = 0 elseif tonumber(actionNBR) == 2 then knowspeaker = 1 -- add the info to some global data -- flag the answered question to not display knownmax = knownmax + 1 npcknown[knownmax] = parsename response[actionTRG] [3] [1] = "del" -- add the info to some global data actionTRG = 0 end end function npc_conversation1_effect_rep(e) -- adjust your global rep or what ever -- could make a response asking the NPC to train you like train50 to get training to adjust -- endless things you could do with flags end function displaytext(e) -- displaymsg=" just checking" Wlen = string.len(displaymsg) -- This counts the characters in the strings WeaponName and MyText by adding them together. Try changing the [1] to another number. Panel(50-(Wlen/3.8), 50, 50+(Wlen/3.8), 18) -- This uses the text lengths to make the panel around the text which will centre on the screen. TextCenterOnXColor(50,52.5,1,displaymsg,248,248,255) -- Displays text in panel using both strings. Try changing the [1] to another number. end