• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua CreatureScripts functions like onCombat or onStatsChange

waqmaz

Member
Joined
Jun 17, 2015
Messages
203
Reaction score
11
Hello.
I would like to know how does function params really works. I have some problems.
Lets say we have onCombat function:

Code:
function onCombat(cid, target)

   -- cid = getCreatureTarget(cid)
   -- target = getCreatureTarget(target )

   if isPlayer(target) then
      doCreatureSay(cid, "isPlayer(target)", TALKTYPE_ORANGE_1)
   end

   if isPlayer(cid) then
      doCreatureSay(cid, "isPlayer(cid)", TALKTYPE_ORANGE_1)
   end

   if isMonster(target) then
      doCreatureSay(cid, "isMonster(target)", TALKTYPE_ORANGE_1)
   end

   if isMonster(cid) then
      doCreatureSay(cid, "isMonster(cid)", TALKTYPE_ORANGE_1)
   end

   return true
end

I wanted to check, when which function is activated, but I can't get it.

Can someone tell me how does it work? I read this phorum and I've discovered if monster is attacker then player should be cid and if player is cid, then monster should be attacker (onStatsChange). If player is target, then monster is cid, if monster is cid, then player is target.
Sometimes it doesn't work. Does it depend if event is registered to monster or is not? Please, help. Thanks.
What does really mean that for example monster is cid?
What does mean if player(target) == cid?
Please, help.
 
Last edited:
If you want to determine the value of anything always use these basic concepts in conjunction with the print function.
1. The original value, we will use cid for this demonstration
Code:
print( cid )
2. Its data-type
Code:
print( type(cid) )
We can even combine the 2 together separating each by a comma.
Code:
print( cid, type(cid) )

The reason we use both is sometimes a value passed to print won't print anything to the console, so type lets us know what type of value it holds even if the value is nil, the data-types returned using type are nil, userdata, string, number, table, function and boolean and they are always returned as a string.
 
Back
Top