• 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 Itemtype --> weapon? TFS 1.2

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
746
Solutions
9
Reaction score
125
Hello! Thanks for reading this and for your time any help would be awesome!

I want something like:

Code:
if itemEx.itemType(weapon) then
.......
instead of
Code:
"if itemEx.itemid == 2190 or 2191 or 2192... (and maaaany other weapons that could take forever to write) ..then"
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

     local text = "[5% Critical]"
     local text2 = "You added 5% critical strike."
     if itemEx.itemid == 2190 then
         doPlayerSendTextMessage(cid, 22, text2)
         doSetItemActionId(itemEx.uid, 3526)
         doSetItemSpecialDescription(itemEx.uid, text)
   end
    
     return true
end

Thanks for your help!
 
Well, I wonder if you could list all of the weapons item ids in an array, and when it checks itemEx.itemid to check the entire array list for the weapon.

For example:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local text = "[5% Critical]"
    local text2 = "You added 5% critical strike."
    local failure = "This is not a weapon."
    local weapon =  {1234, 2522, 3353, 4235}
    if isInArray(weapon, itemEx.itemid) then
        doPlayerSendTextMessage(cid, 22, text2)
        doSetItemActionId(itemEx.uid, 3526)
        doSetItemSpecialDescription(itemEx.uid, text)
    else
        doPlayerSendTextMessage(cid, 22, failure)
    end

    return true
end

Keep in mind that I am just using that as an example, and I'm not 100% sure if that would work without error. It may be possible doing that though.

Otherwise, I believe you would have to make it where it will read the value of "<attribute key="weaponType" value="sword" />" and off of the top of my head I don't remember how to do it.
 
Last edited:
This doesnt work, it just let me apply it everywhere.

Code:
     if ItemType(itemEx):getWeaponType() then
         doPlayerSendTextMessage(cid, 22, text2)
         doSetItemActionId(itemEx.uid, 3526)
         doSetItemSpecialDescription(itemEx.uid, text)
end
 
This doesnt work, it just let me apply it everywhere.

Code:
     if ItemType(itemEx):getWeaponType() then
         doPlayerSendTextMessage(cid, 22, text2)
         doSetItemActionId(itemEx.uid, 3526)
         doSetItemSpecialDescription(itemEx.uid, text)
end

Always check the resource section of this site, chances are you can lift code from an existing script and apply it to the script you are writing :)
Like this excerpt of code from the link below
Code:
function getSlottedItems(player)
    local left = pushThing(player:getSlotItem(CONST_SLOT_LEFT)).itemid
    local right = pushThing(player:getSlotItem(CONST_SLOT_RIGHT)).itemid
 
    left = ItemType( left ):getWeaponType()
    right = ItemType( right ):getWeaponType()
    return left, right
end
https://otland.net/threads/square-trainer-1-2-removes-stamina-while-training.238193/
 
Yeah, thanks! But with that part, it will only be able to use it, if the weapon is equiped, if you have it somewhere other than left or right slot, wont be possible, or am i wrong? I just need a condition that involves all weapons so i dont have to writte and search for every single weapon id.

Obviously im not a master in scripting, nor close to it, a bit more info would be awesome! and again, thanks for the help!
 
Yeah, thanks! But with that part, it will only be able to use it, if the weapon is equiped, if you have it somewhere other than left or right slot, wont be possible, or am i wrong? I just need a condition that involves all weapons so i dont have to writte and search for every single weapon id.

Obviously im not a master in scripting, nor close to it, a bit more info would be awesome! and again, thanks for the help!
Most of, if not all of the code for the tfs framework is written in a syntax you read,(its in english).
Most of your time coding will be spent on testing things out in every program/script you will ever write.
The only way to understand what works best is to test test test...

That is all I do when I have a server running.. i test values to see if x returns what i need.

You are looking for a definitive or an absolute... but that is not how development works.
 

Similar threads

Back
Top