[Admin commands] Any dialog NPC

    Joined
    Jul 15, 2013
    Messages
    333
    Reaction score
    100
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 4
    I recently looked into the /creature_script function.
    It looks like we can add any script in the correct folder (StarMade\data\script)
    Select the concerned NPC with F, and type /creature_script "thescriptyouwant"
    npc-trading-guild.lua is the shop's NPC spawner script (usefull to buy troops in your own base).

    So I wanted to edit a script to set the dialog options I want for NPCs (bar, guards, workers). But this is quite painful. For now, I just have a template of script: the NPC has a text dialog when you press R on him, and a button to leave dialog AND it actually works ^^. It have one variable: the NPC's name. There may be more I don't know. I just kept this one from the existing script.

    Here is the script.
    Code:
    function create(dialogObject, bindings)
      dSysClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogSystem" );
      dSysFactoryClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogStateMachineFactory" );
      dSysEntryClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogStateMachineFactoryEntry" );
      hookClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogTextEntryHookLua" );
     
      dSys = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogSystem", dialogObject );
     
      print(dSys);
     
      factory = dSys:getFactory(bindings);
      hook = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogTextEntryHookLua", "hookFunc", {} );
    
      entry = luajava.newInstance( "org.schema.game.common.data.player.dialog.TextEntry",
      "Bonsoir, client.\n" ..
      "Je m'apelle ".. dialogObject:getConverationParterName() ..".\n"..
      "Ce sera quoi?"..
      "\n"
      , 2000 );
      factory:setRootEntry(entry);
    
      dSys:add(factory)
    
      return dSys
    
    --frame = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogSystem", "Texts" );
    --frame:test()
    end
    This a bartender's dialog. Just edit this part to make him say whatever you want:

    "Bonsoir, client.\n" ..
    "Je m'apelle ".. dialogObject:getConverationParterName() ..".\n"..
    "Ce sera quoi?"..
    "\n"

    Write only between the " and the \n are return to line.
     
    Joined
    Aug 30, 2013
    Messages
    1,744
    Reaction score
    323
    Unless you're French, that looks more like 'classy wine tasting man' conversation more than barman conversation.
    I can't script so this is my best attempt:
    "Alright, mate.\n" ..
    "ay up lad, what'l it be?".. dialogObject:getConverationParterName() ..".\n"..
    "Pint."..
    "\n"
    Just kidding. Good script, we will hopefully see better NPC's in the future. But not wine tasters.
     
    • Like
    Reactions: mgwerner and Mariux

    Master1398

    Keep calm and quit raging
    Joined
    Aug 19, 2013
    Messages
    293
    Reaction score
    229
    • Purchased!
    • Community Content - Bronze 2
    • Legacy Citizen 3
    I also have a script. It has three variables:

    dialogObject:getEntity():getName() //This one gives the name of the player who talks to the npc
    dialogObject:getConverationParterName() //This one gives the name of the npc
    dialogObject:getConverationPartnerFactionName() //This one gives the name of the faction to which the npc belongs


    I quess there is also a variable that gives the faction of the player who talks to the npc.
    A npc with this script just greets the player and tells him who he(the npc) is and to which faction he belongs:
    Code:
    function create(dialogObject, bindings)
      print(bindings)
      print(dialogObject)
      dSysClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogSystem" );
      dSysFactoryClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogStateMachineFactory" );
      dSysEntryClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogStateMachineFactoryEntry" );
      hookClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogTextEntryHookLua" );
      dSys = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogSystem", dialogObject );
      print(dSys);
      factory = dSys:getFactory(bindings);
    
      hook = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogTextEntryHookLua", "hookFunc", {} );
    
      entry = luajava.newInstance( "org.schema.game.common.data.player.dialog.TextEntry",
      "Greetings, ".. dialogObject:getEntity():getName() .."\n\n" ..
      "My name is ".. dialogObject:getConverationParterName() ..", and I'm a member of ".. dialogObject:getConverationPartnerFactionName() ..".\n"
      , 2000 );
      factory:setRootEntry(entry);
      dSys:add(factory)
    
      return dSys
    
    --frame = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogSystem", "Texts" );
    --frame:test()
    end
     
    Joined
    Jul 15, 2013
    Messages
    333
    Reaction score
    100
    • Purchased!
    • Community Content - Bronze 1
    • Legacy Citizen 4
    I also have a script. It has three variables:

    dialogObject:getEntity():getName() //This one gives the name of the player who talks to the npc
    dialogObject:getConverationParterName() //This one gives the name of the npc
    dialogObject:getConverationPartnerFactionName() //This one gives the name of the faction to which the npc belongs


    I quess there is also a variable that gives the faction of the player who talks to the npc.
    A npc with this script just greets the player and tells him who he(the npc) is and to which faction he belongs:
    Code:
    function create(dialogObject, bindings)
      print(bindings)
      print(dialogObject)
      dSysClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogSystem" );
      dSysFactoryClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogStateMachineFactory" );
      dSysEntryClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogStateMachineFactoryEntry" );
      hookClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogTextEntryHookLua" );
      dSys = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogSystem", dialogObject );
      print(dSys);
      factory = dSys:getFactory(bindings);
    
      hook = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogTextEntryHookLua", "hookFunc", {} );
    
      entry = luajava.newInstance( "org.schema.game.common.data.player.dialog.TextEntry",
      "Greetings, ".. dialogObject:getEntity():getName() .."\n\n" ..
      "My name is ".. dialogObject:getConverationParterName() ..", and I'm a member of ".. dialogObject:getConverationPartnerFactionName() ..".\n"
      , 2000 );
      factory:setRootEntry(entry);
      dSys:add(factory)
    
      return dSys
    
    --frame = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogSystem", "Texts" );
    --frame:test()
    end
    Nice to share
    I'll try do make a simple script to say some text just like now but have a button to hire crew (seems I can even set the price I want). I want to give it to a "security chief" NPC who say something like "Everything is fine, commander" and I would ask him if I need a security squad
     
    • Like
    Reactions: Master1398
    Joined
    Dec 3, 2014
    Messages
    135
    Reaction score
    31
    Fantastic, I have not really played around with the NPC crew yet but that gives me some ideas.
     
    Joined
    Jul 12, 2014
    Messages
    511
    Reaction score
    57
    • Purchased!
    • Legacy Citizen 5
    Now for a finite state engine that starts up a 'real' conversation.
    It seems the framework is there. ;)

    Greets,

    Jan