Just wondering if we'll ever get a mostly complete scripting reference?
I'm just messing around trying to add items to players inventories, but without a reference I'm left basically just guessing at commands.
Just wondering if we'll ever get a mostly complete scripting reference?
I'm just messing around trying to add items to players inventories, but without a reference I'm left basically just guessing at commands.
Did you see @King Genius's scripting example?
If you look in the code there are some additional examples beyond just area protection in his code, and it gives a lot of the basic hooks.
Otherwise there is a wiki in the works and that will probably have what you are looking for.
I think I'll probably have to wait for the wiki.
I looked through the example script from the IndieDB tutorial, and the Area Protection script...they're good to look through but only provide a small frame of reference since they are trying to accomplish very specific things.
Thanks.
As @Quezax said, we're currently preparing a wiki which contains a full overview of all functions and events The area protection was indeed just a small basic example.
We will give the wiki a higher priority now. Before Steam release, there were not many people playing multiplayer, and even less people using LUA scripts, so we concentrated on other things. But this has changed now with steam. As soon as the serverlist is running (probably with the next update), we start working on the wiki (to get at least the LUA section online).
Awesome. Thanks for the reply.
Can anyone tell me off the top of their head if there are PlayerTerrainDestroy and PlayerTerrainPlace events and what their proper names would be? I am trying to update this AreaProtection example, and it works but it doesn't really help to protect structures if the other players can just dig giant pits under the structures. Also, how to get the location of the old voxel would be cool too.
Yes, the terrain events are:
PlayerTerrainDestroy
(you can access event.player, event.chunkOffsetX, event.chunkOffsetY, event.chunkOffsetZ, event.blockPositionX, event.blockPositionY, event.blockPositionZ)
PlayerTerrainFill
(you can access everything like for PlayerTerrainDestroy, but additionally also event.newBlockID [this is the ID of the stone the player used to fill the terrain]).
Cancelling the events works exactly like for the PlayerBlockDestroy and PlayerBlockPlace events (event:setCancel(true))
To turn chunkoffset and blockposition into a global position, you can use these functions:
Thank you very much! Now to figure out why I am crashing when dealing with the offsets when placing or destroying objects (e.g. the workbench). Almost there!
I'm a little confused by object placement (e.g. workbench). It has chunk offsets, but it doesn't appear to have block positions. I guess that makes sense since they aren't blocks, but when trying to find the workbench position, what would be the alternative to AreaUtils:isPointInArea3D? Or the equivalent to block positions for objects?
The PlayerObjectPlace and PlayerObjectRemove events already provide the worldposition (accessible with event.position.x, event.position.y, event.position.z).
The AreaUtils:isPointInArea3D() accepts different parameters, so for objects you can use
[lua]AreaUtils:isPointInArea3D(event.position, areax, areay, areaz, areasizex, areasizey, areasizez)
--or alternatively, probably you need this function:
AreaUtils:isPointInArea3D(event.position, startChunkpositionX, startChunkpositionY, startChunkpositionZ, startBlockpositionX, startBlockpositionY, startBlockpositionZ, endChunkpositionX, endChunkpositionY, endChunkpositionZ, endBlockpositionX, endBlockpositionY, endBlockpositionZ)
[/lua]
A wiki is really needed Btw., you can add me in Steam, you can always ask a question about a function or event there, in most cases I can answer much faster then^^
Alright thanks. I don't want to be too much of a bother though.
That's absolutely no problem, you can ask as many questions as you want! We are happy to see someone working with the LUA stuff! And without a wiki, it is really not an easy task^^
I'm getting closer. I got "8,0,3,4,56,1" echoed in my server log from where i was hacking away at the dirt in someone else's area. That is the chunk x,y,z and block position x,y,z. Unfortunately the AreaUtils:isPointInArea3D thinks the event chunk offsets and block positions are outside of any area using:
AreaUtils:isPointInArea3D(chunkoffsetx, chunkoffsety, chunkoffsetz, blockpositionx, blockpositiony, blockpositionz, value["startChunkpositionX"], value["startChunkpositionY"], value["startChunkpositionZ"], value["startBlockpositionX"], value["startBlockpositionY"], value["startBlockpositionZ"], value["endChunkpositionX"], value["endChunkpositionY"], value["endChunkpositionZ"], value["endBlockpositionX"], value["endBlockpositionY"], value["endBlockpositionZ"])
The "value" is an element within the areas array. Still, a lot closer than I was!
[LUA][AreaProtection] Terrain:8,0,3,8,56,4, Area: 6,0,1,11,57,15,8,1,3,12,35,12
The values above line up with:
Terrain being destroyed? (these are event children)
chunkoffsetx = 8
chunkoffsety = 0
chunkoffsetz = 3
blockpositionx = 8
blockpositiony = 56
blockpositionz = 4
Area (these have been pre-stored when a player creates an area):
value["startChunkpositionX"] = 6
value["startChunkpositionY"] = 0
value["startChunkpositionZ"] = 1
value["startBlockpositionX"] = 11
value["startBlockpositionY"] = 57
value["startBlockpositionZ"] = 15
value["endChunkpositionX"] = 8
value["endChunkpositionY"] = 1
value["endChunkpositionZ"] = 3
value["endBlockpositionX"] = 12
value["endBlockpositionY"] = 35
value["endBlockpositionZ"] = 12
The big question is, what really do the event variables represent? Is that the terrain block currently being destroyed or something else? From my understanding of the numbers above, they don't fall within the area limits (the block positions anyway), but I am only barely understanding chunk and block positions. I assume that chunks are terrain chunks and block positions are positions within those chunks.
By the way Absalom I fixed spawn.
Thanks!
I forgot to mention, those numbers above were after triggering the "PlayerTerrainDestroy" event.
The big question is, what really do the event variables represent? Is that the terrain block currently being destroyed or something else? From my understanding of the numbers above, they don't fall within the area limits (the block positions anyway), but I am only barely understanding chunk and block positions. I assume that chunks are terrain chunks and block positions are positions within those chunks.
You are right, the blockposition is within a chunk. Chunkoffset is the global offset of a chunk. Chunks have a size of 16x64x16 (x,y,z) blocks.
The area above is outside the range: X and Z are within the area, but Y is at blockposition 56 (chunkoffset * 64 [chunksizey] + 56 == 0 * 64 + 56 == 56), but the area starts at Y blockposition 57 (chunkoffset 0), so 56 < 57 so it's not inside the area.
Don’t have an account yet? Create a new account now and be part of our community!