TUTORIAL - Creating your first server + savePos script

Need advices or help troubleshooting? Ask for help here.
Karm
Posts: 3
Joined: October 12th, 2018, 7:30 am

TUTORIAL - Creating your first server + savePos script

Post by Karm » October 16th, 2018, 4:42 pm

Hi!
I have decided to do this tutorial for newbies and for those who like programming and who want to experiment with this great game. In this tutorial we will do:
- Download the server.
- Write our first script.
- Test it at game.

First of all, you need to download the server going to the Downloads section in this forum http://forum.iv-mp.eu/viewforum.php?f=1 ... 176cfabc62:
Image

Here, click in Downloads:
Image

And we select the last version of the server. In this case, Beta 1.0 - Patch 5.
Image

After download it, we create a folder for store the server. I create the folder C:/IV-MP Server
Image

Unzip the content of the server at folder.
Image

For run the server, we execute IVMP Lua.exe
Image

But first, we are going to create our first script. At filterscripts folder, we create a file called savePos.lua, a script for save our position at the game typing /savepos at chat.
Image

We will write this code at file. This script read the commands and if we type /savepos save the spawn position at positions.txt and shows a message for the player. You have more info at script comments.:

Code: Select all

-- http://lua-users.org/wiki/CommonFunctions
-- remove trailing and leading whitespace from string.
-- http://en.wikipedia.org/wiki/Trim_(programming)
function trim(s)
  -- from PiL2 20.4
  return (s:gsub("^%s*(.-)%s*$", "%1"))
end

function commandProcessor(playerid, text)
	-- Remove whitespaces from input text
	local command = trim(text)
	if(command == "/savepos") then
		-- Gets player position
		local x, y, z = getPlayerPos(playerid)
	
		-- https://www.tutorialspoint.com/lua/lua_file_io.htm
		-- Opens a file in append mode
		file = io.open("positions.txt", "a")

		-- sets the default output file as positions.txt
		io.output(file)

		-- appends the player command info to the last line of the file
		io.write("setPlayerPos("..x..", "..y..", "..z..")\n")

		-- closes the open file
		io.close(file)
		
		sendPlayerMsg(playerid, "Position saved!: x: "..x..", y: "..y..", z: "..z..")", 0xFFFF00FF)
	end	
end
registerEvent("commandProcessor", "onPlayerCommand")
And in main.lua (at server main folder), we will add the line. All script we want to use must be loaded here:

Code: Select all

loadScript("savePos")
Image

OK, let's try the script! Run your server (close first if it was open) and connect with your client.
Image

When you be in, press T for write at chat and type /savepos:
Image

If all was fine, we will read the position info:
Image

And we will have the info at positions.txt:
Image

You can use this command for store spawn positions.

That's all. Do you need some help at any point?
If you liked the tutorial and you want more tell me at comments.
See you soon!!

SamyrCastello
Posts: 21
Joined: January 21st, 2018, 12:55 am

Re: TUTORIAL - Creating your first server + savePos script

Post by SamyrCastello » October 25th, 2018, 10:18 pm

i cant enter in my server Connection Attempt Failed

Karm
Posts: 3
Joined: October 12th, 2018, 7:30 am

Re: TUTORIAL - Creating your first server + savePos script

Post by Karm » October 27th, 2018, 6:50 am

Hi SamyrCastello,
can you post a image capture of the error?

SamyrCastello
Posts: 21
Joined: January 21st, 2018, 12:55 am

Re: TUTORIAL - Creating your first server + savePos script

Post by SamyrCastello » October 27th, 2018, 5:12 pm

Server in Masterlist Image

SamyrCastello
Posts: 21
Joined: January 21st, 2018, 12:55 am

Re: TUTORIAL - Creating your first server + savePos script

Post by SamyrCastello » October 27th, 2018, 5:18 pm

see i cant connect on my server

Image

WuskieFTW
Site Admin
Posts: 99
Joined: July 29th, 2017, 4:04 pm
Location: Chicago
Contact:

Re: TUTORIAL - Creating your first server + savePos script

Post by WuskieFTW » October 28th, 2018, 7:50 pm

It's impossible to connect to a local host using IP, click on "Direct" instead and select your IPV4.

SamyrCastello
Posts: 21
Joined: January 21st, 2018, 12:55 am

Re: TUTORIAL - Creating your first server + savePos script

Post by SamyrCastello » October 29th, 2018, 8:50 am

problem solved I changed the port in config.cfg and the router now i can connect thanks for the attention and help :D

cortes
Posts: 3
Joined: March 25th, 2019, 10:11 am

Re: TUTORIAL - Creating your first server + savePos script

Post by cortes » March 25th, 2019, 10:56 am

I did everything but gave this error please help me to create my dedicated server Utilis: script loaded: rcon
Utilis: script loaded: playerSpawn
Utilis: script loaded: carSpawning
Utilis: script loaded: weapons
...wnloads\Beta-1.0 Patch 9\/filterscripts/scriptLoader.lua:5: module 'filterscripts/savePos' not found:
no field package.preload['filterscripts/savePos']
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\lua\filterscripts/savePos.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\lua\filterscripts/savePos\init.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\filterscripts/savePos.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\filterscripts/savePos\init.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\..\share\lua\5.3\filterscripts/savePos.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\..\share\lua\5.3\filterscripts/savePos\init.lua'
no file '.\filterscripts/savePos.lua'
no file '.\filterscripts/savePos\init.lua'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\filterscripts/savePos.dll'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\..\lib\lua\5.3\filterscripts/savePos.dll'
no file 'C:\Users\corte\Downloads\Beta-1.0 Patch 9\loadall.dll'
no file '.\filterscripts/savePos.dll'
Player niko(1) credentials arrived

ÉrrePê
Posts: 1
Joined: November 19th, 2020, 6:50 pm

Re: TUTORIAL - Creating your first server + savePos script

Post by ÉrrePê » November 20th, 2020, 2:13 pm

Hello,

I'm trying to create a server and I'm having some troubles.

If someone can give me a hand, it would be really awesome!

Thank you !!

User avatar
Vittorio
Posts: 5
Joined: January 1st, 2018, 6:30 am

Re: TUTORIAL - Creating your first server + savePos script

Post by Vittorio » December 6th, 2020, 3:22 pm

ÉrrePê wrote: November 20th, 2020, 2:13 pm Hello,

I'm trying to create a server and I'm having some troubles.

If someone can give me a hand, it would be really awesome!

Thank you !!
Certainly. If you could join our Discord server to get faster, more effective help, I am gladly awaiting you there: https://discord.gg/wsqf9wH

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest