• 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 returning CID

CoverPower

New Member
Joined
Apr 1, 2013
Messages
19
Reaction score
1
dear developers,

is there any function that returns the CID of the caster?
im creating a spell but the area of the spell have to be based on my current location.

OTHire Beta 0.0.2
OpenTibia Server for Tibia 7.72..

Code:
function setArea(cid)        -- <------- this function doesnt know the CID
    .... --some code
   playerpos = getPlayerPosition(cid)
   .... --some code
   local area = {}
   ..... --some code
   return area
end

local area = createCombatArea(setArea())
setCombatArea(combat, area)  
function onCastSpell(cid, var)
  doCombat(cid, combat, var)

  return true
end

problem here is that i cannot setCobmatArea inside onCastSpell. setCobmatArea "can only be used while loading the script" so theres no way for me to send CID into setArea function. do you have any idea how could i solve this?

SOLVED


Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)
function onGetFormulaValues(cid, level, maglevel)
return -(((maglevel * 1.2) + 25) + (level / 5)), -(((maglevel * 1.2) + 25) + (level / 5)), 0
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
function onCastSpell(cid, var)

local players = {}
players = getSpectators(getPlayerPosition(cid), 10, 10, false)
for index,value in pairs(players) do
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, value)
doCombat(cid, combat, numberToVariant(value))
end

return true
end


[SOLVED]
 
Last edited:
cid holds the value of a creature id, e.g. the creature casting the spell, the cid in your function setArea is just a placeholder and not the the same cid which is gotten from onCastSpell ( it is a parameter ).

If onCastSpell used x instead of cid e.g.
Code:
function onCastSpell(x, var)
and then x was passed to setArea as an argument
Code:
setArea(x)
x would contain the value of the creature id e.g. the creature casting the spell.

Unfortunately combat/conditions must be loaded before you can even consider casting the spell, to get around this you can create a table of combat/condition objects and then access them at cast time.
 
exactly, that cid is not the same. is there any way to get that cid which is used in onCastSpell into my setArea function? something like getCasterCID or anything.. or any way to get around that so i can generate a table of objects i want to attack. because without the cid in setArea i cannot generate a table of objects i want to attack.
 
all area of effect spells already cast based on your location, just look up how the areas are set up in compat.lua or spells.lua in spells lib or wherever they are in ur dist
 
all area of effect spells already cast based on your location, just look up how the areas are set up in compat.lua or spells.lua in spells lib or wherever they are in ur dist
yes, but if i need to compare other players location to mine i cannot work with that only. i need to know my location based on map x,y,z
 
okay heres the code.
i create table of zeroes. then i check every position on site of 16x16 around my creature. if i find a player i change the zero at table to one depending on location. and then i want to cast the spell.
thats why i need my cid. to compare enemy location with my. and i cant do that without knowing my position. and i can know my position only using my cid.

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
--setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -1.92, -0, -3.0, -0)


function setArea(cid)

   local players = {}
   local playerpos = {}
   playerpos = getPlayerPosition(cid)
   local pos = playerpos
   local enemy_pos = {}
   local distance = 7
   local area = {}
   for i=-8, distance, 1 do
     area[i] = {}
     for j=-8, distance, 1 do
       area[i][j] = 0    
     end
   end

   for i=-8, distance, 1 do
     for j=-8, distance, 1 do
       enemy_pos['x'] = pos['x'] + i
       enemy_pos['y'] = pos['y'] + j
       enemy_pos['z'] = pos['z']
       enemy_pos['stackpos'] = pos['stackpos']
  
      
  
       if isPlayer(getThingFromPos(enemy_pos).uid) then
         area[i][j] = 1
         table.insert(players, getThingFromPos(enemy_pos).uid)
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Players UID is: " ..getThingFromPos(enemy_pos).uid)
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your cid is: " ..cid)      
       end
     end
   end
   return area
end





--local area = createCombatArea(setArea())
--setCombatArea(combat, area)

  
function onCastSpell(cid, var)  
   --local area = createCombatArea(setArea(cid))
   setCombatArea(combat, area)
  doCombat(cid, combat, var)

  return true
end
 
so what do you want the spell to do? search the screen around the player to find another player and shoot at it? shoot at only one? shoot at all on screen?
 
cant you make a single target combat, and then in onCastSpell go through entire screen to find players, and execute combat to that player?
if you cant execute single target combat multiple times you can just use
distanceshoot/magiceffect/dotargetcombathealth
 
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)
function onGetFormulaValues(cid, level, maglevel)
  return -(((maglevel * 1.2) + 25) + (level / 5)), -(((maglevel * 1.2) + 25) + (level / 5)), 0
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")   
function onCastSpell(cid, var)   
   
   local players = {}
   players = getSpectators(getPlayerPosition(cid), 10, 10,  false)
   for index,value in pairs(players) do
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, value)    
     doCombat(value, combat, var)
   end   
 
  return true
end

can you tell me why it doesnt do any damage?
 
im pretty sure getSpecs~ returns creature ids, so players[1] would be player 1 etc, so use a for i=1,#spectators,1 do i think
 
also i think doCombats first argument is the player dmg is coming from, not the target, i think the target is contained in var

edit:
if you cant get it to work, you can also use
doTargetCombatHealth(cid, target, type, min, max, effect)
doTargetCombatMana(cid, target, min, max, effect)
 
thank you mate. solved works.

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_EXPLOSIONAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)
function onGetFormulaValues(cid, level, maglevel)
return -(((maglevel * 1.2) + 25) + (level / 5)), -(((maglevel * 1.2) + 25) + (level / 5)), 0
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
function onCastSpell(cid, var)

local players = {}
players = getSpectators(getPlayerPosition(cid), 10, 10, false)
for index,value in pairs(players) do
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, value)
doCombat(cid, combat, numberToVariant(value))
end

return true
end


[SOLVED]
 
Back
Top