Jump to content

[REQ] Sector Callback Example


GhoStalker

Recommended Posts

Calling all experienced modders. I have been trying to figure out how to hook Sector onPlayerEntered. I am looking to have it executed on the server.

 

I have been playing with it, but I haven't had any luck. I am new to LUA and have some cool mod ideas. I am mainly confused on where should I be defining the hook. I tried to place it in server.lua and several other spots.

 

Not looking for a 100% example, but some tips on where I should be putting the code and maybe file structure.

 

Thanks in advanced for any input.

Link to comment
Share on other sites

Not looking for a 100% example, but some tips on where I should be putting the code and maybe file structure.

Too bad: I recommend you to look into my mods for some examples  :P

Edit: For an example on how to use callbacks, I recommend looking at the server.lua and player/asteroidMover.lua in the moveAsteroids mod[mOS], since their code base is very small and might be providing what you need.

 

but now for some real talk:

You should only attach Callbacks to loaded objects. Of the 1,000,000 Sectors ingame only those where Players are in are loaded.

 

Try using: "onSectorEntered"-Callback from player or Entities.

I recommend using the player one. Because if you get an callback to an unloaded Entity the game freezes.

 

Player(playerIndex):registerCallback("onSectorEntered", "methodnameWithoutBrackets")

 

your receiver method gets 3 Parameters:

 

methodnameWithoutBrackets(playerIndex, x, y) 

playerIndex: selfexplaining

x: the x Coordinate of the sectory the Player(playerIndex) just entered

y: the y Coordinate of the sectory the Player(playerIndex) just entered

 

Don't forget to unregister your Hooks as soon as a Player logs off.

Player(playerIndex):unregisterCallback("onSectorEntered", "methodnameWithoutBrackets")

Using the

Server():registerCallback("onPlayerLogOff", "onPlayerLogOffMethod")

 

 

Not looking for a 100% example, but some tips on where I should be putting the code and maybe file structure.

If you need to watch every Sector entered:

You should add your script to the player in the "onPlayerLogIn"-Method in server.lua.

Your file, since it runs on a player, should go into /scripts/player/. But that is not mandatory.

 

If this all didn't help you much. I suggest you tell us about your

cool mod ideas.

So we can help you with your specific problems.

 

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
×
×
  • Create New...