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

Script Problem

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,571
Solutions
3
Reaction score
98
Location
Portugal
Hello, i was trying to make a script for a item that sets weapon attribute aid like this one but i cant put it working, can someone fix it for me?
I would be so greatfull and ofc give REP to every1 who helps me =p

LUA:
local weapons = 
          {
          {7390}, 
          {7405}, 
		  {7408} 
		  }

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerWeapon(cid).actionid == 1234 then
	doPlayerSendCancel (cid, "You already used this on your weapon.")
	else
	if itemEx.itemid == weapons then
	doItemSetAttribute(uid, 'aid', 1234)
	doSendMagicEffect(cid, 33)
	doSendAnimatedText(getCreaturePosition(cid), "UPGRADED!",TEXTCOLOR_LIGHTGREEN)
return true
end
 
"eof" means End Of File , you missed an "end"
LUA:
local weapons = 
          {
          {7390}, 
          {7405}, 
		  {7408} 
		  }
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerWeapon(cid).actionid == 1234 then
	doPlayerSendCancel (cid, "You already used this on your weapon.")
elseif itemEx.itemid == weapons then
	doItemSetAttribute(uid, 'aid', 1234)
	doSendMagicEffect(cid, 33)
	doSendAnimatedText(getCreaturePosition(cid), "UPGRADED!",TEXTCOLOR_LIGHTGREEN)
end
return true
end
there you go
 
Remember that always "IF" is ending with an "END"
LUA:
local weapons = 
          {
          {7390}, 
          {7405}, 
		  {7408} 
		  }
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(getPlayerWeapon(cid).actionid == 1234) then
		doPlayerSendCancel (cid, "You already used this on your weapon.")
	else
		if(itemEx.itemid == weapons) then
			doItemSetAttribute(uid, 'aid', 1234)
			doSendMagicEffect(cid, 33)
			doSendAnimatedText(getCreaturePosition(cid), "UPGRADED!",TEXTCOLOR_LIGHTGREEN)
		end
	end
	return true
end
 
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerWeapon(cid).actionid == 10000 then
	doPlayerSendCancel (cid, "You already used this on your weapon.")
elseif itemEx.itemid == 7390 then
	doSetItemActionId (uid, 10000)
	doSendMagicEffect(cid, 33)
	doSendAnimatedText(getCreaturePosition(cid), "UPGRADED!",TEXTCOLOR_LIGHTGREEN)
end
return true
end
doesnt work, does not even sends cancel, just says "cannot use object"
 
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerWeapon(cid).actionid == 10000 then
	doPlayerSendCancel (cid, "You already used this on your weapon.")
elseif itemEx.itemid == 8306 then
	doItemSetAttribute(item.uid, "aid", 10000)
	doSendMagicEffect(getCreaturePosition(cid), 49)
	doSendAnimatedText(getCreaturePosition(cid), "UPGRADED!",TEXTCOLOR_LIGHTGREEN)
end
return true
end

Nothing Happens

 
LUA:
local t = {7390, 7405, 7408}
local actionId = 12345
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if isInArray(t, itemEx.itemid) then
		if getItemAttribute(itemEx.uid, 'aid') ~= actionId then
			doItemSetAttribute(itemEx.uid, 'aid', actionId)
			doSendMagicEffect(toPosition, CONST_ME_MAGIC_BLUE)
		else
			doPlayerSendCancel(cid, "You cannot use this object.")
		end
	else
		doPlayerSendCancel(cid, "You cannot use this object.")
	end
	return true
end
OtLand is pissing me off. Keeps timing out.
 
worked fine, but how can i set on this script to check if weapon has action id 12345? so the script will work with that weapon

LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 0)
setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 0)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

local manaNeededPerTarget = 20
local hitExtraTargets = 3
local hitExtraTargetsInRange = 0


function getCreaturesInRange(position, radiusx, radiusy, showMonsters, showPlayers)
    local creaturesList = {}
    for x = -radiusx, radiusx do
        for y = -radiusy, radiusy do
            if not (x == 0 and y == 0) then
                creature = getTopCreature({x = position.x+x, y = position.y+y, z = position.z, stackpos = STACKPOS_TOP_CREATURE})
                if (creature.type == 1 and showPlayers == 1) or (creature.type == 2 and showMonsters == 1) then
                    table.insert(creaturesList, creature.uid)
                end
            end
        end
    end
    return creaturesList
end

function onUseWeapon(cid, var)
    local ret = doCombat(cid, combat, var)
    if(ret == LUA_ERROR) then
        return LUA_ERROR
    end
    doPlayerAddSpentMana(cid, manaNeededPerTarget)
    doCreatureAddMana(cid, -manaNeededPerTarget)
    
    local target = variantToNumber(var)
    local hitplayers = 0
    if(target ~= 0) then
        if(isPlayer(target) == TRUE) then
            hitplayers = 1
        end
        local nowHit = 0
        local randomId = 0
        local otherTargets = getCreaturesInRange(getCreaturePosition(target), hitExtraTargetsInRange, hitExtraTargetsInRange, 1, hitplayers)
        if(#otherTargets > 0) then
            for i = 1, hitExtraTargets do
                if(getCreatureMana(cid) > manaNeededPerTarget) then
                    randomId = math.random(1, #otherTargets)
                    nowHit = otherTargets[randomId]
                    if(isCreature(nowHit) == TRUE) then
                        table.remove(otherTargets, randomId)
                        ret = doCombat(cid, combat, numberToVariant(nowHit))
                        if(ret ~= LUA_ERROR) then
                            doPlayerAddSpentMana(cid, manaNeededPerTarget)
                            doCreatureAddMana(cid, -manaNeededPerTarget)
                        end
                    end
                    if(#otherTargets == 0) then
                        break
                    end
                else
                    break
                end
            end
        end
    end
    return true
end
 
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerWeapon(cid).actionid == 10000 then
	doPlayerSendCancel (cid, "You already used this on your weapon.")
elseif itemEx.itemid == 7390 then
	doSetItemActionId (uid, 10000)
	doSendMagicEffect(cid, 33)
	doSendAnimatedText(getCreaturePosition(cid), "UPGRADED!",TEXTCOLOR_LIGHTGREEN)
end
return true
end
doesnt work, does not even sends cancel, just says "cannot use object"

Damn srry, I didn't read that it didn't work before I went to the gym or I would have helped >.<, anyways thank you Zyntax and J.Dre for helping lava :D
 
LUA:
if getItemAttribute(itemEx.uid, 'aid') ~= actionId then
And, you're welcome. :D

rugged do ya know where to put that lane in that weapon script? =p

worked fine, but how can i set on this script to check if weapon has action id 12345? so the script will work with that weapon

LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 0)
setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 0)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

local manaNeededPerTarget = 20
local hitExtraTargets = 3
local hitExtraTargetsInRange = 0


function getCreaturesInRange(position, radiusx, radiusy, showMonsters, showPlayers)
    local creaturesList = {}
    for x = -radiusx, radiusx do
        for y = -radiusy, radiusy do
            if not (x == 0 and y == 0) then
                creature = getTopCreature({x = position.x+x, y = position.y+y, z = position.z, stackpos = STACKPOS_TOP_CREATURE})
                if (creature.type == 1 and showPlayers == 1) or (creature.type == 2 and showMonsters == 1) then
                    table.insert(creaturesList, creature.uid)
                end
            end
        end
    end
    return creaturesList
end

function onUseWeapon(cid, var)
    local ret = doCombat(cid, combat, var)
    if(ret == LUA_ERROR) then
        return LUA_ERROR
    end
    doPlayerAddSpentMana(cid, manaNeededPerTarget)
    doCreatureAddMana(cid, -manaNeededPerTarget)
    
    local target = variantToNumber(var)
    local hitplayers = 0
    if(target ~= 0) then
        if(isPlayer(target) == TRUE) then
            hitplayers = 1
        end
        local nowHit = 0
        local randomId = 0
        local otherTargets = getCreaturesInRange(getCreaturePosition(target), hitExtraTargetsInRange, hitExtraTargetsInRange, 1, hitplayers)
        if(#otherTargets > 0) then
            for i = 1, hitExtraTargets do
                if(getCreatureMana(cid) > manaNeededPerTarget) then
                    randomId = math.random(1, #otherTargets)
                    nowHit = otherTargets[randomId]
                    if(isCreature(nowHit) == TRUE) then
                        table.remove(otherTargets, randomId)
                        ret = doCombat(cid, combat, numberToVariant(nowHit))
                        if(ret ~= LUA_ERROR) then
                            doPlayerAddSpentMana(cid, manaNeededPerTarget)
                            doCreatureAddMana(cid, -manaNeededPerTarget)
                        end
                    end
                    if(#otherTargets == 0) then
                        break
                    end
                else
                    break
                end
            end
        end
    end
    return true
end
 
try it here, but I'm not positive its supposed to go here.
LUA:
						local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 0)
setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 0)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)
 
local manaNeededPerTarget = 20
local hitExtraTargets = 3
local hitExtraTargetsInRange = 0
 
 
function getCreaturesInRange(position, radiusx, radiusy, showMonsters, showPlayers)
    local creaturesList = {}
    for x = -radiusx, radiusx do
        for y = -radiusy, radiusy do
            if not (x == 0 and y == 0) then
                creature = getTopCreature({x = position.x+x, y = position.y+y, z = position.z, stackpos = STACKPOS_TOP_CREATURE})
                if (creature.type == 1 and showPlayers == 1) or (creature.type == 2 and showMonsters == 1) then
                    table.insert(creaturesList, creature.uid)
                end
            end
        end
    end
    return creaturesList
end
 
function onUseWeapon(cid, var)
    local ret = doCombat(cid, combat, var)
    if(ret == LUA_ERROR) then
        return LUA_ERROR
    end
	if getItemAttribute(itemEx.uid, 'aid') ~= actionId then
			doItemSetAttribute(itemEx.uid, 'aid', actionId)
    doPlayerAddSpentMana(cid, manaNeededPerTarget)
    doCreatureAddMana(cid, -manaNeededPerTarget)
 
    local target = variantToNumber(var)
    local hitplayers = 0
    if(target ~= 0) then
        if(isPlayer(target) == TRUE) then
            hitplayers = 1
        end
        local nowHit = 0
        local randomId = 0
        local otherTargets = getCreaturesInRange(getCreaturePosition(target), hitExtraTargetsInRange, hitExtraTargetsInRange, 1, hitplayers)
        if(#otherTargets > 0) then
            for i = 1, hitExtraTargets do
                if(getCreatureMana(cid) > manaNeededPerTarget) then
                    randomId = math.random(1, #otherTargets)
                    nowHit = otherTargets[randomId]
                    if(isCreature(nowHit) == TRUE) then
                        table.remove(otherTargets, randomId)
                        ret = doCombat(cid, combat, numberToVariant(nowHit))
                        if(ret ~= LUA_ERROR) then
                            doPlayerAddSpentMana(cid, manaNeededPerTarget)
                            doCreatureAddMana(cid, -manaNeededPerTarget)
                        end
                    end
                    if(#otherTargets == 0) then
                        break
                    end
                else
                    break
                end
            end
        end
    end
    return true
end
 
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, false)
setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, false)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

local manaNeededPerTarget = 20
local hitExtraTargets = 3
local hitExtraTargetsInRange = 0

local actionId = 12345

function getCreaturesInRange(position, radiusx, radiusy, showMonsters, showPlayers)
	local creaturesList = {}
	for x = -radiusx, radiusx do
		for y = -radiusy, radiusy do
			if not (x == 0 and y == 0) then
				local creature = getTopCreature({x = position.x+x, y = position.y+y, z = position.z, stackpos = STACKPOS_TOP_CREATURE})
				if (creature.type == 1 and showPlayers == 1) or (creature.type == 2 and showMonsters == 1) then
					table.insert(creaturesList, creature.uid)
				end
			end
		end
	end
	return creaturesList
end

function onUseWeapon(cid, var)
	local ret = doCombat(cid, combat, var)
	if(ret == false) then
		return false
	end

	doPlayerAddSpentMana(cid, manaNeededPerTarget)
	doCreatureAddMana(cid, -manaNeededPerTarget)

	if(getPlayerWeapon(cid, true).actionid ~= actionId) then
		return true
	end

	local target = variantToNumber(var)
	local hitplayers = 0
	if(target ~= 0) then
		if(isPlayer(target)) then
			hitplayers = 1
		end
		local nowHit = 0
		local randomId = 0
		local otherTargets = getCreaturesInRange(getCreaturePosition(target), hitExtraTargetsInRange, hitExtraTargetsInRange, 1, hitplayers)
		if(#otherTargets > 0) then
			for i = 1, hitExtraTargets do
				if(getCreatureMana(cid) > manaNeededPerTarget) then
					randomId = math.random(1, #otherTargets)
					nowHit = otherTargets[randomId]
					if(isCreature(nowHit)) then
						table.remove(otherTargets, randomId)
						ret = doCombat(cid, combat, numberToVariant(nowHit))
						if(ret ~= false) then
							doPlayerAddSpentMana(cid, manaNeededPerTarget)
							doCreatureAddMana(cid, -manaNeededPerTarget)
						end
					end
					if(#otherTargets == 0) then
						break
					end
				else
					break
				end
			end
		end
	end
	return true
end
 
Back
Top