Aidenholmes9 Posted February 7, 2020 Share Posted February 7, 2020 So i did an item that spawn a player ship and during generation adds some scripts to the ship, works well until i try to set a statbonus, here the script package.path = package.path .. ";data/scripts/lib/?.lua" package.path = package.path .. ";data/scripts/?.lua" include("stringutility") local ShipGenerator = include("shipgenerator") local NamePool = include ("namepool") function create(item, rarity, allyIndex) rarity = Rarity(RarityType.Legendary) item.stackable = false item.depleteOnUse = true item.name = "Nomad Beacon"%_t item.price = 1000000000 item.icon = "data/textures/icons/ship.png" item.rarity = rarity item:setValue("subtype", "ReinforcementsTransmitter") item:setValue("factionIndex", allyIndex) local tooltip = Tooltip() tooltip.icon = item.icon local title = "Nomad Beacon"%_t local headLineSize = 25 local headLineFontSize = 15 local line = TooltipLine(headLineSize, headLineFontSize) line.ctext = title line.ccolor = item.rarity.color tooltip:addLine(line) -- empty line tooltip:addLine(TooltipLine(14, 14)) local line = TooltipLine(20, 14) line.ltext = "Player Ship"%_t line.rtext = "${faction:"..allyIndex.."}" line.icon = "data/textures/icons/flying-flag.png" line.iconColor = ColorRGB(0.8, 0.8, 0.8) tooltip:addLine(line) tooltip:addLine(TooltipLine(14, 14)) local line = TooltipLine(20, 14) line.ltext = "Nomad Type"%_t line.rtext = "Prototype" line.icon = "data/textures/icons/ship.png" line.iconColor = ColorRGB(0.8, 0.8, 0.8) tooltip:addLine(line) tooltip:addLine(TooltipLine(14, 14)) local line = TooltipLine(20, 14) line.ltext = "Turrets Factory"%_t line.rtext = "Yes" line.rcolor = ColorRGB(0.3, 1, 0.3) line.icon = "data/textures/icons/turret.png" line.iconColor = ColorRGB(0.8, 0.8, 0.8) tooltip:addLine(line) local line = TooltipLine(20, 14) line.ltext = "Fighter Factory"%_t line.rtext = "Yes" line.rcolor = ColorRGB(0.3, 1, 0.3) line.icon = "data/textures/icons/fighter.png" line.iconColor = ColorRGB(0.8, 0.8, 0.8) tooltip:addLine(line) local line = TooltipLine(20, 14) line.ltext = "Upgrades Factory"%_t line.rtext = "No" line.rcolor = ColorRGB(1, 0.3, 0.3) line.icon = "data/textures/icons/circuitry.png" line.iconColor = ColorRGB(0.8, 0.8, 0.8) tooltip:addLine(line) local line = TooltipLine(20, 14) line.ltext = "Torpedoes Factory"%_t line.rtext = "No" line.rcolor = ColorRGB(1, 0.3, 0.3) line.icon = "data/textures/icons/missile-pod.png" line.iconColor = ColorRGB(0.8, 0.8, 0.8) tooltip:addLine(line) local line = TooltipLine(20, 14) line.ltext = "Utilities Factory"%_t line.rtext = "No" line.rcolor = ColorRGB(1, 0.3, 0.3) line.icon = "data/textures/icons/satellite.png" line.iconColor = ColorRGB(0.8, 0.8, 0.8) tooltip:addLine(line) local line = TooltipLine(20, 14) line.ltext = "Research Facility"%_t line.rtext = "Yes" line.rcolor = ColorRGB(0.3, 1, 0.3) line.icon = "data/textures/icons/cog.png" line.iconColor = ColorRGB(0.8, 0.8, 0.8) tooltip:addLine(line) local line = TooltipLine(20, 14) line.ltext = "Refinery Facility"%_t line.rtext = "Yes" line.rcolor = ColorRGB(0.3, 1, 0.3) line.icon = "data/textures/icons/zinc.png" line.iconColor = ColorRGB(0.8, 0.8, 0.8) tooltip:addLine(line) -- empty line tooltip:addLine(TooltipLine(14, 14)) local line = TooltipLine(20, 15) line.ltext = "Depleted on Use"%_t line.lcolor = ColorRGB(1.0, 1.0, 0.3) tooltip:addLine(line) -- empty line tooltip:addLine(TooltipLine(14, 14)) local line = TooltipLine(20, 14) line.ltext = "Can be activated by the player"%_t tooltip:addLine(line) local line = TooltipLine(20, 14) line.ltext = "Calls in the Nomad"%_t tooltip:addLine(line) local line = TooltipLine(20, 14) line.ltext = "Can be used anywhere"%_t tooltip:addLine(line) item:setTooltip(tooltip) return item end function activate(item) local faction = Galaxy():getControllingFaction(Sector():getCoordinates()) local sender = NamedFormat("${faction} Headquarters"%_T, {faction = faction.baseName}) local player = Player() local playerFaction = player.craftFaction local craft = player.craft -- Create the Nomad local pos = random():getDirection() * 1500 local matrix = MatrixLookUpPosition(normalize(-pos), vec3(0, 1, 0), pos) local ship = ShipGenerator.createShip(player, matrix) ship:invokeFunction("icon.lua", "set", nil) ship:removeScript("icon.lua") ship.title = "Nomad"%_T ship:addScriptOnce("data/scripts/entity/merchants/fighterfactory.lua") ship:addScriptOnce("data/scripts/entity/merchants/turretfactory.lua") ship:addScriptOnce("data/scripts/entity/merchants/researchstation.lua") ship:addScriptOnce("data/scripts/entity/merchants/refinery.lua") ship:addAbsoluteBias(StatsBonuses.HyperspaceReach, 300) -- HERE THE PROBLEM ship:addCrew(1, CrewMan(CrewProfessionType.Captain)) NamePool.setShipName(ship) Sector():broadcastChatMessage(ship, 0, "Reporting in..."%_t, ship.title, ship.name) return true end the problem is that the "ship:addAbsoluteBias(StatsBonuses.HyperspaceReach, 300)" works but when i close the "server (Singleplayer)" and then connect again that ship doenst have the hyper space bonus anymore, is possible to make that bonus permanent/persistent ? Thanks and sorry for my english... Link to comment Share on other sites More sharing options...
Rinart73 Posted February 7, 2020 Share Posted February 7, 2020 StatBonuses changes are tied to the script. The moment that script unloads or if entity is reloaded, they disappear and need to be re-applied. Look at how system upgrades apply bonuses - they do it initially in the "initialize" and after that in "restore". Link to comment Share on other sites More sharing options...
Aidenholmes9 Posted February 7, 2020 Author Share Posted February 7, 2020 StatBonuses changes are tied to the script. The moment that script unloads or if entity is reloaded, they disappear and need to be re-applied. Look at how system upgrades apply bonuses - they do it initially in the "initialize" and after that in "restore". So i should make a script that add the bonus? or can i make it on the item? Also where the upgrades "initialize" and "restore"? Here a simple upgrade that adds velocity and acceleration like and absolute value... package.path = package.path .. ";data/scripts/systems/?.lua" package.path = package.path .. ";data/scripts/lib/?.lua" include ("basesystem") include ("utility") -- optimization so that energy requirement doesn't have to be read every frame FixedEnergyRequirement = true Unique = true function getBonuses(seed, rarity) local velocity = 200 local acceleration = 25 local energy = 2 return velocity, acceleration, energy end function onInstalled(seed, rarity, permanent) if not permanent then return end local velocity, acceleration, energy = getBonuses(seed, rarity) addAbsoluteBias(StatsBonuses.Velocity, velocity) addAbsoluteBias(StatsBonuses.Acceleration, acceleration) addBaseMultiplier(StatsBonuses.GeneratedEnergy, energy) end function onUninstalled(seed, rarity, permanent) end function getName(seed, rarity) return "Antimatter Engine"%_t end function getIcon(seed, rarity) return "data/textures/icons/turbine.png" end function getPrice(seed, rarity) return 10000 end function getTooltipLines(seed, rarity, permanent) local velocity, acceleration, energy = getBonuses(seed, rarity) local texts = { {ltext = "Velocity"%_t, rtext = "?"%_t, icon = "data/textures/icons/speedometer.png", boosted = permanent}, {ltext = "Acceleration"%_t, rtext = "?"%_t, icon = "data/textures/icons/acceleration.png", boosted = permanent}, {ltext = "Generated Energy"%_t, rtext = "?"%_t, icon = "data/textures/icons/electric.png", boosted = permanent} } if not permanent then return {}, texts else return texts, texts end end function getDescriptionLines(seed, rarity, permanent) return { {ltext = "This antimatter engine generates energy."%_t, lcolor = ColorRGB(1, 0.5, 0.5)}, {ltext = "", boosted = permanent}, {ltext = "This system gives fixed acceleration /* continues with 'and velocity ignoring weight.' */"%_t, rtext = "", icon = ""}, {ltext = "and velocity ignoring weight. /* continued from 'This system gives fixed acceleration' */"%_t, rtext = "", icon = ""} } end I suppose that the "initialize" is the "oninstalled function"? but where is the "restore"? I dont really know how to programe i can barely read those scripts and modify them like the upgrade or the first item that was a merchant caller... if you can take the time to explain or write an example great and thanks in advance and sorry again for my english :P Link to comment Share on other sites More sharing options...
Rinart73 Posted February 7, 2020 Share Posted February 7, 2020 So i should make a script that add the bonus? Yes Also where the upgrades "initialize" and "restore"? System upgrades include "basesystem.lua" - it has restore Link to comment Share on other sites More sharing options...
Aidenholmes9 Posted February 7, 2020 Author Share Posted February 7, 2020 So i should make a script that add the bonus? Yes Also where the upgrades "initialize" and "restore"? System upgrades include "basesystem.lua" - it has restore So the "onInstalled function" is the"restore" and not "initialize" thanks for the help! i should need the "secure" and "restore" functions right? if you can lead me to how to change "onInstalled" to the so called "entity reload" would save me weeks even if you point to a game file that do it, but for now you made my day thanks! Link to comment Share on other sites More sharing options...
Rinart73 Posted February 7, 2020 Share Posted February 7, 2020 Look at basesystem.lua again. "onInstalled" is being called both by "initialize" and "restore". You need "secure" only if you want to save some data between reloads (like the bonus value). Link to comment Share on other sites More sharing options...
Aidenholmes9 Posted March 16, 2020 Author Share Posted March 16, 2020 Look at basesystem.lua again. "onInstalled" is being called both by "initialize" and "restore". You need "secure" only if you want to save some data between reloads (like the bonus value). Thanks for your help! it worked =) Here the script if somebody is interested... Works well and the stats persist i dont know if it efficient but for my personal use works... package.path = package.path .. ";data/scripts/lib/?.lua" include ("utility") include ("stringutility") include ("callable") function initialize() local durability = Durability() local thrusters = Thrusters() local shield = Shield() thrusters.basePitch = 4 thrusters.baseRoll = 4 thrusters.baseYaw = 4 thrusters.fixedStats = 1 shield.immuneToDeactivation = 1 shield.maxDurabilityFactor = 2 durability.maxDurabilityFactor = 2 addAbsoluteBias(StatsBonuses.HyperspaceReach, 2.5) addAbsoluteBias(StatsBonuses.Velocity, 100) addAbsoluteBias(StatsBonuses.Acceleration, 25) addAbsoluteBias(StatsBonuses.RadarReach, 1) addAbsoluteBias(StatsBonuses.HiddenSectorRadarReach, 5) addAbsoluteBias(StatsBonuses.UnarmedTurrets, 2) addAbsoluteBias(StatsBonuses.ArmedTurrets, 2) if onClient() then invokeServerFunction("remoteReload") end end function remoteReload() broadcastInvokeClientFunction("remoteReloadCallback") end callable(nil, "remoteReload") function remoteReloadCallback() local durability = Durability() local thrusters = Thrusters() local shield = Shield() thrusters.basePitch = 4 thrusters.baseRoll = 4 thrusters.baseYaw = 4 thrusters.fixedStats = 1 shield.immuneToDeactivation = 1 shield.maxDurabilityFactor = 2 durability.maxDurabilityFactor = 2 addAbsoluteBias(StatsBonuses.HyperspaceReach, 2.5) addAbsoluteBias(StatsBonuses.Velocity, 100) addAbsoluteBias(StatsBonuses.Acceleration, 25) addAbsoluteBias(StatsBonuses.RadarReach, 1) addAbsoluteBias(StatsBonuses.HiddenSectorRadarReach, 5) addAbsoluteBias(StatsBonuses.UnarmedTurrets, 2) addAbsoluteBias(StatsBonuses.ArmedTurrets, 2) end function addBaseMultiplier(bonus, factor) if factor == 1 then return end if onClient() then return end local key = Entity():addBaseMultiplier(bonus, factor) return key end function addMultiplier(bonus, factor) if factor == 1 then return end if onClient() then return end local key = Entity():addMultiplier(bonus, factor) return key end function addMultiplyableBias(bonus, factor) if factor == 0 then return end if onClient() then return end local key = Entity():addMultiplyableBias(bonus, factor) return key end function addAbsoluteBias(bonus, factor) if factor == 0 then return end if onClient() then return end local key = Entity():addAbsoluteBias(bonus, factor) return key end function restore(data) local durability = Durability() local thrusters = Thrusters() local shield = Shield() thrusters.basePitch = 4 thrusters.baseRoll = 4 thrusters.baseYaw = 4 thrusters.fixedStats = 1 shield.immuneToDeactivation = 1 shield.maxDurabilityFactor = 2 durability.maxDurabilityFactor = 2 addAbsoluteBias(StatsBonuses.HyperspaceReach, 2.5) addAbsoluteBias(StatsBonuses.Velocity, 100) addAbsoluteBias(StatsBonuses.Acceleration, 25) addAbsoluteBias(StatsBonuses.RadarReach, 1) addAbsoluteBias(StatsBonuses.HiddenSectorRadarReach, 5) addAbsoluteBias(StatsBonuses.UnarmedTurrets, 2) addAbsoluteBias(StatsBonuses.ArmedTurrets, 2) end Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now