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

Why is this script not working? D:

Kombosabo

New Member
Joined
Jul 30, 2009
Messages
27
Reaction score
1
It should teleport the player to the desired location, but it's not doing as intended.
What can be wrong?



PHP:
modaldialog = {
	title = "Teleport",
	message = "Choose you destination",
	buttons = {
		{ id = 1, value = "OK" },
		{ id = 2, value = "CANCEL" },
	},
	buttonEnter = 1,
	buttonEscape = 2,
	choices = {
		{ id = 1, value = "Troll Cave (Level 8)" },
		{ id = 2, value = "Dragon Island (Level 50)" }
	},
	popup = true
}


function callback(cid, button, choice)
	--anything u want
	if (button == 1) then
		     if (choice == 1) then
					doTeleportThing(cid, {x=32493, y=32504, z=1}) -- Troll Cave
		     end
		     if (choice == 2) then
					if getPlayerLevel(cid) >= 100 then 
					doTeleportThing(cid, {x=32493, y=32504, z=1}) -- Dragon
				else
					doCreatureSayWithRadius(cid, "You need level 50 to teleport to that place.", TALKTYPE_ORANGE_1, 1, 1)	
	end
	end
	end
	end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	--struct, id, creature id, callback
	--NOTE:
	--	id should be unique id of all dialogs in whole scripts
	addDialog(modaldialog, 2345, cid, callback);
end
 
Version of server you use, a bit more information?
i am a bit rewrite code for you, and publish my modalDialogConstructor function, but, callback constructor - propietary, sorry, cant publish them, but you free to make them self.

PHP:
local config = {
caves = {
[1] = {id = 1, name = "Troll Cave", lvl = 8, pos = {x=32493, y=32504, z=1}},
[2] = {id = 2, name = "Dragon Island", lvl = 100, pos = {x=32493, y=32504, z=1}}
}
--TODO: Something else?
}

function modalDialogConstructor() --function by HappyDay(c)
tmpTable = {}
for i,x in ipairs(config.caves) do
tb = config.caves[i]
tmpLabel = tb.name .. "(Level: "..tb.lvl..")"
table.insert(tmpTable, choices = {id = tb.id, value = tmpLabel} )
end
table.insert(tmpTable,
title = "Teleport",
message = "Choose you destination",
buttonEnter = 1,
buttonEscape = 2,
buttons = {
{ id = 1, value = "OK" },
{ id = 2, value = "CANCEL" }
},
popup = true
)

return tmpTable
end

function callback(cid, button, choice)
    --anything u want
    if (button == 1) then
             if (choice == 1) then
              if getPlayerLevel(cid) >= config.caves[1].lvl then 
               doTeleportThing(cid, config.caves[1].pos) -- Trolls cave
              else
            doCreatureSayWithRadius(cid, "You need level "..config.caves[1].lvl.." to teleport to that place.", TALKTYPE_ORANGE_1, 1, 1)
			  end
			  end
             elseif (choice == 2) then
              if getPlayerLevel(cid) >= config.caves[2].lvl then 
               doTeleportThing(cid, config.caves[2].pos) -- Dragon
              else
           doCreatureSayWithRadius(cid, "You need level "..config.caves[2].lvl.." to teleport to that place.", TALKTYPE_ORANGE_1, 1, 1)    
             end
            end
    end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    --struct, id, creature id, callback
    --NOTE:
    --    id should be unique id of all dialogs in whole scripts
	window = modalDialogConstructor() -- that function create table for you
    addDialog(window, 2345, cid, callback);
end
So, one problem here - only selecting automatically actions for each caves from config table for callback, without that - you should code manually each response for you callback. Here you need to make a callback constructor for better and easy usage of script without additional coding in file.

Kind regards and good luck.
 
Last edited:
Back
Top