• 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 What is wrong with this "minimum level" script?

Hellrage

Worr
Joined
Oct 30, 2007
Messages
2,477
Reaction score
5
Location
Sweden
Hello. This script is supposed to:

1. Restore level to 70 if player is below that level.
2. Add equipment + supplies upon death or first login.

Only second part is working, why?

Note: I didn't post all item arrays for each vocation. That part is already working.

Lua:
function onLogin(cid)
	if getPlayerLevel(cid) < 70 then
		doPlayerAddExperience(cid, getExperienceForLevel(70) - getPlayerExperience(cid))
		doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You can\'t downgrade below level 70.')
	end
			if getPlayerStorageValue(cid,1002) ~= 1 then
				setPlayerStorageValue(cid, 1001, 0)
				setPlayerStorageValue(cid, 1002, 1)
			end
			if getPlayerStorageValue(cid, 1001) == 0 then
				local items = defaultItems[getPlayerVocation(cid)]
				if getPlayerSlotItem(cid, 3).uid == 0 then
					local mainBackpack = doPlayerAddItem(cid, 1988, 1)
					for i = 1, #items do
						if (items[i].type == ITEM) then
							doAddContainerItem(mainBackpack, items[i].itemId, items[i].count)
						elseif (items[i].type == BACKPACK) then
							local bp = mainBackpack
							local bpInside = doAddContainerItem(bp, items[i].bpId, 1)
							for j=1, items[i].bpCount do
								bp = bpInside
								if (j < items[i].bpCount) then
									bpInside = doAddContainerItem(bp, items[i].bpId, 1)
								else
									doAddContainerItem(bp, items[i].itemId, items[i].count)
								end
								for j=1, 19 do
									doAddContainerItem(bp, items[i].itemId, items[i].count)
								end
							end
						elseif (items[i].type == ITEMS) then
							local bp = doAddContainerItem(mainBackpack, items[i].bpId, 1)
							for j=1, #items[i] do
								doAddContainerItem(bp, items[i][j].itemId, items[i][j].count)
							end
						end
					end
				end
				for i = 1, #items do
					if (items[i].type == SLOT) then
						if getPlayerSlotItem(cid, items[i].slotId).uid == 0 then
							doPlayerAddItem(cid, items[i].itemId, items[i].count)
						end
					end
				end
				setPlayerStorageValue(cid, 1001, 1)
			end
	--registerCreatureEvent(cid, "KillProtection")
	registerCreatureEvent(cid, "PlayerDeath")
 	return TRUE
end
 
Sweet. It worked. Cant rep you though. Is there any way to do this with magic level or skills to? Or do I need to edit sources for those kind of lua functions?

Also, in lua can I write

if getPlayerVocation(cid) = 5 || getPlayerVocation(cid) = 6 then

or i write

if getPlayerVocation(cid) = 5 or getPlayerVocation(cid) = 6 then

?
 
Lua:
if table.find({5,6}, getPlayerVocation(cid)) then
If you don't have function table.find, then add it from latest TFS or use this:
Lua:
if isInArray({5,6}, getPlayerVocation(cid)) == TRUE then
 
Back
Top Bottom