• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

[Mod] Random Item Stats

item.cpp
Code:
		case ATTR_HITCHANCE:
		{
			int32_t hitChance;
			if(!propStream.GET_ULONG((uint32_t&)hitChance))
				return ATTR_READ_ERROR;

			setAttribute("hitchance", hitChance);
			break;
		}

[B][COLOR="#FF0000"]		case ATTR_SHOOTRANGE:
		{
			int32_t shootRange;
			if(!propStream.GET_ULONG((uint32_t&)shootRange))
				return ATTR_READ_ERROR;

			setAttribute("shootrange", shootRange);
			break;
		}[/COLOR][/B]
weapons.cpp
Code:
	if(it.weaponType == WEAPON_AMMO)
		range = player->getShootRange();
[B][COLOR="#FF0000"]	else if(it.weaponType == WEAPON_WAND && player->getWeapon())
		range = player->getWeapon()->getShootRange();[/COLOR][/B]
	else
		range = it.shootRange;
Cyko, it seems now that a sorcerer can't wield a bow. My server just freeze and no errors ;/

EDIT: FIXED!
 
Last edited:
item.cpp
Code:
		case ATTR_HITCHANCE:
		{
			int32_t hitChance;
			if(!propStream.GET_ULONG((uint32_t&)hitChance))
				return ATTR_READ_ERROR;

			setAttribute("hitchance", hitChance);
			break;
		}

[B][COLOR="#FF0000"]		case ATTR_SHOOTRANGE:
		{
			int32_t shootRange;
			if(!propStream.GET_ULONG((uint32_t&)shootRange))
				return ATTR_READ_ERROR;

			setAttribute("shootrange", shootRange);
			break;
		}[/COLOR][/B]
weapons.cpp
Code:
	if(it.weaponType == WEAPON_AMMO)
		range = player->getShootRange();
[B][COLOR="#FF0000"]	else if(it.weaponType == WEAPON_WAND && player->getWeapon())
		range = player->getWeapon()->getShootRange();[/COLOR][/B]
	else
		range = it.shootRange;

So we have to add this to our source? Cause when I've tryed it won't rebuild the compilation if I add this. (or is this just for some people to add?)


EDIT: Never mind is cause in my rev is getLong((uint32_t&) instead of GET_ULONG((uint32_t&) =) Thanks for this release

One more thing, on the weapon.cpp file I get when rebuilding in weapons.cpp I get:

no matching function for call to 'Player::getWeapon()'
candidates are: Item* Player::getWeapon(bool)

What do I need to replace? (Using TFS.4)
 
Last edited:
player->getWeapon() to player->getWeapon(false), if you haven't figured
 
Cykotitan, there is a bug! :D since we disable it to not show any message at config.lua, the default value is to show for both player and party, but seems like your script only shows for who killed the monster, but if people are in party, others members can't see any message =/
 
Dude ur friggin awesome, your powers are endless! But, what if the monster doesnt drop any piece of set or weapon? Just cash.. What happens? Adds attack speed to cash? :eek: Lol

Edit: Do i need to source edit? If yes, i wont be able to add the script to my ot coz i dunno how to do that with a naxedot 8.6..
 
Dude ur friggin awesome, your powers are endless! But, what if the monster doesnt drop any piece of set or weapon? Just cash.. What happens? Adds attack speed to cash? :eek: Lol

Edit: Do i need to source edit? If yes, i wont be able to add the script to my ot coz i dunno how to do that with a naxedot 8.6..


Only for the Shootrange do you need source edits. Up, there are the additions.
 
I dunno how to source edit :'( i got sources but.. How do i source edit..
 
I won't use this mod for everything cuz players don't need "epic mace" and leather armor with knight armor's arm.
Hovever, I still want to use this mod for stronger creatures and bosses. Cuz mod is a bit large idk where I should put "if" so I'm asking:
how to enable this mod only for few creatures?
something like:
creatures = {"Demon", "Plaguesmith", "Nightmare", "Juggernaut", "Hellhound", "Diabolic Imp", "Grim Reaper", "Hellspawn", "Ushuriel", "Madareth", "Annihilon", "Latrivan", "Gorgoldan", "Zugurosh", "Hellgorak", "Apocalypse", "Verminor", "Infernatil", "Bazir", "Tarafiel", "Pumin", "Ashfalor", "Orshabaal", "Ferumbras", "Zoralurk", "Ghazbaran", "Morgaroth", "Massacre", "Mr. Punish", "Handmaiden", "Dracola", "The Plasmother", "The Imperor", "Coutness Sorrow"}

if( (damage == true or bit.band(flags, 1) == 1) and isMonster(target) and isMonster(creatures) )then -- idk what should I add here
 
It spams the script in my .exe. Im using rev 3777 for 8.6 :p
2egh9px.png
 
Maybe time for any update?

Post bugs and stuff here so they can get resolved asap
1. colour should be modified for newer versions unless 9.x won't be able to print all letters from animated text.
eg.
Lua:
color = 66, -- color of 'RARE' text
messagecolor = 22, -- color of 'RARE' non-animated text
messagetype = normal --normal or any letter
...
if messagetype == normal then
doPlayerSendTextMessage(cid,messagecolor,"....")
else
doSendAnimatedText(pos, ...color)
end

2. Is that really hard to add containers support?
3. Should be in config also:
doSendMagicEffect(pos, config.effect)
instead of
doSendMagicEffect(pos, CONST_ME_MAGIC_GREEN)
4. As I wrote in post above

I won't use this mod for everything cuz players don't need "epic mace" and leather armor with knight armor's arm.
Hovever, I still want to use this mod for stronger creatures and bosses. Cuz mod is a bit large idk where I should put "if" so I'm asking:
how to enable this mod only for few creatures?
something like:
creatures = {"Demon", "Plaguesmith", "Nightmare", "Juggernaut", "Hellhound", "Diabolic Imp", "Grim Reaper", "Hellspawn", "Ushuriel", "Madareth", "Annihilon", "Latrivan", "Gorgoldan", "Zugurosh", "Hellgorak", "Apocalypse", "Verminor", "Infernatil", "Bazir", "Tarafiel", "Pumin", "Ashfalor", "Orshabaal", "Ferumbras", "Zoralurk", "Ghazbaran", "Morgaroth", "Massacre", "Mr. Punish", "Handmaiden", "Dracola", "The Plasmother", "The Imperor", "Coutness Sorrow"}

if( (damage == true or bit.band(flags, 1) == 1) and isMonster(target) and isMonster(creatures) )then -- idk what should I add here
 
TFS 0.4 CLIENT 8.71
WORK! but spam on my server and verry lagger
Code:
[12:40:48.191]                                                  ( table.find(n.t                                                                                                                               ypes, DISTANCE) and f.weaponType == WEAPON_DIST and f.ammoType ~= 0 ) or
[12:40:48.191]                                                  ( table.find(n.t                                                                                                                               ypes, ARMOR) and f.armor ~= 0 and f.wieldPosition ~= CONST_SLOT_NECKLACE ) or
[12:40:48.191]                                                  ( table.find(n.t                                                                                                                               ypes, SHIELD) and f.defense ~= 0 and f.weaponType == WEAPON_SHIELD ) or
[12:40:48.191]                                                  ( table.find(n.t                                                                                                                               ypes, WAND) and f.weaponType == WEAPON_WAND ) or
[12:40:48.191]                                                  ( table.find(n.t                                                                                                                               ypes, DURATION_RING) and f.wieldPosition == CONST_SLOT_RING and f.transformEquip                                                                                                                               To ~= 0 ) or
[12:40:48.191]                                                  ( table.find(n.t                                                                                                                               ypes, CHARGES) and table.find({CONST_SLOT_RING, CONST_SLOT_NECKLACE}, f.wieldPos                                                                                                                               ition) and f.charges ~= 0 )
[12:40:48.191]                                          ) )then
[12:40:48.191]                                                  table.insert(cur                                                                                                                               , m)
[12:40:48.191]                                          end
[12:40:48.191]                                  end
[12:40:48.192]
[12:40:48.192]                                  if( #cur ~= 0 )then
[12:40:48.192]                                          local n = cur[math.rando                                                                                                                               m(#cur)]
[12:40:48.192]                                          table.insert(used, n)
[12:40:48.192]
[12:40:48.192]                                          n = attr[n]
[12:40:48.192]                                          local percent, new, tmp                                                                                                                                = math.random(n.percent[1] + (v.extra[1] or 0), n.percent[2] + (v.extra[2] or 0)                                                                                                                               )
[12:40:48.192]                                          -- hacks
[12:40:48.192]                                          if( n.attr == 'duration'                                                                                                                                )then
[12:40:48.192]                                                  tmp = getItemInf                                                                                                                               o(f.transformEquipTo)
[12:40:48.192]                                                  if tmp.transform                                                                                                                               DeEquipTo ~= item then
[12:40:48.192]                                                          break
[12:40:48.192]                                                  end
[12:40:48.192]                                                  new = round( tmp                                                                                                                               .decayTime * (1 + percent / 100) * 1000 )
[12:40:48.192]                                          elseif( n.attr == 'attac                                                                                                                               kSpeed' )then
[12:40:48.192]                                                  new = round( voc                                                                                                                               ation_base_attackspeed / (1 + percent / 100) )
[12:40:48.192]                                          elseif( n.attr == 'hitCh                                                                                                                               ance' ) then
[12:40:48.192]                                                  new = round(
[12:40:48.192]                                                          f.hitCha                                                                                                                               nce == -1 and
[12:40:48.192]                                                                 p                                                                                                                               ercent
[12:40:48.192]                                                          or
[12:40:48.192]                                                                 f                                                                                                                               .hitChance * (1 + percent / 100)
[12:40:48.192]                                                  )
[12:40:48.192]                                          else
[12:40:48.192]                                                  new = round(
[12:40:48.192]                                                          n.base a                                                                                                                               nd
[12:40:48.192]                                                                 f                                                                                                                               [n['attr']] + f[n['base']] * (percent / 100)
[12:40:48.192]                                                          or
[12:40:48.192]                                                                 f                                                                                                                               [n['attr']] * (1 + percent / 100)
[12:40:48.192]                                                  )
[12:40:48.192]
[12:40:48.192]                                                  if( new == f[n[n                                                                                                                               .base and 'base' or 'attr']] )then -- no improvement
[12:40:48.192]                                                          break
[12:40:48.192]                                                  end
[12:40:48.192]                                          end
[12:40:48.192]
[12:40:48.192]                                          doItemSetAttribute(tmpIt                                                                                                                               em, n.attr:lower(), new)
[12:40:48.192]
[12:40:48.192]                                          local name = getItemAttr                                                                                                                               ibute(tmpItem, 'name')
[12:40:48.192]                                          if( v.attrNames or not n                                                                                                                               ame )then
[12:40:48.192]                                                  local name = (v.                                                                                                                               attrNames and used[#used] or k) .. ' ' .. (name or f.name)
[12:40:48.192]                                                  doItemSetAttribu                                                                                                                               te(tmpItem, 'name', name)
[12:40:48.192]
[12:40:48.192]                                                  if( f.article ~=                                                                                                                                '' )then
[12:40:48.192]                                                          local ar                                                                                                                               ticle = getArticle(name)
[12:40:48.192]                                                          if( arti                                                                                                                               cle ~= f.article )then
[12:40:48.192]                                                                 d                                                                                                                               oItemSetAttribute(tmpItem, 'article', article)
[12:40:48.192]                                                          end
[12:40:48.192]                                                  end
[12:40:48.192]                                          end
[12:40:48.192]
[12:40:48.192]                                          local desc = getItemAttr                                                                                                                               ibute(tmpItem, 'description') or f.description
[12:40:48.192]                                          doItemSetAttribute(tmpIt                                                                                                                               em, 'description', '[' .. n.name .. ': +' .. percent .. '%]' .. (desc == '' and                                                                                                                                '' or '\n' .. desc))
[12:40:48.192]
[12:40:48.192]                                          ret = k
[12:40:48.192]                                  end
[12:40:48.192]                                  cur = {}
[12:40:48.192]                                  if( #v.chance == i )then
[12:40:48.192]                                          done = true
[12:40:48.192]                                  end
[12:40:48.192]                          end
[12:40:48.192]                  else
[12:40:48.192]                          done = i ~= 1
[12:40:48.192]                          break
[12:40:48.192]                  end
[12:40:48.192]          end
[12:40:48.192]          if( done )then
[12:40:48.192]                  break
[12:40:48.192]          end
[12:40:48.192]  end
[12:40:48.192]
[12:40:48.192]  return tmpItem, ret
[12:40:48.192] end
[12:40:48.192]
[12:40:48.192] local function createChildLoot(parent, i, ext, pos)
[12:40:48.192]  if( not i or #i == 0 )then
[12:40:48.192]          return true
[12:40:48.192]  end
[12:40:48.192]
[12:40:48.192]  local size, cap = 0, getContainerCap(parent)
[12:40:48.192]  for k = 1, #i do
[12:40:48.192]          if( size == cap )then
[12:40:48.192]                  break
[12:40:48.192]          end
[12:40:48.192]          local tmp, ret = createLoot(i[k], ext)
[12:40:48.192]          if( tmp )then
[12:40:48.192]                  if( isContainer(tmp) )then
[12:40:48.192]                          if( createChildLoot(tmp, i[k].child, ext                                                                                                                               , pos) )then
[12:40:48.192]                                  doAddContainerItemEx(parent, tmp                                                                                                                               )
[12:40:48.192]                                  size = size + 1
[12:40:48.192]                          else
[12:40:48.193]                                  doRemoveItem(tmp)
[12:40:48.193]                          end
[12:40:48.193]                  else
[12:40:48.193]                          if( ret )then
[12:40:48.193]                                  doSendMagicEffect(pos, CONST_ME_                                                                                                                               MAGIC_GREEN)
[12:40:48.193]                                  doSendAnimatedText(pos, ret:uppe                                                                                                                               r(), tiers[ret].color)
[12:40:48.193]                          end
[12:40:48.193]                          doAddContainerItemEx(parent, tmp)
[12:40:48.193]                          size = size + 1
[12:40:48.193]                  end
[12:40:48.193]          end
[12:40:48.193]  end
[12:40:48.193]
[12:40:48.193]  return size > 0
[12:40:48.193] end
[12:40:48.193]
[12:40:48.193] local function dropLoot(pos, v, ext, master, cid, target)
[12:40:48.193]  local corpse
[12:40:48.193]  if( not master or master == target )then -- 0.3/4
[12:40:48.193]          corpse = getTileItemById(pos, v.lookCorpse).uid
[12:40:48.193]          if( isContainer(corpse) )then
[12:40:48.193]                  for i = 1, getContainerSize(corpse) do
[12:40:48.193]                          doRemoveItem(getContainerItem(corpse, 0)                                                                                                                               .uid)
[12:40:48.193]                  end
[12:40:48.193]                  local size, cap = 0, getContainerCap(corpse)
[12:40:48.193]                  for i = 1, #v.loot do
[12:40:48.193]                          if( size == cap )then
[12:40:48.193]                                  break
[12:40:48.193]                          end
[12:40:48.193]                          local tmp, ret = createLoot(v.loot[i], e                                                                                                                               xt)
[12:40:48.193]                          if( tmp )then
[12:40:48.193]                                  if( isContainer(tmp) )then
[12:40:48.193]                                          if( createChildLoot(tmp,                                                                                                                                v.loot[i].child, ext, pos) )then
[12:40:48.193]                                                  doAddContainerIt                                                                                                                               emEx(corpse, tmp)
[12:40:48.193]                                                  size = size + 1
[12:40:48.193]                                          else
[12:40:48.193]                                                  doRemoveItem(tmp                                                                                                                               )
[12:40:48.193]                                          end
[12:40:48.193]                                  else
[12:40:48.193]                                          if( ret )then
[12:40:48.193]                                                  doSendMagicEffec                                                                                                                               t(pos, CONST_ME_MAGIC_GREEN)
[12:40:48.193]                                                  doSendAnimatedTe                                                                                                                               xt(pos, ret:upper(), tiers[ret].color)
[12:40:48.193]                                          end
[12:40:48.193]                                          doAddContainerItemEx(cor                                                                                                                               pse, tmp)
[12:40:48.193]                                          size = size + 1
[12:40:48.193]                                  end
[12:40:48.193]                          end
[12:40:48.193]                  end
[12:40:48.193]          end
[12:40:48.193]  end
[12:40:48.193]  send(cid, corpse, v.description)
[12:40:48.193] end
[12:40:48.193]
[12:40:48.193] function onKill(cid, target, damage, flags)
[12:40:48.193]  if( (damage == true or bit.band(flags, 1) == 1) and isMonster(ta                                                                                                                               rget) )then -- 0.3/4
[12:40:48.193]          local v = getMonsterInfo(getCreatureName(target))
[12:40:48.193]          if( v and v.lookCorpse ~= 0 )then
[12:40:48.193]                  local s = getCreatureStorage(cid, extra_loot_key                                                                                                                               )
[12:40:48.193]                  addEvent(dropLoot, 0, getThingPos(target), v, s                                                                                                                                == -1 and rate or s, getCreatureMaster(target), cid, target)
[12:40:48.193]          end
[12:40:48.193]  end
[12:40:48.193]  return true
[12:40:48.193] end
[12:40:48.193] :onKill
[12:40:48.193] Description:
[12:40:48.193] (luaGetThing) Thing not found
 
Back
Top