new pick up and deliver quests (no visual carry, just variables)
it does need a short tutorial so here goes....
1. place an npc that will give the quest
1.a. check his entity number and put it into the script under quest 1
example
Quote: "--set the number for the quest (i.e, 1, 2, 3 etc)
quest_number = 1
--set to the entity number of the quest giver
pickup_quest_npc[quest_number] = 2"
in this case the entity number is 2
2. place an object that is to be collected (static or dynamic is fine but you will likely want to remove any scripts attached to it)
2.a. get the object entity number and put it in the settings for quest 1
Quote: "--entity number of the first item to be collected (lowest entity number)
first_pickup_e[quest_number] = 3"
in this case it's entity number 3
2.b. place as many objects as you wish to be collected
2.c. when you have place the last object check it's entity number and put it in the script
Quote: "--entity number of the last item to be collected (highest entity number)
last_pickup_e[quest_number] = 7"
in this case it's number 7, therefore there will be 5 items to collect (entities 3,4,5,6 & 7)
3. give the item a name in the script (just so the prompts look nicer)
4.a&b. set the ranges of the quest (player distances)
Quote: "--how close the player needs to be to accept and hand-in the quest
quest_talk_range[quest_number] = 150
--how close the player needs to be to pickup the collectable items
pickup_range[quest_number] = 100"
5. set if it's a repeatable quest (1 = yes, 0 = no) *note; quest will reset as soon as player moves out of quest_talk_range*
and repeat for all quests (remember to increase the quest_number by 1 each time)
--pick up and deliver quest script by smallg
local quest_stage = {}
local time1 = 0
local time2 = 0
local timepassed = 0
local delay = 100
local pressed = 0
local quests = 0
local pickup_quest_npc = {}
local first_pickup_e = {}
local last_pickup_e = {}
local quest_talk_range = {}
local items_collected = {}
local collected = {}
local item_name = {}
local repeatable = {}
local pickup_range = {}
local x = {}
local y = {}
local z = {}
local cash = 0
function pickup_quest_init(e)
quests = quests + 1
quest_stage[quests] = 0
items_collected[quests] = 0
end --init
--setup quests here (***change the entity numbers to fit your own map or script will not work correctly***)
--set the number for the quest (i.e, 1, 2, 3 etc)
quest_number = 1
--set to the entity number of the quest giver
pickup_quest_npc[quest_number] = 2
--entity number of the first item to be collected (lowest entity number)
first_pickup_e[quest_number] = 3
--entity number of the last item to be collected (highest entity number)
last_pickup_e[quest_number] = 7
--name of item to be collected here (for prompts)
item_name[quest_number] = "Explosive Barrel"
--how close the player needs to be to accept and hand-in the quest
quest_talk_range[quest_number] = 150
--how close the player needs to be to pickup the collectable items
pickup_range[quest_number] = 100
--set to 1 if quest can be repeated (no limit) or 0 if a one time only quest
repeatable[quest_number] = 1
--quest2
quest_number = 2
pickup_quest_npc[quest_number] = 10
item_name[quest_number] = "Health Pack"
first_pickup_e[quest_number] = 11
last_pickup_e[quest_number] = 12
quest_talk_range[quest_number] = 150
pickup_range[quest_number] = 100
repeatable[quest_number] = 0
--quest3
--------
function pickup_quest_main(e)
for quest_number = 1, quests do
if g_Entity[pickup_quest_npc[quest_number]] ~= nil then
--check player in range of a quest giver
if GetPlayerDistance(pickup_quest_npc[quest_number]) <= quest_talk_range[quest_number] then
CharacterControlStand(e)
RotateToPlayer(pickup_quest_npc[quest_number])
--if quest not started yet
if quest_stage[quest_number] == 0 then
Prompt("Hi there, please collect " .. 1 + last_pickup_e[quest_number] - first_pickup_e[quest_number] .. " " .. item_name[quest_number] .. "s for me")
--if player accepts quest
if g_KeyPressE == 1 and pressed == 0 then
pressed = 1
PromptDuration("Come back with my " .. item_name[quest_number] .. "s soon please",2000)
quest_stage[quest_number] = quest_stage[quest_number] + 1
end --end accepted quest
--if quest already started
elseif quest_stage[quest_number] == 1 then
--check how many items the player has
if items_collected[quest_number] > 0 then
--if not collected enough then show how many are left to collect
if items_collected[quest_number] < 1 + last_pickup_e[quest_number] - first_pickup_e[quest_number] then
Prompt("I still need " .. 1 + (last_pickup_e[quest_number] - first_pickup_e[quest_number]) - items_collected[quest_number] .. " " .. item_name[quest_number])
else
Prompt("Finish quest?")
--if player has collected all needed items
if g_KeyPressE == 1 and pressed == 0 then
-----
--insert reward code here
--example reward
cash = cash + 100
-----
--change prompt to match reward
PromptDuration("Thank you, cash = " .. cash,2000)
items_collected[quest_number] = 0
quest_stage[quest_number] = quest_stage[quest_number] + 1
pressed = 1
-----
end --player hands quest in
end --items collected number check
end --items collected above 0
end --stage number check
else
--if quest finished but repeatable reset it
if repeatable[quest_number] == 1 and quest_stage[quest_number] == 2 then
quest_stage[quest_number] = 0
--replace collectables
for item = first_pickup_e[quest_number], last_pickup_e[quest_number] do
Show(item)
CollisionOn(item)
collected[item] = 0
end --for item loop
end --quest reset check
end --player in quest giver range check
for item = first_pickup_e[quest_number], last_pickup_e[quest_number] do
if g_Entity[item] ~= nil then
if collected[item] == nil then
collected[item] = 0
end
if GetPlayerDistance(item) <= pickup_range[quest_number] and quest_stage[quest_number] == 1 and collected[item] == 0 then
Prompt("Collect " .. item_name[quest_number] .. "?")
if g_KeyPressE == 1 and pressed == 0 then
pressed = 1
collected[item] = 1
items_collected[quest_number] = items_collected[quest_number] + 1
Hide(item)
CollisionOff(item)
end --collected item
end --player in range of item
end --exist check
end --for item loop
end --quest giver exist
end --for quest_number loop
--reset input
if g_KeyPressE == 0 then
pressed = 0
end
end --main
p.s. if someone can tell me why the non-repeatable quest objects also reappear once a repeatable quest is reset i would be very grateful - it looks like they shouldn't to me but as you can see at the end of the video they do...
guilty code is somewhere here i guess
--if quest finished but repeatable reset it
if repeatable[quest_number] == 1 and quest_stage[quest_number] == 2 then
quest_stage[quest_number] = 0
--replace collectables
for item = first_pickup_e[quest_number], last_pickup_e[quest_number] do
Show(item)
CollisionOn(item)
collected[item] = 0
end --for item loop
end --quest reset check
life's one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11