• 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 help fixing a script

Keiro

New Member
Joined
Jun 24, 2009
Messages
285
Reaction score
0
tfs 0.3.6sp1 ,
Hello , the quest is:

3 guys stand on 3 stone tiles, then use the switch, then they get teleported to a quest.....but if there is someone on the quest already, they wont be able to go in.

Lua:
    -- CONFIG --
  
       local step1 = {
      fromX = 1199,
      fromY = 1050,
      fromZ = 8,
        --------------
        toX = 1254,
        toY = 1104,
        toZ = 8
        }
  
        local playersOnly = "yes"
        local questLevel = 40

        local players_pos = {
        {x = 1118, y =1045, z = 7, stackpos = 253},
        {x = 1118, y =1046, z = 7, stackpos = 253},
        {x = 1118, y =1047, z = 7, stackpos = 253},
        }
 
        local new_player_pos = {
        {x = 1243, y = 1088, z = 8},
        {x = 1244, y = 1088, z = 8},
        {x = 1242, y = 1088, z = 8},
        }
        
        ------------------------------------------------------
        --- CONFIG END ---------------------------------------
        ------------------------------------------------------


function onUse(cid, item, fromPosition, itemEx, toPosition)
       local all_ready, player, level = 0, 0, {}, 0
        if item.itemid == 1945 then
        doPlayerSendTextMessage(cid,19,"kk2.")  
        
                for i = 1, #players_pos do
                        table.insert(player, 0)
                end--forend
                for i = 1, #players_pos do
                        player[i] = getThingfromPos(players_pos[i])
                        if player[i].itemid > 0 then
                                if string.lower(playersOnly) == "yes" then
                                        if isPlayer(player[i].uid) == TRUE then
                                                all_ready = all_ready+1
                                        else
                                              monsters = monsters+1
                                        end--bn
                                else
                                        all_ready = all_ready+1
                                end--bn
                        end--bn
                end--bn
                if all_ready == #players_pos then
                    for i = 1, #players_pos do
                    player[i] = getThingfromPos(players_pos[i])
                         if isPlayer(player[i].uid) == TRUE then
                            if getPlayerLevel(player[i].uid) >= questLevel then
                                level = level+1
                            end --bn
                         else
                           level = level+1
                         end--bn
                    end--bn
                          if level == #players_pos then
                                if string.lower(playersOnly) == "yes" and monsters == 0 or string.lower(playersOnly) == "no" then 
                                        for i = 1, #players_pos do
                                                doSendMagicEffect(players_pos[i], CONST_ME_POFF)
                                                doTeleportThing(player[i].uid, new_player_pos[i], FALSE)
                                                doSendMagicEffect(new_player_pos[i], CONST_ME_ENERGYAREA)
                                                doTransformItem(item.uid,1946)
                                        end--bn
                                else
                                        doPlayerSendTextMessage(cid,19,"Only players can do this quest.")
                                end--bn
                        else
                                doPlayerSendTextMessage(cid,19,"All Players have to be level "..questLevel.." to do this quest.")
                        end--bn
                else
                        doPlayerSendTextMessage(cid,19,"You need "..table.getn(players_pos).." players to do this quest.")
                end--bn
                

     elseif item.itemid == 1946 then
     doPlayerSendTextMessage(cid,19,"kk1")  
                local player_room = 0
                --bien1--
                for x = step1.fromX, step1.toX do
                        for y = step1.fromY, step1.toY do
                for z = step1.fromZ, step1.toZ do
                    local pos = {x=x, y=y, z=z,stackpos = 253}
                    local thing = getThingfromPos(pos)
                    if thing.itemid > 0 then
                        if isPlayer(thing.uid) == TRUE then
                            player_room = player_room+1
                        end
                    end
                end
                end
                
                --bien1--
       end --end del primer for
end--end del primer if
                
                           
                
                if player_room >= 3 then
                        doPlayerSendTextMessage(cid,19,"There is already a team in the quest room.")           
                elseif player_room == 0 then
            
                        doTransformItem(item.uid,1945)
                        else
                        doPlayerSendTextMessage(cid,19,"Tasdfasdom.")  
                end
       
        return TRUE
end

error on console:
[16/03/2011 12:43:56] [Error - Action Interface]
[16/03/2011 12:43:56] data/actions/scripts/quests/questlvl40.lua:eek:nUse
[16/03/2011 12:43:56] Description:
[16/03/2011 12:43:56] data/actions/scripts/quests/questlvl40.lua:42: bad argument #1 to 'insert' (table expected, got number)
[16/03/2011 12:43:56] stack traceback:
[16/03/2011 12:43:56] [C]: in function 'insert'
[16/03/2011 12:43:56] data/actions/scripts/quests/questlvl40.lua:42: in function <data/actions/scripts/quests/questlvl40.lua:36>

[16/03/2011 12:43:57] [Error - Action Interface]
[16/03/2011 12:43:57] data/actions/scripts/quests/questlvl40.lua:eek:nUse
[16/03/2011 12:43:57] Description:
[16/03/2011 12:43:57] data/actions/scripts/quests/questlvl40.lua:111: attempt to compare number with nil
[16/03/2011 12:43:57] stack traceback:
[16/03/2011 12:43:57] data/actions/scripts/quests/questlvl40.lua:111: in function <data/actions/scripts/quests/questlvl40.lua:36>
 
Last edited:
Lua:
local from={x=1199, y=1050, z=8}
local to={x=1254, y=1104, z=8}

local playerA={
	{x=1118, y=1045, z=7},
	{x=1118, y=1046, z=7},
	{x=1118, y=1047, z=7}
}
local playerB={
	{x=1243, y=1088, z=8},
	{x=1244, y=1088, z=8},
	{x=1242, y=1088, z=8}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local t = {}
	if item.itemid == 1945 then
		for i = 1, 3 do
			t[i]=getTopCreature(playerA[i]).uid
			if t[i] == 0 or not isPlayer(t[i]) then
				return doPlayerSendCancel(cid, 'You need 3 players for this quest.')
			elseif getPlayerLevel(t[i]) < 40 then
				return doPlayerSendCancel(cid, 'All players need to have level 40 or higher.')
			end
		end
		for i = 1, 3 do
			doTeleportThing(t[i], playerB[i])
			doSendMagicEffect(playerA[i], CONST_ME_POFF)
			doSendMagicEffect(playerB[i], CONST_ME_ENERGYAREA)
		end
	else
		for x = from.x, to.x do
			for y = from.y, to.y do
				local v = getTopCreature({x=x, y=y, z=from.z}).uid
				if v ~= 0 and isPlayer(v) then
					return doPlayerSendCancel(cid, 'There is already a team in the quest room.')
				end
			end
		end
	end
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
how many times do i have to rewrite the same script because you keep using the bad versions -_-
 
if im not wrong it doesnt check if there is ppl or not, before letting them go inside , it just chck it, if switch is activated, right?
 
but you can't pull it back if there's still someone inside, and it has to be pulled back first if another team wants to go in.
 
im trying to test it but with one player, so i changed 3 for 1

if item.itemid == 1945 then
for i = 1, 1 do
t=getTopCreature(playerA).uid
if t == 0 or not isPlayer(t) then
return doPlayerSendCancel(cid, 'You need 3 players for this quest.')
elseif getPlayerLevel(t) < 40 then
return doPlayerSendCancel(cid, 'All players need to have level 40 or higher.')
end

and it says "you need 3 players for thsi quest" , i dont udnerstand why

maybe t[] not working properly? or maybe my msitake, i know im not good ;C


edit, no , t for i = 1, is 0 , thats why it enters the if , now i wonder why o_O


kk no , the problem is it doesnt "find me" as a player i guyess...

i tested this
Lua:
for i = 1, 1 do
            t[i]=getTopCreature(playerA[i]).uid
            if isPlayer(t[i]) then            
                return doPlayerSendCancel(cid, 'You need 3 players for this quest.')
            elseif getPlayerLevel(t[i]) < 40 then
                return doPlayerSendCancel(cid, 'All players need to have level 40 or higher.')
            end
        end

and it does nothing, it doesnt enter any of them
 
Last edited:
Lua:
for i = 1, 3 do
while i == 1 do
            t[i]=getTopCreature(playerA[i]).uid
            if isPlayer(t[i]) then            
                return doPlayerSendCancel(cid, 'You need 3 players for this quest.')
            elseif getPlayerLevel(t[i]) < 40 then
                return doPlayerSendCancel(cid, 'All players need to have level 40 or higher.')
            end
i=2
        end
end

then turn back after test...
 
Back
Top