Skip to content

Commit

Permalink
Release 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ctcDNightmare committed Sep 23, 2017
2 parents 03c631d + dff0bf6 commit 9c51427
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 95 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#### Version 1.2.1 *"bushless-intimidation"*
* port of vanilla functions from 0.14.2
* add missing getUpdateInterval() & onCloseWindow()

#### Version 1.2.0 *"purebred-terrestrial"*
* buy personal licenses even as alliance member
* fixed vanilla notifications
* notify all online members of an alliance if time is running out
* pricePerMinute and alliancePriceFactor are now configurable
* add clickable coordinates to notifications

#### Version 1.0.0 *"preantiseptic-lingual"*
* variable maxDuration based on reputation
* revamped UI with discounts for bulk-order & reputation
* bought time is added to current one instead of overwriting it
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# ScrapyardPlus

___
Your salvaging ops are longer then 60 minutes?
You want to get something in return for grinding all the precious reputation?
Expand All @@ -10,17 +9,13 @@ With ScrapyardPlus you can:
* get discounts for bulk orders and your current standing with the owner of the scrapyard

## Installation
1. download & extract the [mod](https://github.com/ctcDNightmare/avorion-scrapyardplus/releases) into your avorion folder

2. insert the following code:
``
-- DNightmare/ScrapyardPlus START
if not pcall(require, "mods/ScrapyardPlus/scripts/entity/merchants/scrapyard") then print("Failed to load ScrapyardPlus") end
-- DNightmare/ScrapyardPlus END
``
at the end of the original scrapyard file:
``data/scripts/entity/merchants/scrapyard.lua``
**(in case you are using the MoveUI-Mod as well, insert it above that!)**
1. download & extract the [mod](https://github.com/ctcDNightmare/avorion-scrapyardplus/releases) into your Avorion folder

2. insert the following code at the end of the original scrapyard file (``data/scripts/entity/merchants/scrapyard.lua``)
```Lua
if not pcall(require, "mods/ScrapyardPlus/scripts/entity/merchants/scrapyard") then print("Failed to load ScrapyardPlus") end -- DNightmare/ScrapyardPlus
```
**In case you are using the MoveUI-Mod from Dirtyredz as well, insert it above that!**

3. done

Expand Down
Binary file removed ScrapyardPlus-1.0.0.jpg
Binary file not shown.
Binary file added ScrapyardPlus-1.2.1.zip
Binary file not shown.
88 changes: 69 additions & 19 deletions data/scripts/entity/merchants/scrapyard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -254,51 +254,102 @@ function Scrapyard.updateServer(timeStep)
newsBroadcastCounter = 0
end

-- counter for update, this is only executed once per second to save performance.
for playerIndex, actions in pairs(illegalActions) do
for factionIndex, actions in pairs(illegalActions) do

actions = actions - 1

if actions <= 0 then
illegalActions[playerIndex] = nil
illegalActions[factionIndex] = nil
else
illegalActions[playerIndex] = actions
illegalActions[factionIndex] = actions
end
end

for playerIndex, time in pairs(licenses) do
for factionIndex, time in pairs(licenses) do

time = time - timeStep

local faction = Faction(factionIndex)
local here = false
if faction.isAlliance then
faction = Alliance(factionIndex)
elseif faction.isPlayer then
faction = Player(factionIndex)

local px, py = faction:getSectorCoordinates()
local sx, sy = Sector():getCoordinates()

here = (px == sx and py == sy)
end

local doubleSend = false
local msg = nil

-- warn player if his time is running out
if time + 1 > 10 and time <= 10 then
Player(playerIndex):sendChatMessage(station.title, 0, "Your salvaging license will run out in 10 seconds."%_t);
Player(playerIndex):sendChatMessage(station.title, 2, "Your salvaging license will run out in 10 seconds."%_t);
if here then
msg = "Your salvaging license will run out in 10 seconds."%_t
else
msg = "Your salvaging license in %s will run out in 10 seconds."%_t
end

doubleSend = true
end

if time + 1 > 20 and time <= 20 then
Player(playerIndex):sendChatMessage(station.title, 0, "Your salvaging license will run out in 20 seconds."%_t);
Player(playerIndex):sendChatMessage(station.title, 2, "Your salvaging license will run out in 20 seconds."%_t);
if here then
msg = "Your salvaging license will run out in 20 seconds."%_t
else
msg = "Your salvaging license in %s will run out in 20 seconds."%_t
end

doubleSend = true
end

if time + 1 > 30 and time <= 30 then
Player(playerIndex):sendChatMessage(station.title, 0, "Your salvaging license will run out in 30 seconds. Renew it and save yourself some trouble!"%_t);
if here then
msg = "Your salvaging license will run out in 30 seconds. Renew it and save yourself some trouble!"%_t
else
msg = "Your salvaging license in %s will run out in 30 seconds. Renew it and save yourself some trouble!"%_t
end
end

if time + 1 > 60 and time <= 60 then
Player(playerIndex):sendChatMessage(station.title, 0, "Your salvaging license will run out in 60 seconds. Renew it NOW and save yourself some trouble!"%_t);
if here then
msg = "Your salvaging license will run out in 60 seconds. Renew it NOW and save yourself some trouble!"%_t
else
msg = "Your salvaging license in %s will run out in 60 seconds. Renew it NOW and save yourself some trouble!"%_t
end
end

if time + 1 > 120 and time <= 120 then
Player(playerIndex):sendChatMessage(station.title, 0, "Your salvaging license will run out in 2 minutes. Renew it immediately and save yourself some trouble!"%_t);
if here then
msg = "Your salvaging license will run out in 2 minutes. Renew it immediately and save yourself some trouble!"%_t
else
msg = "Your salvaging license in %s will run out in 2 minutes. Renew it immediately and save yourself some trouble!"%_t
end
end

if time < 0 then
licenses[playerIndex] = nil
licenses[factionIndex] = nil

Player(playerIndex):sendChatMessage(station.title, 0, "Your salvaging license expired. You may no longer salvage in this area."%_t);
if here then
msg = "Your salvaging license expired. You may no longer salvage in this area."%_t
else
msg = "Your salvaging license in %s expired. You may no longer salvage in this area."%_t
end
else
licenses[playerIndex] = time
licenses[factionIndex] = time
end

if msg then
local x, y = Sector():getCoordinates()
local coordinates = "${x}:${y}" % {x = x, y = y}

faction:sendChatMessage(station.title, 0, msg, coordinates)
if doubleSend then
faction:sendChatMessage(station.title, 2, msg, coordinates)
end
end
end

Expand Down Expand Up @@ -369,7 +420,8 @@ function Scrapyard.buyLicense(duration)
end

function Scrapyard.sendLicenseDuration()
local duration = licenses[callingPlayer]
local owner, ship, player = getInteractingFaction(callingPlayer)
local duration = licenses[owner.index]

if duration ~= nil then
invokeClientFunction(Player(callingPlayer), "setLicenseDuration", duration)
Expand Down Expand Up @@ -455,6 +507,4 @@ function Scrapyard.unallowedDamaging(shooter, faction, damage)

end

-- DNightmare/ScrapyardPlus START
if not pcall(require, "mods/ScrapyardPlus/scripts/entity/merchants/scrapyard") then print("Failed to load ScrapyardPlus") end
-- DNightmare/ScrapyardPlus END
if not pcall(require, "mods/ScrapyardPlus/scripts/entity/merchants/scrapyard") then print("Failed to load ScrapyardPlus") end -- DNightmare/ScrapyardPlus END
2 changes: 1 addition & 1 deletion mods/ScrapyardPlus/config/ScrapyardPlusConfig.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local ScrapyardPlusConfig = {}

ScrapyardPlusConfig.version = "[1.2.0]"
ScrapyardPlusConfig.version = "[1.2.1]"
ScrapyardPlusConfig.modName = "[ScrapyardPlus]"
ScrapyardPlusConfig.allowLifetime = true
ScrapyardPlusConfig.lifetimeLevelFactor = 1.0
Expand Down
185 changes: 122 additions & 63 deletions mods/ScrapyardPlus/scripts/entity/merchants/scrapyard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ function Scrapyard.onShowWindow()
visible = true
end

function Scrapyard.onCloseWindow()
local station = Entity()
displayChatMessage("Please, do come again."%_t, station.title, 0)

visible = false
end

-- this function gets called once each frame, on client only
function Scrapyard.getUpdateInterval()
return 1
end

function Scrapyard.getLicenseDuration()
invokeServerFunction("sendLicenseDuration")
end
Expand Down Expand Up @@ -332,69 +344,6 @@ function Scrapyard.getLicensePrice(orderingFaction, minutes, type)
return basePrice, reputationDiscount, bulkDiscount, totalPrice
end

function Scrapyard.updateServer(timeStep)

local station = Entity();

newsBroadcastCounter = newsBroadcastCounter + timeStep
if newsBroadcastCounter > 60 then
Sector():broadcastChatMessage(station.title, 0, "Get a salvaging license now and try your luck with the wreckages!" % _t)
newsBroadcastCounter = 0
end

-- counter for update, this is only executed once per second to save performance.
for playerIndex, actions in pairs(illegalActions) do

actions = actions - 1

if actions <= 0 then
illegalActions[playerIndex] = nil
else
illegalActions[playerIndex] = actions
end
end

for factionIndex, time in pairs(licenses) do
local faction = Faction(factionIndex)
local x,y = Sector():getCoordinates()
local licenseText = 'alliance salvaging license'
if faction.isPlayer then
licenseText = 'salvaging license'
end

-- only check if a full second has passed
if round(time) ~= round(time - timeStep) then
if time > 10 and time - 1 <= 10 then
Scrapyard.notifyFaction(factionIndex, 0, string.format("\\s(%i:%i) Your %s license will run out in 10 seconds." % _t, x, y, licenseText), station.title)
Scrapyard.notifyFaction(factionIndex, 2, string.format("Your %s license will run out in 10 seconds." % _t, licenseText), station.title)
end

if time > 30 and time - 1 <= 30 then
Scrapyard.notifyFaction(factionIndex, 0, string.format("\\s(%i:%i) Your %s will run out in 30 seconds. Renew it NOW and save yourself some trouble!" % _t, x, y, licenseText), station.title)
end

if time > 120 and time - 1 <= 120 then
Scrapyard.notifyFaction(factionIndex, 0, string.format("\\s(%i:%i) Your %s will run out in 2 Minutes. Renew it and save yourself some trouble!" % _t, x, y, licenseText), station.title)
end

if time > 300 and time - 1 <= 300 then
Scrapyard.notifyFaction(factionIndex, 0, string.format("\\s(%i:%i) Your %s will run out in 5 Minutes." % _t, x, y, licenseText), station.title)
end

if time > 600 and time - 1 <= 600 then
Scrapyard.notifyFaction(factionIndex, 0, string.format("\\s(%i:%i) Your %s will run out in 10 minutes." % _t, x, y, licenseText), station.title)
end
end
time = time - timeStep
if time < 0 then
licenses[factionIndex] = nil
Scrapyard.notifyFaction(factionIndex, 0, string.format("\\s(%i:%i) Your %s expired." % _t, x, y, licenseText), station.title)
else
licenses[factionIndex] = time
end
end
end

function Scrapyard.buyLicense(duration, type)
local buyer = Player(callingPlayer)
local player = Player(callingPlayer)
Expand Down Expand Up @@ -496,6 +445,116 @@ function Scrapyard.onHullHit(objectIndex, block, shootingCraftIndex, damage, pos
end
end

function Scrapyard.updateServer(timeStep)

local station = Entity();

newsBroadcastCounter = newsBroadcastCounter + timeStep
if newsBroadcastCounter > 60 then
Sector():broadcastChatMessage(station.title, 0, "Get a salvaging license now and try your luck with the wreckages!"%_t)
newsBroadcastCounter = 0
end

for factionIndex, actions in pairs(illegalActions) do

actions = actions - 1

if actions <= 0 then
illegalActions[factionIndex] = nil
else
illegalActions[factionIndex] = actions
end
end

for factionIndex, time in pairs(licenses) do

time = time - timeStep

local faction = Faction(factionIndex)
local here = false
if faction.isAlliance then
faction = Alliance(factionIndex)
elseif faction.isPlayer then
faction = Player(factionIndex)

local px, py = faction:getSectorCoordinates()
local sx, sy = Sector():getCoordinates()

here = (px == sx and py == sy)
end

local doubleSend = false
local msg

-- warn player if his time is running out
if time + 1 > 10 and time <= 10 then
if here then
msg = "Your salvaging license will run out in 10 seconds."%_t
else
msg = "Your salvaging license in %s will run out in 10 seconds."%_t
end

doubleSend = true
end

if time + 1 > 20 and time <= 20 then
if here then
msg = "Your salvaging license will run out in 20 seconds."%_t
else
msg = "Your salvaging license in %s will run out in 20 seconds."%_t
end

doubleSend = true
end

if time + 1 > 30 and time <= 30 then
if here then
msg = "Your salvaging license will run out in 30 seconds. Renew it and save yourself some trouble!"%_t
else
msg = "Your salvaging license in %s will run out in 30 seconds. Renew it and save yourself some trouble!"%_t
end
end

if time + 1 > 120 and time <= 120 then
if here then
msg = "Your salvaging license will run out in 2 minutes. Renew it NOW and save yourself some trouble!"%_t
else
msg = "Your salvaging license in %s will run out in 2 minutes. Renew it NOW and save yourself some trouble!"%_t
end
end

if time + 1 > 300 and time <= 300 then
if here then
msg = "Your salvaging license will run out in 5 minutes. Renew it immediately and save yourself some trouble!"%_t
else
msg = "Your salvaging license in %s will run out in 5 minutes. Renew it immediately and save yourself some trouble!"%_t
end
end

if time < 0 then
licenses[factionIndex] = nil

if here then
msg = "Your salvaging license expired. You may no longer salvage in this area."%_t
else
msg = "Your salvaging license in %s expired. You may no longer salvage in this area."%_t
end
else
licenses[factionIndex] = time
end

if msg then
local x, y = Sector():getCoordinates()
local coordinates = "${x}:${y}" % {x = x, y = y}

faction:sendChatMessage(station.title, 0, msg, coordinates)
if doubleSend then
faction:sendChatMessage(station.title, 2, msg, coordinates)
end
end
end
end

-- ScrapyardPlus new functions
function Scrapyard.createSoloTab()
-- create a second tab
Expand Down

0 comments on commit 9c51427

Please sign in to comment.