Jump to content

Rinart73

Members
  • Posts

    416
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Rinart73

  1. For example some mod adds a script to every ship. And when server owner will try to delete it, he will need to replace this script file with one that has 'terminate' call in it. And this file will stay forever. Because there is a bunch of sectors with ships and you can only operate sectors that are loaded in memory.
  2. You can check my haulgoods.lua script in http://www.avorion.net/forum/index.php/topic,2896.0.html It calls functions in the same script in other objects and has some simple things in there to check/test/set/return values in other objects. Basically you make functions in the object that set or return the values in that object. Example to set or get the debuglevel in an object that's running my script: function getDebugLevel() return debugLevel end function setDebugLevel(arg) debugLevel = tonumber(arg) end Which will set the global debugLevel in the script this function is called in. Called like this: local retval, level = ship:invokeFunction(haulscript, "getDebugLevel") local retval = ship:invokeFunction(haulscript, "setDebugLevel", debugLevel) You need to let go of the C++ type OOP implementations, where "object" is just the name of a blob of code, and start thinking as objects being *actual* objects, like a ship, or a station, or a sector. To find all ships in a sector, you will call a function in the sector that will return a list of ship objects. Each of these ship objects have a number of scripts attached to them that will have certain functionality. In my example, "haulscript" is the global variable I've defined that contains the definition of the script that provides the setDebugLevel and getDebugLevel functions for JUST that script. local haulscript = "data/scripts/entity/ai/haulgoods.lua" Another script can have exactly the same functions, but will still only work in the context of that script attached to that specific ship object. Within the script, Entity() will be the object it's attached to. There is a lot of function documentation (very unfinished) in the Documentation folder of your Avorion install. Thank you for response and tips. I actually already figured out and implemented some variables system that syncs them when I need it. And my mod is almost ready for the beta-release, I think. Now I just trying to figure out how to uninstall mods properly. I get this in my logs after reverting to the vanilla scripts: "Loading of sector (x:y) failed. Treating sector as non-exsting. Error: Script 'data/scripts/entity/myScript.lua' not found. Tried the following paths:". So, as I understand, server saves object with my script attached to them. So right now I'm looking in the mods of other people to understand how they deal with this. UPD: As I see, there is no good ways to uninstall mod that attaches scripts right now. Basically everyone just replaces attached scripts content with "terminate()" and tells users that they need to delete this files when they're 100% sure, that scripts are unattached
  3. Thanks, I just found it myself in the API Reference :) (I probably shouldn't create so many threads..)
  4. When I'm trying to do something like this in script that I attached earlier: -- MyScript function initialize() local entity = Entity() if someCondition then entity:removeScript(pathToMyScript) end end server just crashes with error "EXCEPTION_ACCESS_VIOLATION". So.. how to removeScript from itself?
  5. Thanks, I'm going to the finish.. gradually. I'm trying to add some custom variables that're accessible after restart to the all Stations and Ships made by players in the sector. So I think I should do all checkings and attach script in the Sector's "onEntityCreate" callback or in defaultscripts.lua. But then I need to access this local script variables in some vanilla scripts, that were attached to this ship/station too. I don't think that variables from one attached script are visible to another attached script. Because it shouldn't be. So I think to complete my first mod for this game I just need to understand how people use variables from attached scripts anywhere. Maybe its something related to 'require', but I don't need to require a whole script again. I'll try to search in existing mods again.
  6. Ok, thanks, I'm beginning to understand. Probably I should attach scripts to Entities in a callback events like onPlayerLogIn, onEntityCreate e.t.c.? But now I have another question - When I should attach the script? I mean, for example I want to mess with a stations like factories or trading posts. Where should I attach my script? Earlier (when the sector just loaded) or just before user interacts with Entity. I mean, how I can be sure that I'll get some data from 'restore' just after I attached script to the Entity? Or its how it works? When you attach script, game instantly retrieves some data for it?
  7. Thanks. I understand how to use 'secure' and 'restore', but I can't understand where to put them. I mean, for example we have a defined class "Person" with some methods and callbacks like "onFirstStep". And if we want to "say hi", when user makes his first step: 1. We will make a new class that extends "Person" and overrides "onFirstStep". 2. Or we'll just change "Person" definition. I'm not very familiar with the Lua, but in our case we don't have definitions for classes and structures, for "Entity". So, what should I do, just put 'restore' and 'secure' in a random place in a random file and wait it to 'fire'? I don't think that's a good idea. Also I don't want to extend and override Entity structure. That's a bad idea too. - You gave me link, but showdist mod has nothing to do with 'secure'.
  8. I can't find anything to write something to the server database. How can I do that? Actually, I just need to attach Lua table to every Entity. And I need to save this tables between server restarts. I read about 'secure' and 'restore' Entity methods, but I'd like to see some examples. I just can't understand how to attach it.
  9. Wait a second, so when "Improved Trading System" upgrade shows me some trading routes in the X sectors around.. this traderoutes are actually just telling me that I can buy and sell this goods myself? Trade routes between sectors are fake? Only trade routes that exist in one sector do something with the goods count on both ends? As I think, its possible to simulate trading between factories out of sector (just like out of sector production mod does). But then we will soon have problem of overpopulated resources. So it needs to go somewhere. As for the next "Alliance" update, as I understand devs want to keep all Alliance sectors in memory as long as one player of the Alliance online. Thats.. not very good idea, considering that game server tends to lag even with 3 sectors loaded. I mean, not everybody has a dedicated server to run the game.
  10. Awesome, thanks for the answer. Can I ask another question related to this theme? For example we have a trade route from sector A (Ore Mine) to sector B (Steel Factory). We enter a sector A and see that Ore Mine has 500 Ore in it. We exit sector A and enter sector B. We stay here online for 9999 Hours. How will trade route act? I mean, yes, it will deliver ore to the Steel Factory but until when? Until the end of time or until we will transport all 500 Ore from the sector A to the sector B? What I'm trying to ask is: Does the traderoute affect goods on the factories that are placed in unloaded sectors if one end of the trade route is in the loaded sector?
  11. Hi. Before trying this mod I need to ask: Does this simulate only player-traders from Goods Hauler out-of-sector? It doesn't work for vanilla NPC traders?
  12. I've got some nice idea, but I need help to understand how auto-trading with factories/mines works. As I see, my steel factory trades with: 1. NPC ships on a trading routes (Steel Factory -> Servo Factory, Ore Mine -> Steel Factory) 2. Some random NPC ships that appear out of nowhere and buy/sell some stuff, from Ore to the Coal (and I don't have any Coal sources in a big radius. Only 2 trading posts that always has 0/X Coal). I can't understand second case. Is this some script that spawns random cargo ships? Or its a ships on the trading routes too, but I just can't see all routes? Can somebody explain this to me and give an API hint. I need to track those guys :) Also, how long can trade route be? (Sorry for any mistakes, my English is kinda poor)
×
×
  • Create New...