From 8ad8a25c2f3c46b4793a61ba95ab93af44625960 Mon Sep 17 00:00:00 2001
From: madmaxoft
+ Instead, the cWorld provides access to these objects using callbacks. The plugin provides a + function that is called and receives the object as a parameter; cWorld guarantees that while + the callback is executing, the object will stay valid. If a plugin needs to "remember" the + object outside of the callback, it needs to store the entity ID, blockentity coords or player + name.
++ The following code examples show how to use the callbacks
++ This code teleports player Player to another player named ToName in the same world: +
+-- Player is a cPlayer object +-- ToName is a string +-- World is a cWorld object +World:ForEachPlayer( + function (a_OtherPlayer) + if (a_OtherPlayer:GetName() == ToName) then + Player:TeleportToEntity(a_OtherPlayer); + end +); ++
+ This code fills each furnace in the chunk with 64 coals: +
+-- Player is a cPlayer object +-- World is a cWorld object +World:ForEachFurnaceInChunk(Player:GetChunkX(), Player:GetChunkZ(), + function (a_Furnace) + a_Furnace:SetFuelSlot(cItem(E_ITEM_COAL, 64)); + end +); ++
+ This code teleports all spiders up by 100 blocks: +
+-- World is a cWorld object +World:ForEachEntity( + function (a_Entity) + if not(a_Entity:IsMob()) then + return; + end + local Monster = tolua.cast(a_Entity, "cMonster"); -- Get the cMonster out of cEntity, now that we know the entity represents one. + if (Monster:GetMobType() == cMonster.mtSpider) then + Monster:TeleportToCoords(Monster:GetPosX(), Monster:GetPosY() + 100, Monster:GetPosZ()); + end + end +); ++ ]], + }, + }, -- AdditionalInfo }, TakeDamageInfo =