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

Solved can't use

Lbtg

Advanced OT User
Joined
Nov 22, 2008
Messages
2,398
Reaction score
165
why can't i use this scripts multiple times ?

rainitems.lua
PHP:
-- Rain item Events created by Maniucza (c) --
 
local fromPos = {x=991, y=992, z=7}
local toPos = {x=1000, y=1000, z=7}
local items = {{8306,1}, {2157,5}, {9020,1}, {2151,10}, {5808,1}, {2151,10}, {5808,1}, {9693,1}}
local maxItems = 14
 
function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
local n = not proj and 3 or 2
for i = 0, 255 do
	pos.stackpos = i
	local tile = getTileThingByPos(pos)
	if tile.itemid ~= 0 and not isCreature(tile.uid) then
		if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
			return true
		end
	end
end
return true
end
 
function checkPositions(n)
local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
if isWalkable(pos, true, false, true) then
	return pos
end
return (n < 50 and checkPositions(n+1) or false)
end
 
function onSay(cid, words, param)
	doBroadcastMessage("Rain item event will start in 1 minute. Go to temple.", MESSAGE_EVENT_ADVANCE)
	return addEvent(spawnItem, 60000, 1)
end
 
function spawnItem(created)
	if created >= maxItems then
		return doBroadcastMessage("Rain Item Event just finished!", MESSAGE_EVENT_ADVANCE)
	end
	local itemPos, itemInf = checkPositions(1), math.random(#items)
	doCreateItem(items[itemInf][1], items[itemInf][2], itemPos)
    doSendMagicEffect(itemPos, 55)
	return addEvent(spawnItem, 5000, created+1)
end

getgn.lua
PHP:
local fromPos = {x=976, y=977, z=7}
local toPos = {x=990, y=988, z=7}
local items = {{2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}}
local maxItems = 60
 
function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
local n = not proj and 3 or 2
for i = 0, 254 do
	pos.stackpos = i
	local tile = getTileThingByPos(pos)
	if tile.itemid ~= 0 and not isCreature(tile.uid) then
		if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
			return true
		end
	end
end
return true
end
 
function checkPositions(n)
local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
if isWalkable(pos, true, false, true) then
	return pos
end
return (n < 50 and checkPositions(n+1) or false)
end
 
function onSay(cid, words, param)
	doBroadcastMessage("Rain Cash event will start in 1 minute. Go to temple.", MESSAGE_EVENT_ADVANCE)
	return addEvent(spawnItem, 60000, 1)
end
 
function spawnItem(created)
	if created >= maxItems then
		return doBroadcastMessage("Rain Cash Event just finished!", MESSAGE_EVENT_ADVANCE)
	end
	local itemPos, itemInf = checkPositions(1), math.random(#items)
	doCreateItem(items[itemInf][1], items[itemInf][2], itemPos)
    doSendMagicEffect(itemPos, 28)
	return addEvent(spawnItem, 1200, created+1)
end


talkactions.xml
HTML:
	<talkaction log="yes" words="/rainitems" access="5" event="script" value="rainitems.lua"/>
HTML:
	<talkaction log="yes" words="/getgn" access="5" event="script" value="getgn.lua"/>

the thing is than i start rainitems it starts getgn , why ?
 
It's because the functions checkPositions and spawnItem have the same name in both scripts and it does the first function it finds. So change those names in 1 of the scripts.
 
checkPositions and spawnItem are just the names of the functions, you can change this, for example spawnItems. It doesn't matter which name you choose as long as it's not the same as in the other script. Don't forget to also change the name on the places where the function is used then.
 
Last edited:
LUA:
local fromPos = {x=976, y=977, z=7}
local toPos = {x=990, y=988, z=7}
local items = {{2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}}
local maxItems = 60
 
function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
local n = not proj and 3 or 2
for i = 0, 254 do
    pos.stackpos = i
    local tile = getTileThingByPos(pos)
    if tile.itemid ~= 0 and not isCreature(tile.uid) then
        if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
            return true
        end
    end
end
return true
end
 
function checkPositionss(n)
local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
if isWalkable(pos, true, false, true) then
    return pos
end
return (n < 50 and checkPositionss(n+1) or false)
end
 
function onSay(cid, words, param)
    doBroadcastMessage("Rain Cash event will start in 1 minute. Go to temple.", MESSAGE_EVENT_ADVANCE)
    return addEvent(spawnItems, 60000, 1)
end
 
function spawnItems(created)
    if created >= maxItems then
        return doBroadcastMessage("Rain Cash Event just finished!", MESSAGE_EVENT_ADVANCE)
    end
    local itemPos, itemInf = checkPositionss(1), math.random(#items)
    doCreateItem(items[itemInf][1], items[itemInf][2], itemPos)
    doSendMagicEffect(itemPos, 28)
    return addEvent(spawnItems, 1200, created+1)
end

I added a s to the functions checkPositions and spawnItem, so they don't have the same name anymore as the other script, but you can change the name to what you want.
 
The differences.
Code:
local fromPos = {x=976, y=977, z=7}
local toPos = {x=990, y=988, z=7}
local items = {{2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}, {2157,1}}
local maxItems = 60
 
function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
local n = not proj and 3 or 2
for i = 0, 254 do
    pos.stackpos = i
    local tile = getTileThingByPos(pos)
    if tile.itemid ~= 0 and not isCreature(tile.uid) then
        if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
            return true
        end
    end
end
return true
end
 
function checkPositions[COLOR=#ff0000]s[/COLOR](n)
local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
if isWalkable(pos, true, false, true) then
    return pos
end
return (n < 50 and checkPositions[COLOR=#ff0000]s[/COLOR](n+1) or false)
end
 
function onSay(cid, words, param)
    doBroadcastMessage("Rain Cash event will start in 1 minute. Go to temple.", MESSAGE_EVENT_ADVANCE)
    return addEvent(spawnItem[COLOR=#ff0000]s[/COLOR], 60000, 1)
end
 
function spawnItem[COLOR=#ff0000]s[/COLOR](created)
    if created >= maxItems then
        return doBroadcastMessage("Rain Cash Event just finished!", MESSAGE_EVENT_ADVANCE)
    end
    local itemPos, itemInf = checkPositions[COLOR=#ff0000]s[/COLOR](1), math.random(#items)
    doCreateItem(items[itemInf][1], items[itemInf][2], itemPos)
    doSendMagicEffect(itemPos, 28)
    return addEvent(spawnItem[COLOR=#ff0000]s[/COLOR], 1200, created+1)
end
 
If you use a function in a script, it looks for the function with that name and it executes the first one it finds, so thats why if you use functions with the same name in different scripts, it just takes one of them.
By changing the name, doesn't matter if this is by adding a s or changing a whole word, it looks for the function with that name, which isn't the same now anymore so it finds the correct one.
 
Only thing that matters is that the name of the function is different (name that is not used in other scripts), you can even call it bunny instead of spawnItems, by adding an s I just made the name different.
 
Back
Top