Jump to content

Need a tip on making calling custom functions


Recommended Posts

Here's the thing:

I've wrote some cool functions that would make my life on the console a lot easier. The problem is that I'm not sure how to actually apply them to the game as a mod, all I can do right now is trow the functions on some game file like consolecommands.lua and then I can call them like any o ther.

 

What I need to know is how to  implement them to a 'standalone' mod.

Thanks in advance.

Link to comment
Share on other sites

You mean like putting them in the modmain.lua? What kind of functions do you mean?

Also, if you wanted, you could just keep them in consolecommands.lua and put that copy in your mod folder in a scripts folder, it will overwrite the currently existing version with your version while the mod is enabled

Link to comment
Share on other sites

You mean like putting them in the modmain.lua? What kind of functions do you mean?

Also, if you wanted, you could just keep them in consolecommands.lua and put that copy in your mod folder in a scripts folder, it will overwrite the currently existing version with your version while the mod is enabled

 

That's what I'm doing right now, but it's quite annoying to have to restore that file after each update on all servers... even especially when I feel like changing the functions.

What I need is to make a mod so I can load them without invading the game files.

The functions are just functions. all I want to do is call them at will.

Link to comment
Share on other sites

@expert975,

 

In modmain:

GLOBAL.c_mycom = function()	print("Hello")endGLOBAL.c_kill = function(player)	player.components.health:Kill()end

Now in console you can write

- c_mycom() and it will print "Hello".

- c_kill(ThePlayer), c_kill(AllPlayers[2]) to kill somebody

 

This is for server side commands, or for when you host a game directly.

If you put them on the server, and you are a client, then you can send

Remote: c_mycom()

and it will run on the server.

 

Even for the server, this should be specified client side mod, so it doesn't appear on the list.

 

 

If you want remote custom commands, you send strings to the server:

GLOBAL.c_mycom = function()	local x, y, z = TheSim:ProjectScreenPos(TheSim:GetPosition())	local fnstr = "print(\"hello\")"	GLOBAL.TheNet:SendRemoteExecute(fnstr, x, z)endGLOBAL.c_kill = function(playerstr)	local x, y, z = TheSim:ProjectScreenPos(TheSim:GetPosition())	local fnstr = playerstr..".components.health:Kill()"	GLOBAL.TheNet:SendRemoteExecute(fnstr, x, z)end

Now running c_mycom() will send the string of what c_mycom does and it will run in the server.

 

This way you can have a client side mod and have server ready commands in multiple servers.

Link to comment
Share on other sites

@DarkXero, Thank you very much!

 

I can call the print function with no problems, but seems like I can't use local variables in the same way I did before for some reason.

 

The traceback says "attempt to call global 'GetEnabledModsModInfoDetails' (a nil value)" on this line:

 

local mods = GetEnabledModsModInfoDetails()
 

Maybe the problem is not actually on local variables, but on something to do with the function I'm calling and this GLOBAL thingy. How do we work around that?

Edited by expert975
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...