• 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 wont properly randomize

Jgarder

Tprogramming Ex-Adm|n
Premium User
Joined
Jun 7, 2007
Messages
355
Reaction score
4
Location
Michigan
everything works on this script.. except that it wont randomize where its warp location is.. the portalPos i have defined at the start is just to be a fail safe.. but the script still refuses to set a random location.

PHP:
-- -- By jgarder
function onUse(cid, item, frompos, item2, topos)
	local warzone = {     [1] = {name = "Aurora Island", fromPos = {x=908, y=601, z=4}, toPos = {x=958, y=642, z=8}}, }
	local post = getThingPosition(cid)
	local storage = 15100
	local portalPos = {x=943, y=611, z=7, stackpos=1}	
	setPlayerStorageValue(cid,storage, 0)
	
	local rand1 = math.random(943, 953)
	local rand2 = math.random(612, 618)

	if isInRange(getThingPosition(cid), warzone[1].fromPos, warzone[1].toPos) then 
			local portalPos = {x=rand1, y=rand2, z=7, stackpos=1}
	
	else 
			local portalPos = {x=rand1, y=rand2, z=7, stackpos=1}
			doPlayerSendTextMessage(cid,22, "You are not on Aurora Island")
	end
	
	
		if 1==2 then
			doPlayerSendCancel(cid, "You cannot create a portal in the same place you are going to!")
		return TRUE
		end
	
			if(getPlayerStorageValue(cid, 15100) ~= 1) and (getTilePzInfo(getThingPosition(cid)) == false) then
				if (isInRange(getThingPosition(cid), warzone[1].fromPos,warzone[1].toPos) == true) then
					local portal = doCreateTeleport(1387, portalPos, post)
					local a = {cid=cid, storage=storage, post=post}
					doPlayerSendTextMessage(cid,22,"You have used The Aurora Portal.")
					doTeleportThing(cid, portalPos, FALSE)
					setPlayerStorageValue(a.cid, a.storage, 1)	
					addEvent(removePortal, 10000, a)
				else
					doPlayerSendTextMessage(cid,22, "You are not on Aurora Island")
				end

			else
				doPlayerSendCancel(cid, "You already have a portal.")
			end
end

function removePortal(a)
	local rpost = getTileItemByType(a.post, ITEM_TYPE_TELEPORT)
		doRemoveItem(rpost.uid, 1)
		setPlayerStorageValue(a.cid, a.storage, 0)
	end
 
learn to use the fucking variables u specified..
Code:
local warZone = {
	fromPos = {x=908, y=601, z=4},
	toPos = {x=958, y=642, z=8},
	name = "Aurora Island"
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local pos, storage, portalPos =
		getThingPos(cid),
		15100,
		{}
	if isInRange(getThingPos(cid), warZone.fromPos, warZone.toPos) then
		portalPos = {x = warZone.fromPos.x[math.random(1, #warZone.fromPos.x)], y = warZone.toPos.y[math.random(1, #warZone.toPos.y)], z = warZone.fromPos.z[math.random(1, #warZone.fromPos.z)]}
		if getPlayerStorageValue(cid, storage) ~= 1 and not getTilePzInfo(pos) then
			doCreateTeleport(1387, portalPos, pos)
			doPlayerSendTextMessage(cid,22,"You have used The " .. warZone.name:gsub("(%d)(%d)(%d)", "%1%2%3%4%5") .. " Portal.") 
			doTeleportThing(cid, portalPos, false)
			local it = getTileItemById(portalPos, 1387).uid
			if it > 0 then
				addEvent(doRemoveItem, 10000, it)
			end
		else
			doPlayerSendCancel(cid, "You already have a portal.") 
		end
	else
		doPlayerSendTextMessage(cid,22, "You are not on " .. warZone.name) 
	end
	return true
end
 
Code:
-- By jgarder
local warzone = {
	{name = 'Aurora Island', fromPos = {x=908, y=601, z=4}, toPos = {x=958, y=642, z=8}}
}
local storage = 15100
local portalPos = {x=943, y=611, z=7}

local function removePortal(cid, post)
	local rpost = getTileItemById(post, 1387).uid
	doRemoveItem(rpost)
	setPlayerStorageValue(cid, storage, 0)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local post, _portalPos = getThingPos(cid), nil
	setPlayerStorageValue(cid, storage, 0)

	if isInRange(post, warzone[1].fromPos, warzone[1].toPos) then 
		_portalPos = {x=math.random(943, 953), y=math.random(612, 618), z=7}
	else 
		return doPlayerSendTextMessage(cid,22, 'You are not on Aurora Island')
	end

	if 1==2 then
		return doPlayerSendCancel(cid, 'You cannot create a portal in the same place you are going to!')
	end

	if getPlayerStorageValue(cid, storage) ~= 1 then
		if not getTilePzInfo(post) then
			doPlayerSendTextMessage(cid, 22, 'You have used The Aurora Portal.')
			doTeleportThing(cid, portalPos)
			doCreateTeleport(1387, portalPos, post)
			doSendMagicEffect(post, CONST_ME_MAGIC_BLUE)
			doSendMagicEffect(portalPos, CONST_ME_TELEPORT)
			setPlayerStorageValue(cid, storage, 1)    
			addEvent(removePortal, 10000, cid, post)
		else
			doPlayerSendCancel(cid, 'You cannot create a portal in protection zones.')
		end
	else
		doPlayerSendCancel(cid, 'You already have a portal.')
	end
	return true
end
 
learn to use the fucking variables u specified..


I'm giving this the ol' college try here, I don't know much. got a good place to start for lua programming? OT specific or not really~... Btw im Repping you both for helping with noob scripts like mine
 
Back
Top