![]() |
|
attempting to make a plugin to spawn giants - 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: attempting to make a plugin to spawn giants (/thread-3366.html) |
attempting to make a plugin to spawn giants - Code_Blue - 07-14-2021 Hi, I am new to Lua and I wanted to modify the tutorial code a bit to create a plugin to spawn giants (1.12.2). I think I got most of it down, but I am having an issue with two different parts of it. Console Errors: [12:58:58] LUA: Plugins/SpawnGiants/spawngiants.lua:28: attempt to call method 'SpawnMob' (a nil value) [12:58:58] Stack trace: [12:58:58] Plugins/SpawnGiants/spawngiants.lua(28): (no name) [12:58:58] [C](-1): FindAndDoWithPlayer [12:58:58] Plugins/SpawnGiants/spawngiants.lua(35): (no name) [12:58:58] Stack trace end [12:58:58] Error in <attached> calling function <callback>() Code: Code: PLUGIN = nil
function Initialize(Plugin)
Plugin:SetName("GiantSpawn")
Plugin:SetVersion(1)
-- Hooks
PLUGIN = Plugin -- NOTE: only needed if you want OnDisable() to use GetName() or something like that
-- Command Bindings
cPluginManager.BindCommand("/spawngiant", "SpawnGiants.main", SpawnGiant, " ~ Spawn a Giant at someone's location")
LOG("Initialised version " .. Plugin:GetVersion())
return true
end
function SpawnGiant(Split, Player)
if (#Split ~= 2) then
-- Send the proper usage to the player and exit
Player:SendMessage("Usage: /spawngiant [PlayerName]")
return true
end
local CommandSent = false
local GiantSpawnPerson = function(Giantee)
if (Giantee:GetName() == Split[2]) then
Player:SpawnMob(giant)
Player:SendMessageSuccess(Split[2] .. " has been attacked by a giant")
CommandSent = true
return true
end
end
cRoot:Get():FindandDoWithPlayer(Split[2], GiantSpawnPerson)
if not(CommandSent) then
Player:SendMessageFailure:(Split[2] .. " was not found")
end
return true
end
function OnDisable()
LOG("Shutting down...")
endI am new to Lua and new to programming in general. Any help would be appreciated (This is running on a raspberry pi, I am not sure if that makes any difference.) RE: attempting to make a plugin to spawn giants - 12xx12 - 07-14-2021 Hi, The Player doesn't contain a SpawnMob Method. You need to get the world object from the player and call the spawn method from there. Code: Player:GetWorld():SpawnMob(Player:GetPosition(), mtGiant, false)Edit: This wall cause the giant to spawn at the position of the player using the command. If you replace "Player" with "Giantee" you should get your desired result RE: attempting to make a plugin to spawn giants - NiLSPACE - 07-14-2021 Hi, welcome to the forum! The reason it's giving an error is because you're calling 'SpawnMob' on a player object. What you want is the world object, probably the world of the player on which you're trying to spawn a monster on. So this line: Player:SpawnMob(giant) would have to be replaced with something like this: Giantee:GetWorld():SpawnMob(Giantee:GetPosX(), Giantee:GetPosY(), Giantee:GetPosZ(), mtGiant, false); RE: attempting to make a plugin to spawn giants - 12xx12 - 07-14-2021 (07-14-2021, 03:15 AM)NiLSPACE Wrote: Hi, welcome to the forum! Doesn't the SpawnMob method take a vector as a position parameter? RE: attempting to make a plugin to spawn giants - NiLSPACE - 07-14-2021 I thought so as well, but the documentation showed individual coordinates: https://api.cuberite.org/cWorld.html#SpawnMob_1 But perhaps it's out of date. RE: attempting to make a plugin to spawn giants - 12xx12 - 07-14-2021 It should still work. The vector object just pushes three integers and then the API takes just three integers. I don‘t think anyone took the time to add this explicitly RE: attempting to make a plugin to spawn giants - Code_Blue - 07-14-2021 Success! Giant spawned. Thanks for your help everybody! |