• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua [TFS 0.3.6] Step-In onMove event?

Sho Ke

New Member
Joined
Jun 9, 2008
Messages
31
Reaction score
1
After some digging around, I found a way to add events upon stepping into or out of certain types of files in the xml file root/data/movements/movements.xml. However, this is only for events bound to certain tiles(granted, the same event can be bound to multiple types of tiles).

What I'm looking for is a generic event that will be called every time the player moves, regardless of the tile the player is moving onto/out of. Does such a thing exist?

Edit: Also, after looking around I can't seem to find an event for when a creature or player dies. Is there an event for that? It's kind of chaotic looking for events without proper documentation to consult first :s


Thanks in advance
-Sho Ke
 
I'm pretty sure there is a way to just set a default moveevent for stepin, but I don't remember exactly how.

As for creature die events. That is in Creaturescripts.
 
Thanks for the reply. Do you remember what the creature die event is called? In creaturescripts, I have an xml file with a few <event>s pointing to the following lua files:
login, guildmotd, mail, reportbug, advancesave, antimagebomb, idle, skullcheck, and spellup.

The scripts folder only has the lua files listed above, and the lib folder contains an empty lua file called creaturescripts.
 
If you are using TFS 0.3/0.4, then you can find all the types in the folder doc, in the file SCRIPTSYSTEM_HELP.

For the death creaturescript you can use type death (function onDeath(cid, corpse, deathList)) or type preparedeath (function onPrepareDeath(cid, deathList)).
preparedeath can be used for example with things that should happen before someone dies, like being teleported, blessings or effects.

You can also use type kill (function onKill(cid, target, lastHit)), when it should have effect on the killer.
 
Thank you for the help! I completely skipped over SCRIPTSYSTEM_HELP when looking through the doc folder.

So I registered both onDeath and onPrepareDeath in creaturescripts.xml like so(inside the <creaturescripts like all of the other events):
HTML:
<event type="preparedeath" name="Prepdeath" event="script" value="prepdeath.lua"/>
<event type="death" name="Death" event="script" value="death.lua"/>


Then, in prepdeath.lua I have:
Code:
function onPrepareDeath(cid, deathList)
   doSendMagicEffect(cid, CONST_ME_MAGIC_RED)
   doBroadcastMessage("test prepdeath")
end
And in death.lua:
Code:
function onDeath(cid, corpse, deathList)
   doSendMagicEffect(cid, CONST_ME_MAGIC_BLUE)
   doBroadcastMessage("test ondeath")
end

However, every time I kill something, both mob or player, none of the effects inside either function trigger. There aren't any errors in the server's console, either(usually if I misspell something or have a syntax error, either the console will show a few errors or the server will crash). Am I missing something?
 
Did you register the name in login.lua?
Code:
registerCreatureEvent(cid, "Prepdeath")
You need to register all creaturescripts except from scripts with type login.
 
Ah, I was unaware of that. Thank you so much!
Also it should be noted that the code I had for onPrepareDeath was incomplete. It seems onPrepareDeath must return true for the character to *actually* die, otherwise the function will just be called indefinitely.

Edit: Out of curiousity, where did you learn all of this?
 
Last edited:
You have to add return true to every Lua script, else the function will return false. It's just that with some creaturescripts types it has a more extreme effect if the function returns false when it shouldn't.
But for example with action scripts, people will get the "You cannot use this object." message or with spells the spell words don't show and it won't have exhaustion or mana cost.

I learned it by doing it alot, I hosted OTs for years and I had to made scripts for them.
I started with editing existing scripts, trying to understand errors and when I understood the basic things, trying to make scripts myself with learning from mistakes and errors.
The files LUA_FUNCTIONS and SCRIPTSYSTEM_HELP are really usefull to know what you can use and also Lua sites and looking at other scripts for examples can be useful to understand things.
 
Back
Top