-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- DESCRIPTION: smallg kill X number of targets quest script -- DESCRIPTION: [QUESTACTIVE!=1] (so quest can be triggered by another script etc) -- DESCRIPTION: [TALKRANGE=120] (how far the NPC can deliver the quest lines) -- DESCRIPTION: [TARGETNAME$="Masked Soldier"] (the name of the entitys to kill - as shown in their properties) -- DESCRIPTION: [KILLSREQUIRED=10] (how many targets need killing to complete the quest) -- DESCRIPTION: [TIMED!=1] (if there is a time limit) -- DESCRIPTION: [TIMELIMIT=60] (how long the time limit is if active) -- DESCRIPTION: (enter the entity number of the rewards below and make them 'spawn at start = no' -- DESCRIPTION: and the script will spawn them when the quest completes - enter 0 if no reward) -- DESCRIPTION: [REWARD1=1] (reward entity #1) -- DESCRIPTION: [REWARD2=1] (reward entity #2) -- DESCRIPTION: [REWARD3=1] (reward entity #3) -- DESCRIPTION: [QUESTCOMPLETETEXT$="Thank you, please take your reward"] (text to show at NPC when quest is complete) -- DESCRIPTION: [SHOWSTATUS!=1] (show quest progress on screen) -- DESCRIPTION: [STATUSX=1] (x position of status text) -- DESCRIPTION: [STATUSY=1] (y position of status text) -- DESCRIPTION: [STATUSSIZE=3] (size of status text) -- DESCRIPTION: [REPEATING!=0] (can quest be repeated endlessly?) -- DESCRIPTION: [REPEATDELAY=30] (delay before quest can be repeated (leave time so player has time to pick up rewards)) U = U or require "scriptbank\\utillib" local kxq = nil local killsremaining = {} local queststate = {} local presse = 0 g_killxquest = {} local gottargets = {} local maxtargets = {} local targetlist = {} local countedtarget = {} local timer1 = {} local timer2 = {} function killxquest_properties(e, questactive, talkrange, targetname, killsrequired, timed, timelimit, reward1, reward2, reward3, questcompletetext, showstatus, statusx, statusy, statussize, repeating, repeatdelay) kxq.questactive = questactive kxq.talkrange = talkrange kxq.targetname = targetname kxq.killsrequired = killsrequired kxq.timed = timed kxq.timelimit = timelimit kxq.reward1 = reward1 kxq.reward2 = reward2 kxq.reward3 = reward3 kxq.questcompletetext = questcompletetext kxq.showstatus = showstatus kxq.statusx = statusx kxq.statusy = statusy kxq.statussize = statussize kxq.repeating = repeating kxq.repeatdelay = repeatdelay end function killxquest_init(e) g_killxquest[e] = {} kxq = g_killxquest[e] kxq.questactive = 1 kxq.talkrange = 120 kxq.targetname = "Masked Soldier" kxq.killsrequired = 10 kxq.timed = 1 kxq.timelimit = 300 kxq.reward1 = e kxq.reward2 = e kxq.reward3 = e kxq.questcompletetext = "Thank you so much!" kxq.showstatus = 1 kxq.statusx = 1 kxq.statusy = 1 kxq.statussize = 3 kxq.repeating = 0 kxq.repeatdelay = 30 targetlist[e] = {} queststate[e] = "begin" gottargets[e] = nil maxtargets[e] = nil timer1[e] = nil timer2[e] = nil end function killxquest_main(e) local function SecondsToClock(seconds) local seconds = tonumber(seconds) if seconds <= 0 then return "00:00:00"; else hours = string.format("%02.f", math.floor(seconds/3600)); mins = string.format("%02.f", math.floor(seconds/60 - (hours*60))); secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60)); return hours..":"..mins..":"..secs end end if kxq.questactive == 1 then RotateToPlayerSlowly(e,2) LookAtPlayer(e) if U.PlayerLookingNear( e, kxq.talkrange, 48 ) == true and g_PlayerHealth > 0 then if queststate[e] == "begin" then PlaySoundIfSilent(e,0) kxq.questbegintext = "Hello, please can you kill "..kxq.killsrequired.." "..kxq.targetname.."s for me? (E)" PromptLocal(e,kxq.questbegintext) if g_KeyPressE == 1 then if presse == 0 then presse = 1 killsremaining[e] = kxq.killsrequired queststate[e] = "active" if kxq.timed == 1 then timer1[e] = g_Time + kxq.timelimit*1000 end end else presse = 0 end elseif queststate[e] == "active" then if killsremaining[e] > 0 then PlaySoundIfSilent(e,1) kxq.questactivetext = "Please return when you have killed "..(killsremaining[e]).." "..kxq.targetname.."s" PromptLocal(e,kxq.questactivetext) else if kxq.reward1 > 0 then Spawn(kxq.reward1) end if kxq.reward2 > 0 then Spawn(kxq.reward2) end if kxq.reward3 > 0 then Spawn(kxq.reward3) end queststate[e] = "complete" end elseif queststate[e] == "complete" then PlaySoundIfSilent(e,2) PromptLocal(e,kxq.questcompletetext) if kxq.repeating == 1 then if timer2[e] == nil then timer2[e] = g_Time + (kxq.repeatdelay*1000) else if g_Time > timer2[e] then if kxq.reward1 > 0 then Destroy(kxq.reward1) end if kxq.reward2 > 0 then Destroy(kxq.reward2) end if kxq.reward3 > 0 then Destroy(kxq.reward3) end queststate[e] = "begin" gottargets[e] = nil maxtargets[e] = nil timer1[e] = nil timer2[e] = nil end end end end end if queststate[e] == "active" then if gottargets[e] == nil then maxtargets[e] = 0 for a = 0, g_EntityElementMax do if g_Entity[a] ~= nil then if g_Entity[a]['obj'] ~= nil then if GetEntityName(a) == kxq.targetname then if g_Entity[a].health > 0 then maxtargets[e] = maxtargets[e] + 1 targetlist[e][maxtargets[e]] = a countedtarget[a] = false end end end end end gottargets[e] = true killsremaining[e] = kxq.killsrequired timer1[e] = g_Time + (kxq.timelimit*1000) else for a,b in pairs(targetlist[e]) do if g_Entity[b] ~= nil then if g_Entity[b].health < 1 then if countedtarget[b] == false then countedtarget[b] = true killsremaining[e] = killsremaining[e] - 1 end end end end if killsremaining[e] < 1 then killsremaining[e] = 0 end if kxq.showstatus == 1 then TextCenterOnX(kxq.statusx, kxq.statusy, kxq.statussize, "Kill "..killsremaining[e].." "..kxq.targetname.."s") if kxq.timed == 1 then TextCenterOnX(kxq.statusx, kxq.statusy+kxq.statussize+1, kxq.statussize, SecondsToClock((timer1[e]-g_Time)/1000)) end end if kxq.timed == 1 then if g_Time > timer1[e] then queststate[e] = "begin" gottargets[e] = nil maxtargets[e] = nil timer1[e] = nil timer2[e] = nil end end end end end end