Custom NPC's

    Joined
    Aug 14, 2012
    Messages
    22
    Reaction score
    13
    • Purchased!
    • Legacy Citizen 3
    Morlans NPC's



    I am writing some scripts for NPC's. I will continue to update this post with new script packages (which may have varying levels of difficulty installing). I will supply instructions with each one (once I tidy up the packages) but normally this will involve only placing the files into StarMade/data/script and sometimes adding data files to a known location. In all cases it is HIGHLY recommended that you look at the top of the source files for any configuration options, and in some cases you might need to change some body text to your liking.

    I hope to have a new default.lua for hired units that will be able to fire guns, patrol your ship/base and perform other duties. The other long term project is the AI-Anti-Faction. Both of these are long term and I shall be using these smaller projects as milestones to the end goal. Hopefully by the time we reach there we will have quests, traders, crew, civilians or even factions with evolving diplomacy.

    Here is a list of my current projects:
    • Lost crew member quest aka; Waldo (100% - available in this post)
    • Useful crew member (20% - unavailable)
    • AI Anti-faction Commander (0% - thinking stage)
    • Mailman (1% - unavailable/not functional)
    Downloads are attached to this post

    You may customize these as you wish or use them as a template to create your own. but if you do this I strongly recommend that you publish your scripts for everyone else to use too. I am not an expert LUA programmer so please excuse the clumsy coding, I'm far more at home with C or java.
    I feel happy that anyone use these on their public servers without any linking to my own services. I hold no copyright over any material and my status shall remain no more than "first post", all rights belong to the creators of Star-Made.


    ~morlan
     

    Attachments

    Last edited:
    Joined
    Aug 14, 2012
    Messages
    22
    Reaction score
    13
    • Purchased!
    • Legacy Citizen 3
    I will go in to how to install the new scripts, how to apply them to an NPC and how to edit the script for customisation.
    I will explain a little now. I have found it relatively easy to code new NPC using the internal scripting system. There is no documentation on how this is done so for the moment I have limited actions that NPC's can take but it looks like it should be enough.

    The main way you will customise these scripts would be to open them up in a text editor and at the top will be some defines for values, you will simply have to change the value assignments (cords for movement locations, doors, and body text).
    To install you just pop the file into the right folder and then set the script in game using the admin commands.

    I hope this helps and although I'm at work this week and quite busy I'll have something to show you soon, by the weekend at least. Are there are preferences on how the files can be posted here. Does the forum allow me to attach files, I could use pastebin, github or direct download from my webserver.

    Any ideas for mobs that you would like added? Some ideas I'm working on are ...
    • Basic greeters (done)
    • Pirates for custom event stations (20%)
    • Shop (20%)
    • Lost Shipmate quest (80%)
    • Upgraded crew member (warning, this replaces the default crew member script and requires you to make a copy of the original. 30%)
     
    Last edited:
    Joined
    Jul 15, 2013
    Messages
    333
    Reaction score
    100
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 4
    Good idea
    I did my own NPC with custom dialogue, but I didn't achieve to make them do something (except one "crewsergeant" who can spawn new crew for free, but I just copied the crew seller's script). I didn't achieve to give them a specific skin

    I will be interested to look at your scripts
     
    Joined
    Jul 15, 2013
    Messages
    333
    Reaction score
    100
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 4
    Is this even possible? If so: Someone give it to me. NOOWWWWW
    I'm not sure, but I think the NPC at 2,2,2 (the one selling crew) has a specific skin (not the dave suit)
    So I though it was in its script so I checked but my poor LUA skills stopped me here
     

    Master1398

    Keep calm and quit raging
    Joined
    Aug 19, 2013
    Messages
    293
    Reaction score
    229
    • Purchased!
    • Community Content - Bronze 2
    • Legacy Citizen 3
    I'm not sure, but I think the NPC at 2,2,2 (the one selling crew) has a specific skin (not the dave suit)
    So I though it was in its script so I checked but my poor LUA skills stopped me here
    As far as my research goes the trading guild NPC doesn't get his skin directly from his script (which would be awesome schema ) but if you change his script the skin stays until the server restarts!
    My quess is that the skin is hooked to any NPC that has the trader script when the NPC spawns. And yes, i tried to change the script of a regular NPC to the trading guild NPC script - worked but skin hasn't changed.
     
    Joined
    Jul 15, 2013
    Messages
    333
    Reaction score
    100
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 4
    As far as my research goes the trading guild NPC doesn't get his skin directly from his script (which would be awesome schema ) but if you change his script the skin stays until the server restarts!
    My quess is that the skin is hooked to any NPC that has the trader script when the NPC spawns. And yes, i tried to change the script of a regular NPC to the trading guild NPC script - worked but skin hasn't changed.
    So this is not something written inside the script that do it
    But it should!
     
    Joined
    Aug 14, 2012
    Messages
    22
    Reaction score
    13
    • Purchased!
    • Legacy Citizen 3
    most of the actions available are exposed in the current NPC scripts, it looks like there are other routines that can be accessed from the LUA interface, hopefully I can get a call to command callbacks so an npc can initiate an invasion. As far as I am concerned the NPC skin is someone elses problem, I would really like to keep the conversation about the actual scripting of these things.

    I am writing a small system with this with user level identification. The NPC will retain a list of people it talks to, current "quest" state for that user etc, so I think some kind of questing system should be very possible. although it will probably require a separate file for each NPC element in the quest chain. But simple go here and back(using a source and dest NPC), item retrieval (using a pseudo item) should be possible. I do not see a way (unless the author implements one) to trigger an event that an NPC can respond to without an NPC being interacted with, by this I mean;
    The NPCs' operate in a separate domain to the rest of the world. They have only 1 "sensor" and very few "actuators".

    I'm really pleased this has sparked discussion, and also that other people are having a go at this. I am pretty sure the author did not intend for this area to be customizable as his interface in the target language is limited to addressed references.

    I'm looking forward to sharing what I am working on, (but development time is limited) and seeing what everyone else comes up with.


    ~Morlan
     
    Last edited:
    Joined
    Aug 14, 2012
    Messages
    22
    Reaction score
    13
    • Purchased!
    • Legacy Citizen 3
    Hi, I'm just posting today to update and give a milestone report on my progress.

    WoW! This has been more of a pain than I thought, looks like to do anything meaningful I have had to import libraries, find workarounds and yell at the screen. On the up side I have learned a few things. The amount of values I have available has gone up. The NPC interface can give/take money, health, change factions and all the usual things. The first NPC I will post will be the "Lost crew member" npc;
    The objective is to simply locate him which rewards the player with a defined amount of money.
    The issue at the moment is getting luaj to store full tables in files without corrupting the dataset, I know this sounds simple but the basic file handling and table handling is not natively accessible so for the moment this NPC uses 2 lua files and 2 data files.
    It will be important to NOT edit the files by hand as its VERY sensitive to 0 byte line. The script I will upload first should have enough annotation to make building from my work much easier.

    Any suggestions for future questers?

    ~morlan
     
    Joined
    Jul 15, 2013
    Messages
    333
    Reaction score
    100
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 4
    Nice job, I'll be pleased to check your scripts (annotations will be quite useful for me)

    The lost NPC crew is a great idea and this kind of feature could help us reward exploration on servers.

    But it could be great if it was possible to script a quest giver NPC. It could be the one looking for the lost crew. If talking to him he explain how his friend was trapped in an anomaly and lost since. He should give the player the coordinates of the star system where the lost NPC is, so you still have to search an entire system to find it.

    And the lost NPC would reward you only if you have the quest given by the other one, or if it's the first time you talk to the lost NPC

    This is a lot of things, and it won't be easy so consider it just like suggestions.

    I was thinking about hostiles crew, but I think it is already possible using stock NPC and spawning it within pirate faction.
    But it could be great if we could place a "hostile spawner crew". It would spawn pirates NPC every x minutes. The NPC spawned would be assigned to a hostile faction (pirates, pagans, marine deserters), have a weapon and attack player on sight, but not the spawner (will stay where it is placed "hiding"). So when all hostiles are killed, you have to find the spawner in order to stop the pirates from attacking you. When talking to him, the text would say you neutralize him, and let you choose between letting him alive (but he could not spawn pirates anymore) or kill him.
     
    Joined
    Aug 14, 2012
    Messages
    22
    Reaction score
    13
    • Purchased!
    • Legacy Citizen 3
    Hi, again!
    I'm uploading revision 1 of this questing npc.
    Here are the installation instructions:
    • upload the zip to your server (skip if your server i is local)
    • extract the files
    • move both LUA files to the StarMade/data/script folder
    • put the two dat files somewhere where you know the path!
    • open up the script files in turn and change the filepath and filepathc variables to point to your dat files.
    • change the prize value in waldo2.lua to taste
    • load two NPC's and assign a script to each (DO NOT activate)
    • put the NPC containing waldo1 at your spawn
    • put the NPC containing waldo2 somewhere magical
    • open up waldo1 and search for "QUEST CLUE" and alter this to give a hint to his location
    • profit

    Please do not judge too harshly on my code, I did all this reverse engineering with nothing but a StarMade cleint, server, and vi; the only feedback I received was when it doesn't work you get an NPE, no traceback.


    >------------SNIP----------<
    Next project and a bit of a rant:
    I have annotated this to make it easy to understand, it shouldn't be hard to make things like shops, google data retrieval, mail, more quests etc.
    One project I am also working on is a custom crew member where you define points for him to be, defining weapon positions and a standby position/wander. Then he will add a hook for HIS commander/crew leader that when they next open a ship core a dialog will open (using hooks).
    From this dialog you will be able to tell him to "start firing pattern", "patrol ship", "close all doors" and "guard the bridge".

    Obviously the setup for this will be extensive and I think ill use sqlite than files in future (I would have used only one file if it was such a sissy about writing tables to files), essentially you would be able to define 3 weapon computers for him to fire, 6 doors, location of standby position and the location of your bridge.
    [DOUBLEPOST=1423403556,1423401589][/DOUBLEPOST]
    Nice job, I'll be pleased to check your scripts (annotations will be quite useful for me)

    The lost NPC crew is a great idea and this kind of feature could help us reward exploration on servers.

    But it could be great if it was possible to script a quest giver NPC. It could be the one looking for the lost crew. If talking to him he explain how his friend was trapped in an anomaly and lost since. He should give the player the coordinates of the star system where the lost NPC is, so you still have to search an entire system to find it.

    And the lost NPC would reward you only if you have the quest given by the other one, or if it's the first time you talk to the lost NPC

    This is a lot of things, and it won't be easy so consider it just like suggestions.

    I was thinking about hostiles crew, but I think it is already possible using stock NPC and spawning it within pirate faction.
    But it could be great if we could place a "hostile spawner crew". It would spawn pirates NPC every x minutes. The NPC spawned would be assigned to a hostile faction (pirates, pagans, marine deserters), have a weapon and attack player on sight, but not the spawner (will stay where it is placed "hiding"). So when all hostiles are killed, you have to find the spawner in order to stop the pirates from attacking you. When talking to him, the text would say you neutralize him, and let you choose between letting him alive (but he could not spawn pirates anymore) or kill him.
    Yes I think much of that is possible. I have a list of variables and functions I have fluffed. You can give meta items, items by number and can maintain databases, so I don't see why what you are saying isn't possible. Look at my previous post, might interest you.
    The Waldo quest already relies on you triggering the event from an npc, it will track who has started and who has completed (VERY simply). I'm not sure if I can get an NPC to actually spawn something unless getWorld() is a valid member of the dialogObject, I haven't looked at that much get, but you can certainly reference the player and the npc, assign hooks (things that happens when something is detected, but limited)
     

    Attachments

    Joined
    Jul 15, 2013
    Messages
    333
    Reaction score
    100
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 4
    I just looked inside, it's quite understadable and clean, good job
    I'll try to put it in game in order to test it today or tomorrow.

    Maybe the quest system in the future will be done this way.
    I'll try to find a way to take items from the player's inventory. So maybe I can do some kind of old hermit asking for food.
     
    Joined
    Aug 14, 2012
    Messages
    22
    Reaction score
    13
    • Purchased!
    • Legacy Citizen 3
    If you have access to the code having a look at the methods returned by getPlayer(), probably defined in its own class called player. i have tried takeItem and take() but of course with no feedback from the engine apart from a null when it doesnt work its quite a mission to fluff out all the methods. i have about a dozen i have fluffed already for changing credit values, faction data things like that. position data is something im working on also. The crwe member im working on will have positions you can define as battle positions and define standby positions so you can declare status alerts to AI crew on your ship.

    Just remember if you need any string, sorting functions things like that then you will have to bind the object yourself the environment is very basic. but it does look like we can bind to any function in the codebase as long as we know how its defined.
     
    Joined
    Jul 15, 2013
    Messages
    333
    Reaction score
    100
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 4
    we can bind to any function in the codebase as long as we know how its defined.
    That's so much great. But I see what you're talking about lack of debugging possibility. I do not know how you managed to find the exact denominations to get a full script ^^
    That's what makes it very difficult for me to try my own, but I hope for some documentation/debugging tools in the future because my skills are too humble at the moment

    I think the "guard" script you're describing with position function will be really awesome
     
    Joined
    Aug 14, 2012
    Messages
    22
    Reaction score
    13
    • Purchased!
    • Legacy Citizen 3
    apparently there is a community javadoc im going to try and see if the methods in there are directly bindable, but as i said not every method seems available to the LUA. Here are some methods i have already picked out, and yes I know these were the low hanging fruit here, but had to start somewhere. :)
    I wont put my full reference here, but reading the scripts easily solves most of that.
    Obviously the create is equal to main(), the createSomething() functions is the format for populating dialogs and linking.
    here are some methods
    dialogObject:getConverationParterName() = npc name
    dialogObject:isConverationPartnerInTeam() =returns bool
    dialogObject:getConverationPartnerAffinity() =ship/object afinity
    dialogObject:getConverationPartnerOwnerName() = NPC owner (shows as faction ae for some)
    dialogObject:getConverationPartnerFactionName() = faction
    dialogObject:getEntity():getName() = player name
    dialogObject:getEntity():getCredits() = player credits
    dialogObject:getEntity():setCredits(int) = set money
    dialogObject:getEntity():getHealth()
    dialogObject:getEntity():getMaxHealth() (setMaxHealth() not tested for yet)
    dialogObject:getEntity():setHealth(int)
    dialogObject:getEntity():getFactionName()
    dialogObject:getEntity():getFactionId()
    dialogObject:getEntity():setFactionId() (not fully tested, can set variable but may not update factiondb)
     
    Joined
    Feb 24, 2014
    Messages
    101
    Reaction score
    23
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 5
    good work .
    I have used your waldo scripts on my server ,
    one thing i think could make the install a bit easier is set the default paths in the script to ./data/script/xxxx then you can just drop all the files in the script directory and it will work

    If you get the database side working reliably would it be possible to write a banker NPC script?
     
    Last edited:
    Joined
    Aug 14, 2012
    Messages
    22
    Reaction score
    13
    • Purchased!
    • Legacy Citizen 3
    Thats a good idea, I'll make that change and use that convention in future. And sure it would be possible though I would need to have some kind of checking that someone doesn't try withdrawing money that would take them over the max purse amount. also there would need to be some kind of control in there as the script actually gets executed in totality every time the user click it. So this means any nonlinear event, user dependent event needs to be held behind an if statement using a flag as control, the control would need to be carefully switched because if you just buying=true on a new form called by a button that script itself will be executed ahead of time. I think making better use of hooks (hooking a function to a button object) would be a better way around this.
    I haven't tested this to see if it avoid the above problem, but it should as its not a synchronous event (the server can not possibly predict when a user will trigger a hooked event).

    Also I'm still looking for methods for creating user input elements.
     
    Joined
    Feb 24, 2014
    Messages
    101
    Reaction score
    23
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 5
    dont know if you have found this out already but toString() seems to work on some methods, might be usefull for determining what kind of data they return
    dialogObject:getEntity():getInventory():toString();
     
    • Like
    Reactions: morlan
    Joined
    Mar 23, 2015
    Messages
    1
    Reaction score
    3
    So I have been doing some work here and there.. and I think NPCs/quests are key. I loved minecraft because it was so open world/ I hated minecraft because it was without purpose/focus/reward. Here we can have the best of both worlds + we have loads more worlds to work with and spaceships..

    So here is a little of what I have done thus far--

    Using StarNet.jar w/ super admin enabled--
    I wrote a script to gather user details and store them in a mysql database. Stuck this script in cron to execute every 5 minutes.
    It tracks a timestamp for last seen, ip address, username, account name, credits etc etc..
    I also allow players (I only started this server a few days ago, so just my friends for now), to register their character on a website with a code sent to them in game to verify ownership. I then flag them as registered in the database. They then can gain merit points for time online (capped daily), PKs, NPC kills, trading in certain blocks, and soon, quests!

    I include a single function that calls a secured php script (outside the web root, and locked down to local machine).

    function hookphp(cmd)
    local command = "php-cgi -f /path/to/my/hook.php player="..player.." cmd="..cmd;
    local handle = io.popen(command);
    local result = handle:read("*a");
    handle:close();
    return result;
    end

    where player is a global var, player = dialogObject:getEntity():getName();
    and cmd is a delimited string. ex hookphp("NPC_001|QuestStep3")

    This php script interfaces with my web application/myssql database to set/fetch state flags for a specific NPC. I also invoke and regex parse anything you can do with admin commands. This means I can use the mthods I wrote to do things like:

    Take/Give Money
    Take/Give Items
    Teleport people - This one is kinda cool! It allows instanced missions! Players detected entering into these sectors are kicked back and given a warning. But players with the flag are allowed to be there (until they complete the mission, die, logout, or the mission expires). Then if the sector is free, just reload it and someone else can have a go!
    Track time (for quests that expire)
    And other things not realted so much to quests, like have a killboard (tracking both pvp and pve kills), use the merit points and player actions to assigning ranks etc etc.. I'm building new methods all the time as I learn more about how I can manipulate the tools I have access to with the skills I have.

    Anyway.. Once I have this to an art, and later in the games development, maybe I'll release it open source (not going to happen right now do to the unstable nature of the game). That said, I don't mind sharing the ideas because it might spark something in someone else..

    The ability to have deep dynamic quests with multiple types of rewards is possible, I do it, but at the end of the day.. It's a kick in the teeth when people kill your npcs :(.. Has anyone found a way of making them invulnerable? Lock them in place (the boune all over the place when shot at).

    Like I said, I only started at this a few days ago.. But there is some potential here.. And it would be cool to find like-minded folks to work on this project with.