• 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 Function - Help

Cosmotonio

New Member
Joined
Nov 26, 2007
Messages
142
Reaction score
0
i made this code, but do not work.
someone help me with this?

Code:
local weapons = {a=2376, b=2404, c=2406, d=2419, e=2421, f=2453}

function HaveWeapon(cid)
	for x = weapons.a, weapons.b do
		for y = weapons.c, weapons.d do
			for z = weapons.e, weapons.f do	
				if getPlayerSlotItem(cid, 5) == x or getPlayerSlotItem(cid, 6) == x or getPlayerSlotItem(cid, 

5) == y or getPlayerSlotItem(cid, 6) == y or getPlayerSlotItem(cid, 5) == z or getPlayerSlotItem(cid, 6) == z then
					return TRUE
				else
					return FALSE
				end
			end
		end
	end
end
 
Last edited:
PHP:
function hasWeapons(cid, weaponIds)
	local rightHand = getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid
	local leftHand = getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid
	local hasRightHand = (rightHand >= weaponIds[1]) and rightHand <= weaponIds[2]
	local hasLeftHand = (leftHand >= weaponIds[1]) and leftHand <= weaponIds[2]
	return (hasRightHand or hasLeftHand) and TRUE or FALSE
end

function checkWeapon(cid, weaponIds)
	for startId, endId in pairs(weaponIds) do
		if hasWeapons(cid, {startId, endId}) == TRUE then
			return TRUE
		end
	end
	return FALSE
end

And then you use:
PHP:
local weaponIds = {[2376]=2404, [2406]=2419, [2421]=2453}

if checkWeapon(cid, weaponIds) == TRUE then
    -- CODE IF HAS WEAPON HERE
else
    -- CODE IF HAS NOT WEAPON HERE
end
 
Well, idk if there is a function like getPlayerWeaponType or getWeaponType, try if they work first, if not try this:
PHP:
WEAPONTYPE_CLUB = 1
WEAPONTYPE_SWORD = 2
WEAPONTYPE_AXE = 3
WEAPONTYPE_ROD = 4
WEAPONTYPE_WAND = 5
WEAPONTYPE_DISTANCE = 6
 
WEAPON_CLUB = {
           2321, 2382, 2391, 2394, 2398, 2401, 2416, 2417, 2421, 2422, 2423, 2424, 2433, 2434, 2436, 2437, 2439, 2444, 2445, 2448, 2449, 2452, 2453, 3961, 3966, 4846, 7379, 7381, 7387, 7392, 7410, 7414, 7415, 7424, 7425, 7426, 7427, 7429, 7430, 7431, 7432, 7437, 7451, 7452
          }
WEAPON_SWORD = {
            2376, 2377, 2379, 2383, 2384, 2385, 2390, 2392, 2393, 2395, 2396, 2397, 2400, 2402, 2403, 2404, 2406, 2407, 2408, 2409, 2411, 2412, 2413, 2419, 2420, 2438, 2442, 2446, 2450, 2451, 3963, 6101, 6528, 7382, 7383, 7384, 7385, 7386, 7390, 7402, 7404, 7405, 7406, 7407, 7408, 7416, 7449
           }
WEAPON_AXE = {
          2378, 2380, 2381, 2386, 2387, 2388, 2405, 2414, 2415, 2418, 2425, 2426, 2427, 2428, 2429, 2430, 2431, 2432, 2435, 2440, 2441, 2443, 2447, 2454, 2550, 2559, 3962, 3964, 6553, 7380, 7388, 7389, 7412, 7413, 7419, 7434
         }
WEAPON_WAND = {
           2187, 2188, 2189, 2190, 2191
          }
WEAPON_ROD = {
          2181, 2182, 2183, 2185, 2186
         }
 
WEAPON_DISTANCE = {
                   1294, 2111, 2389, 2399, 2410, 2455, 2456, 3965, 5803, 7366, 7367, 7368, 7378, 7438
                   }
 
function isWeapon(itemId)
 
    if (isInArray(WEAPON_DISTANCE, itemId)) or (isInArray(WEAPON_CLUB, itemId)) or (isInArray(WEAPON_SWORD, itemId)) or (isInArray(WEAPON_AXE, itemId)) or (isInArray(WEAPON_ROD, itemId)) or (isInArray(WEAPON_WAND, itemId)) then
        return TRUE
    else
        return FALSE
    end
end
 
function getWeaponType(itemId)
    if (isWeapon(itemId) == FALSE) then
        return FALSE
    else
        if isInArray(WEAPON_CLUB, itemId) then
            return WEAPONTYPE_CLUB
        elseif isInArray(WEAPON_AXE, itemId) then
            return WEAPONTYPE_AXE
        elseif isInArray(WEAPON_SWORD, itemId) then
            return WEAPONTYPE_SWORD
        elseif isInArray(WEAPON_WAND, itemId) then
            return WEAPONTYPE_WAND
        elseif isInArray(WEAPON_ROD, itemId) then
            return WEAPONTYPE_ROD            
        elseif isInArray(WEAPON_DISTANCE, itemId) then
            return WEAPONTYPE_DISTANCE
        end
    end    
end
credits to Forger for this script


You might also want to add all ids there lol
 

Similar threads

  • Question Question
Replies
5
Views
289
Back
Top