Lua chatbox

The Lua scripting language allows you to give your plugin more advanced features.

Moderator: Plugin Moderators

Jeremiah Stephens
Inhabitant of a Megacity
Reactions:
Posts: 208
Joined: Thu Jan 30, 2020 16:56
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#141

Post by Jeremiah Stephens »

Screenshot_20201022-205028_TheoTown.png
Screenshot_20201022-205028_TheoTown.png (31.95 KiB) Viewed 2786 times
Check out my TheoTown YouTube videos (and subscribe): https://www.youtube.com/playlist?list=P ... wCvFdgyiTk
Show
Warning: do not tap or click "Show"
Just kidding, join my discord server: http://discord.gg/hA5EVazhCC

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 671
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#142

Post by Hadestia »

Check Gui Compendium @Jeremiah Stephens
𝕳𝕬𝕯𝕰𝕾𝕿𝕴𝕬
Age of Sail CEO
“TheoTown Philippine Council”
Age of Sail @ TPC discord:https://discord.gg/baMkPTc7nZ

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 671
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#143

Post by Hadestia »

@Lobby is there any Runtime modules that detects user inputs in all Textfields?

im making a text sensor that will censored all inappropriate words that the user used, this will be nice addon for the game if you want too :)
𝕳𝕬𝕯𝕰𝕾𝕿𝕴𝕬
Age of Sail CEO
“TheoTown Philippine Council”
Age of Sail @ TPC discord:https://discord.gg/baMkPTc7nZ

User avatar
Lobby
Developer
Reactions:
Posts: 3637
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta

Platform

Re: Lua chatbox

#144

Post by Lobby »

I'm afraid there's no mechanism to do that.
=^._.^= ∫

User avatar
ian`
Supporter
Reactions:
Posts: 110
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#145

Post by ian` »

i think you can use string.gmatch and table of the "words" you want to censor.
:bc

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 671
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#146

Post by Hadestia »

ian` wrote:
Wed Nov 18, 2020 12:24
i think you can use string.gmatch and table of the "words" you want to censor.
I used string.gsub and works but can only censor Author name and City name :/
𝕳𝕬𝕯𝕰𝕾𝕿𝕴𝕬
Age of Sail CEO
“TheoTown Philippine Council”
Age of Sail @ TPC discord:https://discord.gg/baMkPTc7nZ

User avatar
CERRERA
Small-town resident
Reactions:
Posts: 30
Joined: Sat Jan 25, 2020 6:19
Location: Philippines
Plugins: Show
Version: Beta
Contact:

Platform

Re: Lua chatbox

#147

Post by CERRERA »

Can i use lua to make fence animation?
Everything you can imagine is real

User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2137
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#148

Post by KINGTUT10101 »

I'm sorry for bother you Lua experts lately, but could you tell me how I could get a sidebar button to open the building tool for an item with the ID "test.kt101"? I haven't been able to find any documentation or examples of it.

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 671
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#149

Post by Hadestia »

KINGTUT10101 wrote:
Wed Dec 23, 2020 23:33
I'm sorry for bother you Lua experts lately, but could you tell me how I could get a sidebar button to open the building tool for an item with the ID test.kt101"? I haven't been able to find any documentation or examples of it.
Here refering from GUI compedium

Code: Select all    Reset

function script:buildCityGUI() -- Let's append the button to the sidebar line local sidebar = GUI.get('sidebarLine') local size = sidebar:getFirstPart():getChild(2):getWidth() local button = sidebar:getFirstPart():addButton{ width = size, height = size, icon = Icon.OK, frameDefault = Icon.NP_BLUE_BUTTON, frameDown = Icon.NP_BLUE_BUTTON_PRESSED, onClick = function() City.createDraftDrawer("test.kt101")end } end
Interactive Lua editor
Run
𝕳𝕬𝕯𝕰𝕾𝕿𝕴𝕬
Age of Sail CEO
“TheoTown Philippine Council”
Age of Sail @ TPC discord:https://discord.gg/baMkPTc7nZ

User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2137
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#150

Post by KINGTUT10101 »

Gosh darn undocumented functions. Thank you for the help.

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 671
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#151

Post by Hadestia »

KINGTUT10101 wrote:
Sat Dec 26, 2020 0:42
Gosh darn undocumented functions. Thank you for the help.
i forgot you need first to get the draft of the building by using Draft.getDraft("")
𝕳𝕬𝕯𝕰𝕾𝕿𝕴𝕬
Age of Sail CEO
“TheoTown Philippine Council”
Age of Sail @ TPC discord:https://discord.gg/baMkPTc7nZ

User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2137
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#152

Post by KINGTUT10101 »

Code: Select all

function script:buildCityGUI()
  -- Let's append the button to the sidebar line
  local sidebar = GUI.get('sidebarLine')
  local size = sidebar:getFirstPart():getChild(2):getWidth()
  local button = sidebar:getFirstPart():addButton{
    width = size,
    height = size,
    icon = Icon.BIGBIGBIG_MAP,
    frameDefault = Icon.NP_BLUE_BUTTON,
    frameDown = Icon.NP_BLUE_BUTTON_PRESSED,
    onClick = function() City.createDraftDrawer(Draft.getDraft("AreaTool.kt101"))end
  }
end
Should this work? I tried it in my project, but it didn't open the building tool after I pressed the button like I was hoping it would.

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 671
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#153

Post by Hadestia »

KINGTUT10101 wrote:
Wed Dec 30, 2020 2:34

Code: Select all

function script:buildCityGUI()
  -- Let's append the button to the sidebar line
  local sidebar = GUI.get('sidebarLine')
  local size = sidebar:getFirstPart():getChild(2):getWidth()
  local button = sidebar:getFirstPart():addButton{
    width = size,
    height = size,
    icon = Icon.BIGBIGBIG_MAP,
    frameDefault = Icon.NP_BLUE_BUTTON,
    frameDown = Icon.NP_BLUE_BUTTON_PRESSED,
    onClick = function() City.createDraftDrawer(Draft.getDraft("AreaTool.kt101"))end
  }
end
Should this work? I tried it in my project, but it didn't open the building tool after I pressed the button like I was hoping it would.
Ive done this before maybe try to remove the Draft.getDraft()
𝕳𝕬𝕯𝕰𝕾𝕿𝕴𝕬
Age of Sail CEO
“TheoTown Philippine Council”
Age of Sail @ TPC discord:https://discord.gg/baMkPTc7nZ

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 671
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#154

Post by Hadestia »

:76: one more thing it can't open Draft that was hidden from building tool (hidden:true) unless you gonna move it to hidden categories
𝕳𝕬𝕯𝕰𝕾𝕿𝕴𝕬
Age of Sail CEO
“TheoTown Philippine Council”
Age of Sail @ TPC discord:https://discord.gg/baMkPTc7nZ

User avatar
ian`
Supporter
Reactions:
Posts: 110
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#155

Post by ian` »

You forgot to add .select() after draft drawer.

Code: Select all

City.createaDraftDrawer(draft).select()
:bc

User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2137
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#156

Post by KINGTUT10101 »

That worked! Thanks to you both.

User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2137
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#157

Post by KINGTUT10101 »

I think I found a bug or maybe an oversight in my coding. I am using that function to open the building tool when a sidebar button is pressed, but it creates multiple instances of the item in the recent tab for every time I push the button:
image.png
Oddly enough, these extra instances will disappear after the GUI is refreshed. Is there a way I could fix this?

User avatar
ian`
Supporter
Reactions:
Posts: 110
Joined: Sat Apr 04, 2020 17:36
Location: Indonesien
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua chatbox

#158

Post by ian` »

KINGTUT10101 wrote:
Thu Dec 31, 2020 1:09
I think I found a bug or maybe an oversight in my coding. I am using that function to open the building tool when a sidebar button is pressed, but it creates multiple instances of the item in the recent tab for every time I push the button:
image.png
Oddly enough, these extra instances will disappear after the GUI is refreshed. Is there a way I could fix this?
It is. I just realized that thing happen on my plugin (the sidebar small button). I thought it no problem because there are not multiple build mode.

To prevent that, you can try this code

Code: Select all

if City.createDraftDrawer(draft):getHistory()[1] ~= selectId then
   City.createDraftDrawer(selectDraft).select()
 end
If that code not work, try to make local var of the history.
:bc

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 671
Joined: Mon Jul 17, 2017 16:16
Location: Philippines
Plugins: Show

Platform

Plugin Creator

Re: Lua chatbox

#159

Post by Hadestia »

ian` wrote:
Thu Dec 31, 2020 11:40
KINGTUT10101 wrote:
Thu Dec 31, 2020 1:09
I think I found a bug or maybe an oversight in my coding. I am using that function to open the building tool when a sidebar button is pressed, but it creates multiple instances of the item in the recent tab for every time I push the button:
image.png
Oddly enough, these extra instances will disappear after the GUI is refreshed. Is there a way I could fix this?
It is. I just realized that thing happen on my plugin (the sidebar small button). I thought it no problem because there are not multiple build mode.

To prevent that, you can try this code

Code: Select all

if City.createDraftDrawer(draft):getHistory()[1] ~= selectId then
   City.createDraftDrawer(selectDraft).select()
 end
If that code not work, try to make local var of the history.
i think these will not work if there is already previous history
𝕳𝕬𝕯𝕰𝕾𝕿𝕴𝕬
Age of Sail CEO
“TheoTown Philippine Council”
Age of Sail @ TPC discord:https://discord.gg/baMkPTc7nZ

User avatar
KINGTUT10101
1,000,000 inhabitants
Reactions:
Posts: 2137
Joined: Thu Jul 07, 2016 22:50
Location: 'Merica
Plugins: Show
Version: Beta
Contact:

Platform

Plugin Creator

Re: Lua chatbox

#160

Post by KINGTUT10101 »

ian` wrote:
Thu Dec 31, 2020 11:40
KINGTUT10101 wrote:
Thu Dec 31, 2020 1:09
I think I found a bug or maybe an oversight in my coding. I am using that function to open the building tool when a sidebar button is pressed, but it creates multiple instances of the item in the recent tab for every time I push the button:
image.png
Oddly enough, these extra instances will disappear after the GUI is refreshed. Is there a way I could fix this?
It is. I just realized that thing happen on my plugin (the sidebar small button). I thought it no problem because there are not multiple build mode.

To prevent that, you can try this code

Code: Select all

if City.createDraftDrawer(draft):getHistory()[1] ~= selectId then
   City.createDraftDrawer(selectDraft).select()
 end
If that code not work, try to make local var of the history.
Unfortunately, it didn't seem to work for me. I did notice something though. One odd quirk about these multiple instances is that getHistory() ignores the extra ones, even if they fill the menu.

Post Reply Previous topicNext topic

Return to “Lua Scripting”