• 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!

loopy function doArmPlayer(cid) :s

Status
Not open for further replies.

hodleo

Formerly cbrm -Crypto enthusiast, Retired scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,598
Solutions
3
Reaction score
955
Location
Caribbean Sea
Lua:
function armPlayer(cid)
Helm = {2497, 2493, 2506, 2471, 2323, 2496, 5741, 2474, 9778}
arm = {2656, 2487, 8867, 2503, 2466, 8869, 8877, 2486, 8890}
leg = {2488, 2469, 2470, 2495, 7894, 9777, 7885, 7895, 7730}    
boot = {2195, 9932, 7892, 2646, 7893, 7891, 2641, 5462, 7886}    
amulet = {2198, 10220, 10219, 10221, 2171, 2197, 2131}
ring = {2168, 2164, 2165, 2169}
potion = {7588, 7589}
b1 = {2313, 2304}
bow = {7438, 7367, 8849, 8850, 8851, 8852, 8853}
weap = {2407, 7449, 7748, 2438, 7405, 7436, 7419, 7751, 7456, 7434, 7388, 7429, 7756, 7774, 7430, 7451, 2421}
rod = {2183, 8912, 2181, 8910}
wand = {8921, 2187, 8920, 8922}
shield = {2532, 2534, 2535, 2519, 2520, 2522, 2514, 2539, 2542}
book = {8918, 8900, 8903, 8902, 8901, 8904}
ammo = {7368, 7366, 7365, 7364, 2399, 7839, 7840, 2545, 2410}

local function r(n) return math.random(n) end
local randDist, randWeapon, randDef, randBows, randH, randArmor, randLeg, randBoots, randAmulets, randRings, randWands, randRods, randBooks = r(#ammo), r(#weap), r(#shield), r(#bow), r(#Helm), r(#arm), r(#leg), r(#boot), r(#amulet), r(#ring), r(#wand), r(#rod), r(#book)

local commonItems = {
  {itemid=Helm[randH], count=1}, -- HELMET
  {itemid=arm[randArmor], count=1}, -- ARMOR
  {itemid=leg[randLeg], count=1}, -- LEG
  {itemid=boot[randBoots], count=1}, -- BOTAS
  {itemid=amulet[randAmulets], count=1}, -- AMULETOS
  {itemid=ring[randRings], count=1}, -- ANILLO
}

local firstItems = {
  { -- SORC ITEMS
    {itemid=wand[randWands], count=1}, -- wand
    {itemid=book[randBooks], count=1}, -- book
  },
  { -- DRUID ITEMS
    {itemid=rod[randRods], count=1}, -- rod
    {itemid=book[randBooks], count=1}, -- book
  },
  { -- PALADIN ITEMS
    {itemid=ammo[randDist], count=99}, -- Municion
    {itemid=bow[randBows], count=1}, -- bow/crossbow
    {itemid=shield[randDef], count=1}, -- Escudo
  },
  { -- KNIGHT ITEMS
    {itemid=weap[randWeapon], count=1}, -- arma
    {itemid=shield[randDef], count=1}, -- Escudo
  }
}

for _, items in ipairs(firstItems) do
  for _, item in ipairs(commonItems) do
    table.insert(items, item)
  end
end

      --[[local backpack = ]]doPlayerAddItem(cid, 10518, 1)

      --local giveItems = firstItems[3]
      local giveItems = firstItems[getPlayerVocation(cid)]

      if giveItems ~= nil then
        for _, v in ipairs(giveItems) do
          --doAddContainerItem(backpack, v.itemid, v.count or 1)
          doPlayerAddItem(cid, v.itemid, v.count or 1)
        end      
      end
end
 
Last edited:
[sarcasm="false"]
IRC_cli said:
(17:32:39) <@Hani_> 21:57:23 <@Talaturen> "if it works, don't fix it"
(17:32:39) <@Hani_> 21:57:32 <@Talaturen> kool quote ;d
(17:32:41) <@Hani_> :D
[sarcasm]
 
Also, why loop things several times if it's gonna return 1 (one) variable in the end?
You're not even using loop variable (i) anywhere.
Lua:
local function r(n) return math.random(n) end
local randDist, randWeapon, randDef, randBows, randH, randArmor, randLeg, randBoots, randAmulets, randRings, randWands, randRods, randBooks = r(#ammo), r(#weap), r(#shield), r(#bow), r(#Helm), r(#arm), r(#leg), r(#boot), r(#amulet), r(#ring), r(#wand), r(#rod), r(#book)
 
Last edited:
..anyway, refresh the main post and check my loops
it works100%, i just need some lua table technique to reduce it the most possible
 
Code:
local function r(n) return math.random(n) end

local Helm = {2497, 2493, 2506, 2471, 2323, 2496, 5741, 2474, 9778}
local arm = {2656, 2487, 8867, 2503, 2466, 8869, 8877, 2486, 8890}
local leg = {2488, 2469, 2470, 2495, 7894, 9777, 7885, 7895, 7730}    
local boot = {2195, 9932, 7892, 2646, 7893, 7891, 2641, 5462, 7886}    
local amulet = {2198, 10220, 10219, 10221, 2171, 2197, 2131}
local ring = {2168, 2164, 2165, 2169}
local potion = {7588, 7589}
local b1 = {2313, 2304}
local bow = {7438, 7367, 8849, 8850, 8851, 8852, 8853}
local weap = {2407, 7449, 7748, 2438, 7405, 7436, 7419, 7751, 7456, 7434, 7388, 7429, 7756, 7774, 7430, 7451, 2421}
local rod = {2183, 8912, 2181, 8910}
local wand = {8921, 2187, 8920, 8922}
local shield = {2532, 2534, 2535, 2519, 2520, 2522, 2514, 2539, 2542}
local book = {8918, 8900, 8903, 8902, 8901, 8904}
local ammo = {7368, 7366, 7365, 7364, 2399, 7839, 7840, 2545, 2410}

function doArmPlayer(cid)
	local randDist, randWeapon, randDef, randBows, randH, randArmor, randLeg, randBoots, randAmulets, randRings, randWands, randRods, randBooks = r(#ammo), r(#weap), r(#shield), r(#bow), r(#Helm), r(#arm), r(#leg), r(#boot), r(#amulet), r(#ring), r(#wand), r(#rod), r(#book)

	local commonItems = {
		{itemid=Helm[randH]}, -- HELMET
		{itemid=arm[randArmor]}, -- ARMOR
		{itemid=leg[randLeg]}, -- LEG
		{itemid=boot[randBoots]}, -- BOTAS
		{itemid=amulet[randAmulets]}, -- AMULETOS
		{itemid=ring[randRings]}, -- ANILLO
	}

	local firstItems = {
		{ -- SORC ITEMS
			{itemid=wand[randWands]}, -- wand
			{itemid=book[randBooks]}, -- book
		},
		{ -- DRUID ITEMS
			{itemid=rod[randRods]}, -- rod
			{itemid=book[randBooks]}, -- book
		},
		{ -- PALADIN ITEMS
			{itemid=ammo[randDist], count=99}, -- Municion
			{itemid=bow[randBows]}, -- bow/crossbow
			{itemid=shield[randDef]}, -- Escudo
		},
		{ -- KNIGHT ITEMS
			{itemid=weap[randWeapon]}, -- arma
			{itemid=shield[randDef]}, -- Escudo
		}
	}
	for _, items in ipairs(firstItems) do
		for _, item in ipairs(commonItems) do
			table.insert(items, item)
		end
	end
	doPlayerAddItem(cid, 10518, 1)
	local giveItems = firstItems[getPlayerVocation(cid)]
	if(giveItems) then
		for _, v in ipairs(giveItems) do
			doPlayerAddItem(cid, v.itemid, v.count or 1)
		end
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "The instance downstairs is recommended for new players!")
	end
end
Sorry, but I can't do better than that.
 
Status
Not open for further replies.
Back
Top