RE: !! Pioneer Question Time !! - Ask them here
Posted: Mon Feb 07, 2011 7:20 am
by Potsmoke66
that would look like this
Code:
-- Danger should be from 0 to 1. zero means nothing bad happens. greater than-- zero means spawn an enemy ship of that 'power' to kill youlocal delivery_flavours = {{adtext = "GOING TO the %1 system? Money paid for delivery of a small package.",introtext = "Hi, I'm %1. I'll pay you %2 if you will deliver a small package until %7 to %3 in the %4 (%5, %6) system.",whysomuchdoshtext = "When a friend visited me she left behind some clothes and antique paper books. I'd like to have them returned to her.",successmsg = "Thank you for the delivery. You have been paid in full.",failuremsg = "Jesus wept, you took forever over that delivery. I'm not willing to pay you.",danger = 0,time = 3,money = .5,}, {adtext = "WANTED. Delivery of a package to the %1 system.",introtext = "Hello. I'm %1. I'm willing to pay %2 for a ship to carry a package until %7 to %3 in the %4 (%5, %6) system.",whysomuchdoshtext = "It is nothing special.",successmsg = "The package has been received and you have been paid in full.",failuremsg = "I'm frustrated by the late delivery of my package, and I refuse to pay you.",danger = 0,time = 1,money = 1,}, {adtext = "URGENT. Fast ship needed to deliver a package to the %1 system.",introtext = "Hello. I'm %1. I'm willing to pay %2 for a ship to carry a package until %7 to %3 in the %4 (%5, %6) system.",whysomuchdoshtext = "It is a research proposal and must be delivered by the deadline or we may not get funding.",successmsg = "You have been paid in full for the delivery. Thank you.",failuremsg = "I was quite clear about the deadline and am very disappointed by the late delivery. You will not be paid.",danger = 0,time = .75,money = 1.1,}, {adtext = "DELIVERY. Documents to the %1 system. %2 to an experienced pilot.",introtext = "Hello. I'm %1. I'm willing to pay %2 for a ship to carry a package until %7 to %3 in the %4 (%5, %6) system.",whysomuchdoshtext = "Some extremely sensitive documents have fallen into my hands, and I have reason to believe that the leak has been traced to me.",successmsg = "Your timely and discrete service is much appreciated. You have been paid in full.",failuremsg = "Useless! I will never depend on you again! Needless to say, you will not be paid for this.",danger = .5,time = 0.75,money = 2.5,}}--[[for i = 0,10 dolocal sys = StarSystem:new(i,2,0)print('Looking near ' .. sys:GetSectorX() .. '/' .. sys:GetSectorY() .. '/' .. sys:GetSystemNum())print(sys:GetSystemName())print(sys:GetSystemShortDescription())local sport = sys:GetRandomStarportNearButNotIn()if sport thenprint(sport:GetBodyName() .. ' in the ' .. sport:GetSystemName() .. ' system')elseprint("No suitable nearby space station found.")endend--]]Module:new {__name = 'DeliverPackage',Init = function(self)self:EventListen("onCreateBB")self:EventListen("onUpdateBB")self:EventListen("onEnterSystem")self:EventListen("onPlayerDock")self.ads = {}self.missions = {}end,GetPlayerMissions = function(self)return self.missionsend,_TryAddAdvert = function(self, station)local gender = Pi.rand:Int(0,1) == 1local flavour = Pi.rand:Int(1, #delivery_flavours)ad = {flavour = flavour,personGender = gender,client = Pi.rand:PersonName(gender),reward = Pi.rand:Real(200, 1000) * delivery_flavours[flavour].money,due = Pi.GetGameTime() + Pi.rand:Real(0, delivery_flavours[flavour].time * 60*60*24*31),bb = station,dest = Pi.GetCurrentSystem():GetRandomStarportNearButNotIn(),id = #self.ads+1}-- if we found a destinationif ad.dest ~= nil thentable.insert(self.ads, ad)local addescription = _(delivery_flavours[ad.flavour].adtext, {ad.dest:GetSystemName(),format_money(ad.reward) } )station:SpaceStationAddAdvert(self.__name, #self.ads, addescription)endend,onCreateBB = function(self, args)local station = args[1]for i = 1,10 do --Pi.rand:Int(0, 5) doselfGDN_TryAddAdvert(station)endend,onEnterSystem = function(self)for k,mission in pairs(self.missions) doif mission.status == 'active' and mission.dest:GetSystem() == Pi:GetCurrentSystem() thenlocal danger = delivery_flavours[mission.flavour].dangerif danger > 0 then--ship, e = Pi.SpawnShip(Pi.GetGameTime()+60, "Ladybird Starfighter")ship, e = Pi.SpawnRandomShip(Pi.GetGameTime(), danger, 20, 100)if e == nil thenship:ShipAIDoKill(Pi.GetPlayer());Pi.ImportantMessage(ship:GetLabel(), _("You're going to regret dealing with %1!", {mission.client}))endendendendend,onPlayerDock = function(self)local station = Pi.GetPlayer():GetDockedWith():GetSBody()print('player docked with ' .. station:GetBodyName())for k,mission in pairs(self.missions) doif mission.status == 'active' thenif mission.dest == station thenif Pi.GetGameTime() > mission.due thenPi.ImportantMessage(mission.client, delivery_flavours[mission.flavour].failuremsg)mission.status = 'failed'elsePi.ImportantMessage(mission.client, delivery_flavours[mission.flavour].successmsg)Pi.GetPlayer():AddMoney(mission.reward)mission.status = 'completed'endelseif Pi.GetGameTime() > mission.due thenmission.status = 'failed'endendendend,onUpdateBB = function(self, args)local station = args[1]for k,ad in pairs(self.ads) doif (ad.bb == station) and (ad.due < Pi.GetGameTime() + 60*60*24*1) thenself.ads[k] = nilad.bb:SpaceStationRemoveAdvert(self.__name, ad.id)endendif Pi.rand:Int(0,12*60*60) < 60*60 then -- roughly once every twelve hoursselfGDN_TryAddAdvert(station)endend,onChatBB = function(self, dialog, optionClicked)local ad = self.ads[dialog]dialog:Clear()if optionClicked == -1 thendialog:Close()returnelseif optionClicked == 0 thendialog:SetMessage(_(delivery_flavours[ad.flavour].introtext, {ad.client, format_money(ad.reward), ad.dest:GetBodyName(), ad.dest:GetSystemName(), ad.dest:GetSectorX(), ad.dest:GetSectorY(), Date.Format(ad.due) }))elseif optionClicked == 1 thendialog:SetMessage(delivery_flavours[ad.flavour].whysomuchdoshtext)--[[elseif optionClicked == 2 thendialog:SetMessage(_('It must be delivered by %1', { Date.Format(ad.due) }))--]]elseif optionClicked == 3 thendialog:RemoveAdvertOnClose()self.ads[ad.id] = nilad.description = _("Deliver a package to %1 in the %2 system (%3, %4).",{ ad.dest:GetBodyName(), ad.dest:GetSystemName(), ad.dest:GetSectorX(), ad.dest:GetSectorY() })ad.status = "active"table.insert(self.missions, ad)dialog:SetMessage("Excellent.")dialog:AddOption("Hang up.", -1)returnenddialog:AddOption("Why so much money?", 1);dialog:AddOption("Could you repeat the original request?", 0);--dialog:AddOption("How soon must it be delivered?", 2);dialog:AddOption("Ok, agreed.", 3);dialog:AddOption("Hang up.", -1);end,}
this is how i use it
Code:
-- Danger should be from 0 to 1. zero means nothing bad happens. greater than-- zero means spawn an enemy ship of that 'power' to kill youlocal delivery_flavours = {{adtext = "GOING TO the %1 system? Money paid for delivery of a small package.",introtext = "Hi, I'm %1. I'll pay you %2 if you will deliver a small package until %5 to %3 in the %4 system.",howtogettheretext_0 = "O.K., i will take a look, wait...",howtogettheretext_1 = "Oh, excuse me Sir, i forgot, %1 in the %2 system has %3, %4 as coordinates. live long and prosperous, Sir",whysomuchdoshtext = "When a friend visited me she left behind some clothes and antique paper books. I'd like to have them returned to her.",successmsg = "Thank you for the delivery. You have been paid in full.",failuremsg = "Jesus wept, you took forever over that delivery. I'm not willing to pay you.",danger = 0,time = 3,money = .5,}, {adtext = "WANTED. Delivery of a package to the %1 system.",introtext = "Hello. I'm %1. I'm willing to pay %2 for a ship to carry a package until %5 to %3 in the %4 system.",whysomuchdoshtext = "It is nothing special.",howtogettheretext_0 = "I thought in your Spaceship?.",howtogettheretext_1 = "Of course i can tell you, %1 in the %2 system has %3, %4 as coordinates, have a nice trip.",successmsg = "The package has been received and you have been paid in full.",failuremsg = "I'm frustrated by the late delivery of my package, and I refuse to pay you.",danger = 0,time = 1,money = 1,}, {adtext = "URGENT. Fast ship needed to deliver a package to the %1 system.",introtext = "Hello. I'm %1. I'm willing to pay %2 for a ship to carry a package until %5 to %3 in the %4 system.",whysomuchdoshtext = "It is a research proposal and must be delivered by the deadline or we may not get funding.",howtogettheretext_0 = "What do i know? are YOU the Pilot or am I?",howtogettheretext_1 = "%1 in the %2 System, is located %3, %4. I thought you know that?",successmsg = "You have been paid in full for the delivery. Thank you.",failuremsg = "I was quite clear about the deadline and am very disappointed by the late delivery. You will not be paid.",danger = .5,time = .75,money = 1.5,}, {adtext = "DELIVERY. Documents to the %1 system. %2 to an experienced pilot.",introtext = "Hello. I'm %1. I'm willing to pay %2 for a ship to carry a package to until %5 %3 in the %4 system.",whysomuchdoshtext = "Some extremely sensitive documents have fallen into my hands, and I have reason to believe that the leak has been traced to me.",howtogettheretext_0 = "-",howtogettheretext_1 = "Are you shure that you are the right Pilot for this Delivery? %2 is located %3, %4.",successmsg = "Your timely and discrete service is much appreciated. You have been paid in full.",failuremsg = "Useless! I will never depend on you again! Needless to say, you will not be paid for this.",danger = 1,time = 1,money = 2.5,}}--[[for i = 0,10 dolocal sys = StarSystem:new(i,2,0)print('Looking near ' .. sys:GetSectorX() .. '/' .. sys:GetSectorY() .. '/' .. sys:GetSystemNum())print(sys:GetSystemName())print(sys:GetSystemShortDescription())local sport = sys:GetRandomStarportNearButNotIn()if sport thenprint(sport:GetBodyName() .. ' in the ' .. sport:GetSystemName() .. ' system')elseprint("No suitable nearby space station found.")endend--]]Module:new {__name = 'DeliverPackage',Init = function(self)self:EventListen("onCreateBB")self:EventListen("onUpdateBB")self:EventListen("onEnterSystem")self:EventListen("onPlayerDock")self.ads = {}self.missions = {}end,GetPlayerMissions = function(self)return self.missionsend,_TryAddAdvert = function(self, station)local gender = Pi.rand:Int(0,1) == 1local flavour = Pi.rand:Int(1, #delivery_flavours)ad = {flavour = flavour,personGender = gender,client = Pi.rand:PersonName(gender),reward = Pi.rand:Real(200, 1000) * delivery_flavours[flavour].money,due = Pi.GetGameTime() + Pi.rand:Real(0, delivery_flavours[flavour].time * 60*60*24*31),bb = station,dest = Pi.GetCurrentSystem():GetRandomStarportNearButNotIn(),id = #self.ads+1}-- if we found a destinationif ad.dest ~= nil thentable.insert(self.ads, ad)local addescription = _(delivery_flavours[ad.flavour].adtext, {ad.dest:GetSystemName(),format_money(ad.reward) } )station:SpaceStationAddAdvert(self.__name, #self.ads, addescription)endend,onCreateBB = function(self, args)local station = args[1]for i = 1,10 do --Pi.rand:Int(0, 5) doselfGDN_TryAddAdvert(station)endend,onEnterSystem = function(self)for k,mission in pairs(self.missions) doif mission.status == 'active' and mission.dest:GetSystem() == Pi:GetCurrentSystem() thenlocal danger = delivery_flavours[mission.flavour].dangerif danger > 0 then--ship, e = Pi.SpawnShip(Pi.GetGameTime()+60, "Ladybird Starfighter")ship, e = Pi.SpawnRandomShip(Pi.GetGameTime(), danger, 20, 100)if e == nil thenship:ShipAIDoKill(Pi.GetPlayer());Pi.ImportantMessage(ship:GetLabel(), _("You're going to regret dealing with %1!", {mission.client}))endendendendend,onPlayerDock = function(self)local station = Pi.GetPlayer():GetDockedWith():GetSBody()print('player docked with ' .. station:GetBodyName())for k,mission in pairs(self.missions) doif mission.status == 'active' thenif mission.dest == station thenif Pi.GetGameTime() > mission.due thenPi.ImportantMessage(mission.client, delivery_flavours[mission.flavour].failuremsg)mission.status = 'failed' -- erase the missionself.missions[k] = nilelsePi.ImportantMessage(mission.client, delivery_flavours[mission.flavour].successmsg)Pi.GetPlayer():AddMoney(mission.reward)mission.status = 'completed'-- erase the missionself.missions[k] = nilendelseif Pi.GetGameTime() > mission.due thenmission.status = 'failed'-- erase the missionself.missions[k] = nilendendendend,onUpdateBB = function(self, args) local station = args[1]for k,ad in pairs(self.ads) doif (ad.bb == station) and (ad.due < Pi.GetGameTime() + 60*60*24*1) thenself.ads[k] = nilad.bb:SpaceStationRemoveAdvert(self.__name, ad.id)end --self.missions[k] = nilendif Pi.rand:Int(0,12*60*60) < 60*60 then -- roughly once every twelve hoursselfGDN_TryAddAdvert(station)endend,onChatBB = function(self, dialog, optionClicked)local ad = self.ads[dialog] dialog:Clear()if optionClicked == -1 thendialog:Close()returnelseif optionClicked == 0 thendialog:SetMessage(_(delivery_flavours[ad.flavour].introtext, {ad.client, format_money(ad.reward), ad.dest:GetBodyName(), ad.dest:GetSystemName(), Date.Format(ad.due) }))elseif optionClicked == 1 thendialog:SetMessage(delivery_flavours[ad.flavour].whysomuchdoshtext)--[[elseif optionClicked == 2 thendialog:SetMessage(_('It must be delivered by %1', { Date.Format(ad.due) }))--]]elseif optionClicked == 3 then local answ_1 = math.fmod((ad.dest:GetSystemLawlessness()),1) if answ_1 > .15 then -- old value = .125 dialog:SetMessage(delivery_flavours[ad.flavour].howtogettheretext_0)else dialog:SetMessage(_(delivery_flavours[ad.flavour].howtogettheretext_1, {ad.dest:GetBodyName(), ad.dest:GetSystemName(), ad.dest:GetSectorX(), ad.dest:GetSectorY() }))endelseif optionClicked == 4 thendialog:RemoveAdvertOnClose() self.ads[ad.id] = nil local answ_1 = math.fmod((ad.dest:GetSystemLawlessness()),1) if answ_1 > .15 then ad.description = (_("Deliver a package to %1 in the %2 system.",{ ad.dest:GetBodyName(), ad.dest:GetSystemName() })) else ad.description = (_("Deliver a package to %1 in the %2 system (%3, %4).",{ ad.dest:GetBodyName(), ad.dest:GetSystemName(), ad.dest:GetSectorX(), ad.dest:GetSectorY() }))endad.status = "active"table.insert(self.missions, ad)dialog:SetMessage("Excellent.")dialog:AddOption("Hang up.", -1)returnenddialog:AddOption("Why so much money?", 1);dialog:AddOption("Could you repeat the original request?", 0);--dialog:AddOption("How soon must it be delivered?", 2);dialog:AddOption("How do i get there?", 3);dialog:AddOption("Ok, agreed.", 4);dialog:AddOption("Hang up.", -1);end,}
it adds a "how do i get there" while not all will tell you the coordinates (it depends on target system lawlessness, as soon as we have a character value this could be changed).removes the "useless" - howsoon.deletes all finished missions from the roster (you could optionally only erase succeeded).increases danger somewhat.