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

Walk on tile and monster spawn

Tofflarn

New Member
Joined
Mar 22, 2008
Messages
360
Reaction score
1
Location
Sweden
As the title says. I need a script that create like 5 monsters on different sqm(X;Y;Z) when you walk on a sqm.

If someone can help me with this, could that person be kind and Explain about the script how he did it, beacuse i wan't to learn lua :D




I tried this, first script i ever done!

]function onStepIn(cid, item, position, fromPosition)
if item.uid == 9009 then
if item.itemid == 431 then
demon1pos = {x=33232, y=31728, z=11}
demon2pos = {x=33197, y=31696, z=11}
demon3pos = {x=33165, y=31728, z=11}
demon4pos = {x=33198, y=31762, z=11}
demon5pos = {x=33130, y=31692, z=11}
demon6pos = {x=33104, y=31729, z=11}

doSummonCreature("Demon", demon1pos)
doSummonCreature("Demon", demon2pos)
doSummonCreature("Demon", demon3pos)
doSummonCreature("Demon", demon4pos)
doSummonCreature("Demon", demon5pos)
doSummonCreature("Demon", demon6pos)
end
end



Error =
[13/11/2008 20:16:57] Warning: [Event::loadScript] Can not load script. data/movements/scripts/walking.lua
[13/11/2008 20:16:57] data/movements/scripts/walking.lua:1: unexpected symbol near ']'
 
Last edited:
Code:
[COLOR="Red"][b][u]][/u][/b][/COLOR]function onStepIn(cid, item, position, fromPosition)

remove

PHP:
function onStepIn(cid, item, position, fromPosition)
    local positions = { 
        {x=33232, y=31728, z=11},
        {x=33197, y=31696, z=11},
        {x=33165, y=31728, z=11},
        {x=33198, y=31762, z=11},
        {x=33130, y=31692, z=11},
        {x=33104, y=31729, z=11}
    }
	if item.uid == 9009 then
	    if isPlayer(cid) == TRUE
	        for i = 1, #positions do
	            doSummonCreature("Demon", i)
	        end
	    end
	end
	return TRUE
end

First time tried like this, not sure if this will work! :D
 
Last edited:
[13/11/2008 22:31:45] Warning: [Event::loadScript] Can not load script. data/movements/scripts/walking.lua
[13/11/2008 22:31:45] data/movements/scripts/walking.lua:12: 'then' expected near 'for'


:(

And this should not only summon demons. When i/you get this work there will be six different monsters ;)

thx in andvanced
 
PHP:
function onStepIn(cid, item, position, fromPosition) 
    local positions = {  
        {x=33232, y=31728, z=11}, 
        {x=33197, y=31696, z=11}, 
        {x=33165, y=31728, z=11}, 
        {x=33198, y=31762, z=11}, 
        {x=33130, y=31692, z=11}, 
        {x=33104, y=31729, z=11} 
    } 
    if item.uid == 9009 then 
        if isPlayer(cid) == TRUE 
            for i = 1, table.maxn(positions) do 
                doSummonCreature("Demon", i) 
            end 
        end 
    end 
    return TRUE 
end
 
PHP:
function onStepIn(cid, item, position, fromPosition) 
    local positions = {  
        {x=33232, y=31728, z=11}, 
        {x=33197, y=31696, z=11}, 
        {x=33165, y=31728, z=11}, 
        {x=33198, y=31762, z=11}, 
        {x=33130, y=31692, z=11}, 
        {x=33104, y=31729, z=11} 
    } 
    if item.uid == 9009 then 
        if isPlayer(cid) == TRUE 
            for i = 1, table.maxn(positions) do 
                doSummonCreature("Demon", i) 
            end 
        end 
    end 
    return TRUE 
end

No, no... there is missing "then" after isPlayer(cid) check. ^^

Code:
function onStepIn(cid, item, position, fromPosition)
    local positions = { 
        {x=33232, y=31728, z=11},
        {x=33197, y=31696, z=11},
        {x=33165, y=31728, z=11},
        {x=33198, y=31762, z=11},
        {x=33130, y=31692, z=11},
        {x=33104, y=31729, z=11}
    }
    if item.uid == 9009 then
        if isPlayer(cid) == TRUE then
            for i = 1, #positions do
                doSummonCreature("Demon", i)
            end
        end
    end
    return TRUE
end

PHP:
function onStepIn(cid, item, position, fromPosition)
    local lalala = { 
        ["Demon"] = {x=33232, y=31728, z=11},
        ["Demon"] = {x=33197, y=31696, z=11},
        ["Rat"] = {x=33165, y=31728, z=11},
        ["Orc"] = {x=33198, y=31762, z=11},
        ["Troll"] = {x=33130, y=31692, z=11},
        ["Rotworm"] = {x=33104, y=31729, z=11}
    }
    if item.uid == 9009 then
        if isPlayer(cid) == TRUE then
            for k, v in ipairs(lalala) do
                doSummonCreature(k, v)
            end
        end
    end
    return TRUE
end
Not sure ^
 
Last edited:
is thiere any change?? thx for the support Marcinek and macroman but i need some more help ;) a script that summon different monster on different pos! :)


Btw: how did you learn lua? any good tutorial and such
 
Haha :( I used your code.

Well, I can see that, but you didnt fix right error ^^

is thiere any change?? thx for the support Marcinek and macroman but i need some more help ;) a script that summon different monster on different pos! :)


Btw: how did you learn lua? any good tutorial and such

Reading *.lua files, trying myself, asking Colandus.

Look up, there is one for different monsters.
 
Haha didn't even look at the error to be honest, all I did was looking at your code where the comment was (using php highlight, #).

@Tofflarn: Use math.random for the random monsters.
I actually learned LUA a few weeks ago, although it's pretty much the same as PHP (which I've known for about 2 years now), so kinda made it easier for me. But if you look at the scripts, you can see it's pretty much basic English.
 
function onStepIn(cid, item, position, fromPosition)
local lalala = {
["Demon"] = {x=33232, y=31728, z=11},
["Demon"] = {x=33197, y=31696, z=11},
["Rat"] = {x=33165, y=31728, z=11},
["Orc"] = {x=33198, y=31762, z=11},
["Troll"] = {x=33130, y=31692, z=11},
["Rotworm"] = {x=33104, y=31729, z=11}
}
if item.uid == 9009 then
if isPlayer(cid) == TRUE then
for k, v in ipairs(lalala) do
doSummonCreature(k, v)
end
end
end
return TRUE
end



Local lalalalA?
And for k, v in ipairs(lalala) do?


No errors in consol. but it isnt working :(
 
PHP:
function onStepIn(cid, item, position, fromPosition)
    local positions = { 
        {x=33232, y=31728, z=11},
        {x=33197, y=31696, z=11},
        {x=33165, y=31728, z=11},
        {x=33198, y=31762, z=11},
        {x=33130, y=31692, z=11},
        {x=33104, y=31729, z=11}
    }
	local monsters = { "Demon", "Troll", "Rotworm", "Demon", "Rat", "Bug" }
    if item.uid == 9009 then
        if isPlayer(cid) == TRUE then
            for i = 1, #positions do
				for y = 1, #monsters do
                    doSummonCreature(y, i)
				end
            end
        end
    end
    return TRUE
end

If #positions and #monsters doesnt work, replace them with table.maxn(positions) and table.maxn(monsters). I just wanted to see if this work the same. :p
 
ehh found a wierd think?
when i click in the tile i wan't to create the monsters i get a katana? WTF?!?

23:15 You see stone flooring.
ItemID: [431].
ActionID: [9009].
UniqueID: [9009].
Position: [X: 33192] [Y: 31690] [Z: 14].

i'll try to delete action id 9009 maybe already in use in some noob quest :p
 
[13/11/2008 23:21:46] Lua Script Error: [MoveEvents Interface]
[13/11/2008 23:21:46] data/movements/scripts/walking.lua:eek:nStepIn

[13/11/2008 23:21:46] attempt to index a number value
[13/11/2008 23:21:46] stack traceback:
[13/11/2008 23:21:46] [C]: in function 'doSummonCreature'
[13/11/2008 23:21:46] data/movements/scripts/walking.lua:15: in function <data/movements/scripts/walking.lua


error after last script
 
Code:
function onStepIn(cid, position, fromPosition)
	local ajaja = {
		["Demon"] = {x=219, y=564, z=6}, ["Troll"] = {x=220, y=564, z=6}, ["Rotworm"] = {x=221, y=564, z=6},
		["Goblin"] = {x=219, y=565, z=6}, ["Rat"] = {x=221, y=565, z=6}, ["Bug"] = {x=219, y=566, z=6}
	}
	if item.uid == 9009 then
		if isPlayer(cid) == TRUE then
			for k, v in pairs(ajaja) do
				doSummonCreature(k, v)
			end
		end
	end
    return TRUE
end

Note: It doesnt want to summon the monsters with the same name (["Key"]).
 
PHP:
function onStepIn(cid, item, pos)
    local critters = {
        [1] = {x = 1000, y = 1024, z = 6, c = "Demon"},
        [2] = {x = 1002, y = 1024, z = 6, c = "Demon"},
        [3] = {x = 1004, y = 1024, z = 6, c = "Rat"},
        [4] = {x = 1000, y = 1026, z = 6, c = "Bug"},
        [5] = {x = 1002, y = 1026, z = 6, c = "Rotworm"},
        [6] = {x = 1004, y = 1026, z = 6, c = "Dragon"}
    }
    if item.uid == 9009 then
        if isPlayer(cid) == TRUE then
            for i = 1, table.maxn(critters) do
                doSummonCreature(critters[i].c, {x = critters[i].x, y = critters[i].y, z = critters[i].z})
            end
        end
    end
    return TRUE
end
This way you can use several of the same critters. :- )

EDIT:
Added a time-check so they can only spawn the critters each $x seconds (to prevent mass-spawning).
PHP:
function onStepIn(cid, item, pos)

    local seconds  = 30
    local critters = {
        [1] = {x = 1000, y = 1024, z = 6, c = "Demon"},
        [2] = {x = 1002, y = 1024, z = 6, c = "Demon"},
        [3] = {x = 1004, y = 1024, z = 6, c = "Rat"},
        [4] = {x = 1000, y = 1026, z = 6, c = "Bug"},
        [5] = {x = 1002, y = 1026, z = 6, c = "Rotworm"},
        [6] = {x = 1004, y = 1026, z = 6, c = "Dragon"}
    }
    
    
    if item.uid == 9009 and item.actionid ~= 9009 then
        if isPlayer(cid) == TRUE then
            doSetItemActionId(item.uid, 9009)
            addEvent(goNormal, 1000 * seconds, {item = item.uid})
            for i = 1, table.maxn(critters) do
                doSummonCreature(critters[i].c, {x = critters[i].x, y = critters[i].y, z = critters[i].z})
            end
        end
    end
    return TRUE
end

function goNormal(parameters)
    local item = parameters.item
    doSetItemActionId(item, 0)
end
 
Last edited:
Code:
                doSetItemActionId(item.uid, 9009)
                addEvent(goNormal, 1000 * seconds, {item = item.uid})

Put those above for i = ...
now you are setting the actionid and adding event few times, depending on table size.
 
Awesome support guys! you both will get Rep by me :)

One last thing about this..

tha last script that you posted work fine with 6 spawning monster, but when i try to add 7 monster i got errors again :(


Erros : [14/11/2008 16:46:37] Warning: [Event::loadScript] Can not load script. data/movements/scripts/walkon.lua
[14/11/2008 16:46:37] data/movements/scripts/walkon.lua:11: '}' expected (to close '{' at line 4) near '['



And as you can see here i only changed one thing

function onStepIn(cid, item, pos)

local seconds = 30
local critters = {
[1] = {x = 33197, y = 31697, z = 11, c = "Annihilon"},
[2] = {x = 33163, y = 31728, z = 11, c = "Ushuriel"},
[3] = {x = 33234, y = 31731, z = 11, c = "Golgordan"},
[4] = {x = 33229, y = 31731, z = 11, c = "Latrivan"},
[5] = {x = 33128, y = 31692, z = 11, c = "Zugurosh"},
[6] = {x = 33104, y = 31731, z = 11, c = "Hellgorak"}
[7] = {x = 33197, y = 31764, z = 11, c = "Madareth"}
}


if item.uid == 9009 and item.actionid ~= 9009 then
if isPlayer(cid) == TRUE then
doSetItemActionId(item.uid, 9009)
addEvent(goNormal, 1000 * seconds, {item = item.uid})
for i = 1, table.maxn(critters) do
doSummonCreature(critters.c, {x = critters.x, y = critters.y, z = critters.z})
end
end
end
return TRUE
end

function goNormal(parameters)
local item = parameters.item
doSetItemActionId(item, 0)
end
 
Back
Top