• 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 Equipping armor changes your outfit

GregoryJ

New Member
Joined
Sep 8, 2013
Messages
21
Reaction score
0
Hello there,

I'll start by saying that I am new to lua and programming in general (but not the OT community - anyone else remember the WoT days? :p ), so the layout and logic of my code is likely to be unorthodox or just damn right messy.

I've created three files in the movements folder that changes your outfit depending on what is equipped in the armor slots, they work fine and do what they are suppose to. However, I'm wondering if it can be done in a more simplified or more effective way.

In this case I'm using the demon armor as the event creator, the other pieces of armor have separate lua files too. I should note that I have edited the .dat file to enable the 3rd addon for the male citizen outfit - the sprites are custom too, just encase you are wondering why equipping demon armor gives the citizen addons!


Movement files:

Lua tag isn't displaying for me.
Code:
<movevent event="Equip" itemid="2495" function="onEquipItem" slot="feet" script="legs.lua"/>
<movevent event="DeEquip" itemid="2495" function="onDeEquipItem" slot="feet" script="legs.lua"/>
<movevent event="Equip" itemid="2494" function="onEquipItem" slot="armor" script="chest.lua"/>
<movevent event="DeEquip" itemid="2494" function="onDeEquipItem" slot="armor" script="chest.lua"/>
<movevent event="Equip" itemid="2493" function="onEquipItem" slot="head" script="head.lua"/>
<movevent event="DeEquip" itemid="2493" function="onDeEquipItem" slot="head" script="head.lua"/>

Here's "chest.lua"

Code:
local cfg =
{
outfit1 = {lookType = 128, lookAddons = 1},  --male addon 1 
outfit2 = {lookType = 128, lookAddons = 2},  --male addon 2
outfit3 = {lookType = 128, lookAddons = 3},  --male addon 1 and 2
outfit4 = {lookType = 128, lookAddons = 4},  --male addon 3
outfit5 = {lookType = 128, lookAddons = 5},  --male addon 2 and 3
outfit6 = {lookType = 128, lookAddons = 6},  --male addon 1 and 3
outfit7 = {lookType = 128, lookAddons = 7}  --male all addons
}

function onEquip(cid, item, slot)    --Equipping the equipment
     if getPlayerSlotItem(cid, CONST_SLOT_HEAD).itemid == 2493 and getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2495 then
         doSetCreatureOutfit(cid, cfg.outfit7, -1)
     return true     
   end
           
     if getPlayerSlotItem(cid, CONST_SLOT_HEAD).itemid == 2493 then
         doSetCreatureOutfit(cid, cfg.outfit3, -1)
     return true     
   end
           
     if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2495 then
         doSetCreatureOutfit(cid, cfg.outfit5, -1)
     return true     
   end
     
     if getPlayerSlotItem(cid, CONST_SLOT_ARMOR).itemid == 2494 and getPlayerSlotItem(cid, CONST_SLOT_HEAD).itemid == 2493 then
         doSetCreatureOutfit(cid, cfg.outfit7, -1)
           else
          doSetCreatureOutfit(cid, cfg.outfit1, -1)
     return true
   end
 return true
end


function onDeEquip(cid, item, slot)       --Removing the equipment
     if getPlayerSlotItem(cid, CONST_SLOT_HEAD).itemid == 2493 and getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2495 then
         doSetCreatureOutfit(cid, cfg.outfit6, -1)
     return true     
   end
           
     if getPlayerSlotItem(cid, CONST_SLOT_FEET).itemid == 2495 then
         doSetCreatureOutfit(cid, cfg.outfit4, -1)
     return true     
   end
           
     if getPlayerSlotItem(cid, CONST_SLOT_HEAD).itemid == 2493  then
         doSetCreatureOutfit(cid, cfg.outfit2, -1)
           else
             doRemoveCondition(cid, CONDITION_OUTFIT)
     return true
   end
   
end

From the code you can see that it checks the various slots and according to the contents it will change your outfit. If the demon helmet and demon legs are equipped then upon executing the event it will change your addons to 7 - which is all of them. If there is a demon helmet equipped it will change your addons to the 1st and 2nd ones and so forth. The lua files for the demon helmet and legs work in a similar fashion.

The ultimate goal would be having any equipped armor displayed on your character, what ever the combination it's equipped in. Is this possible? and can it be achieved through .lua? Perhaps using a different method than the onEquip add addon concept.

Almost forgot to mention that I'm using 9.6 protocol through the OTclient.

As I have already stated, I am an absolute novice at programming - so please be gentle! Any input is very much appreciated.

Thanks for reading. :)
 
Hmm... I don't have much time, but I'll take your code and try to expand.. I'll get back to you when I've found time.
 
Back
Top