Ok, considering the topic of this thread is inventory we've gotten off track, please make a new topic if you have any more questions.. it's just so it's easier for other people to find answers during searches.

But here is the answer - I think you want to know how to "spawn" a coin.
Don't replace the current entities graphic to look like a coin, it's cleaner to just make a coin object.
Check worlds/RT_TreeWorld/script/static/ent_brick.lua
When you hit this with the players head, it needs to make a bunch of 'brick chunks' to fly around. These are spawned entities, look at this function it has:
Code:
function AddDebris(vPos, vForce)
ent = CreateEntity(this:GetMap(), this:GetPos()+vPos, "misc/ent_brick_chunk.lua");
ent:AddForce(vForce);
ent:SetPersistent(false);
Schedule(800, ent:GetID(), "this:GetBrainManager():Add(\"FadeOutAndDelete\",'');");
end
This creates an entity and gives it the "misc/ent_brick_chunk.lua" script. (you could change this to the coin script and it would spawn a coin instead)
The parameters are a position offset and velocity so the chunks start moving.
The FadeAndDelete brain kills the chunks after a bit.
Notice it's making changes to the newly created entity (like with ent:SetPersistent(false); ) - you can also use ent:RunFunction("SomeFunc", optionalParms, etc); to run a function inside its .lua script/namespace.
The functions can return values etc, so this provides a way to communicate with other entities if you need to.
It actually calls it like this:
Code:
function Crumble()
//Bust up this brick
this:SetDeleteFlag(true);
GetSoundManager:Play("audio/mario/smash.wav");
//create the particles that fly off
AddDebris(Vector2(0,0), Vector2(-2,-2));
AddDebris(Vector2(20,0), Vector2(2,-2));
AddDebris(Vector2(0,20), Vector2(-1,-2));
AddDebris(Vector2(20,20), Vector2(1,-2));
end
function OnDamage(normal, depth, enemy, damage, userVar, projectile)
Crumble();
end
So you see it makes four chunks and makes them fly off in different directions.
These same concepts work fine for spawning anything.
Bookmarks