Test Pluggin: Noooo.... - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: Test Pluggin: Noooo.... (/thread-1381.html) Pages:
1
2
|
Test Pluggin: Noooo.... - Narroo - 02-19-2014 So, I'm trying to write a basic plugin to get a feel for how the plugins work. This is what I've gotten so far, and it doesn't work. PLUGIN = nil function Initialize(Plugin) Plugin:SetName("PluginTest") Plugin:SetVersion(1) -- Hooks cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY, ExplodeHoe) PLUGIN = Plugin -- NOTE: only needed if you want OnDisable() to use Get() name or something like that -- Command Bindings [undefined=undefined] LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) return true end function OnDisable() LOG(PLUGIN:GetName() .. " is shutting down...") end function ExplodeHoe(Player, Entity) local HeldItem = Player:GetEquippedItem(); if (cItemCategory:IsHoe(HeldItem.m_ItemType)) then Player:GetWorld():DoExplosionAt(0,Entity:GetPosX(), Entity:GetPosY(), Entity:GetPosZ(), false, esPlugin) end endNow, what happens is that I get a complaint from the Server Console. It says: [13:38:52] LUA: Plugins/PluginTest/main.lua:23: attempt to index global 'cItemCa tegory' (a nil value) I assume this is because cItemCategory isn't declared anywhere, and nothing is #include'ed. The thing is, I'm just following the example in the API documentation. How do I get this to work? EDIT: Fixed the showcode. (The show code button glitched before and I didn't know the manual tags, so I just rolled with it.) RE: Test Pluggin: Noooo.... - NiLSPACE - 02-19-2014 I think it's ItemCategory:IsHoe not cItemCategory:IsHoe RE: Test Pluggin: Noooo.... - Narroo - 02-19-2014 Okay, that helps. (The API example says to use cItemCategory) But now I have a different error: [14:06:19] LUA: Plugins/PluginTest/main.lua:23: error in function 'IsHoe'. argument #1 is 'table'; 'number' expected. HeldItem.m_ItemType should return a number, so I'm not sure what the problem is. RE: Test Pluggin: Noooo.... - NiLSPACE - 02-19-2014 What does the console say when you put: print(HeldItem.m_ItemType)after local HeldItem = Player:GetEquippedItem() RE: Test Pluggin: Noooo.... - xoft - 02-19-2014 Narroo, please use [ shcode=lua ] and [ /shcode ] when pasting code, so that the forum uses proper highlighter for the code Also, where in the API docs does it say to use cItemCategory? It's probably a bug in the docs, I'd like it fixed. RE: Test Pluggin: Noooo.... - NiLSPACE - 02-19-2014 I think it's in the example code. RE: Test Pluggin: Noooo.... - Narroo - 02-19-2014 (02-19-2014, 07:18 AM)xoft Wrote: Narroo, please use [ shcode=lua ] and [ /shcode ] when pasting code, so that the forum uses proper highlighter for the code It's in the code example on the bottom. (02-19-2014, 05:16 AM)STR_Warrior Wrote: What does the console say when you put:print(HeldItem.m_ItemType)afterlocal HeldItem = Player:GetEquippedItem() It says: userdata: 079C3218 . RE: Test Pluggin: Noooo.... - worktycho - 02-19-2014 Its because IsHoe is a static function not a method. So the correct code would be if (ItemCategory.IsHoe(HeldItem.m_ItemType)) then It seems that the error argument #1 is 'table'; 'whatever' expected often indicates calling a static function as though it was a method. RE: Test Pluggin: Noooo.... - Narroo - 02-19-2014 Okay. I though ":" was the equivalent to C++'s "->". I need to reread Lua's reference manual. Also, I was copying from the API documentation on the ItemCategory page, so that needs to be fixed. Finally, there was another error, I was lacking the "SourceData" parameter which was being left off in the example. Anyways, what's SourceData? The API dump just says "The SourceData parameter is specific to each source type, usually it provides more info about the source.." What does that mean? Why would "DoExplosionAt()" require this? RE: Test Pluggin: Noooo.... - xoft - 02-19-2014 The SourceData specifies what exactly is exploding. If the explosion is from an entity, it is the entity instance. If the explosion is from a bed in the nether, it is a Vector3i with the bed's coordinates. Here's a list: http://mc-server.xoft.cz/LuaAPI/OnExploded.html I know the docs are lacking in this manner, the table should be with the esXXX constants documentation and it should be linked to all of the places where the constants are mentioned; somehow I didn't get around to fixing that. |