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

[APCL] Awsome player class lib v.1.0 - Like revscripts!

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
Hello! This is one of the most awsome codes i have released in all my life! This lib will help too many begginer scripters and too many anothers. This lib you can do it:
Code:
local user = Player:new(cid)
print(user.health)
Okay mock, you're awsome, my mother can do a table and sho the player health ¬¬'
Yes! but if the playes has the health changed and we use the SAME table (lets call object) it will print the current player health!
Okay, you are using loops to check every seconds! LAGS!
No i'm not... And no one source chenge ;D
And if you do it:
Code:
user.health = 100
the player health will go to 100 :D
OMG THIS IS POSSIBLE?
Yes! Also you can do:
Code:
user.health = 100 -- the same of the another
user.addhealth(100) -- same...

user:domove(0)
I will explain if my english let it '-'
Well the class got a bit syntax:
[OBJ]:[METHOD][VALUE](PARAMS)

How you can see the OBJ is the var returned by the Player:new. the Methos can be add do or get. But use something like user.gethealth() is useless, you can use user.health (because if the mewthos was nil the code use the defaut methos, and it is the GET)
Examples:
Code:
user:addhealth(10)
user:domove(0)
user:gethealth()
Remenber! IN ALL CASES EXCEPT GET YOU HAVE TO USE : and (). Inside the () you put the params if necessary...
Code:
user:dosay('hello',TALKTYPE_YELL)

If you can see, the lib only take the defaut lua functions and set the FIRST param (#1) to cid. But this methos is usefull only on get and set.

The set methos id like:
[OBJ].[VALUE] = [VAR]
And then:
Code:
user.health = 100
user.position = {x=300,y=200,z=5}
In some cases like storage value you can use:
Code:
user:setPack(100)
user.storage = 4911
^this code set the storage 4911 to value 100

You can use the lib like this way better:
Code:
user:doCreatureSay('hail',3)
user:doSetPlayerStorageValue(43911,100)
user:print('omg')
user:doRemoveCreature()

This lib work with ALL lua functions in your otserv. The method
[OBJ]:[FUNC]([PARAM])


If you dont belive try by yourself!


Run this code:
Code:
function health(user)
     print(user.health)
     user.health=1000
     addEvent(health,5000,user)
end
function onSay(cid, words, param, channel)
        local user = Player:new(cid)
        print(user.health)
        user.health=1000
        addEvent(health,5000,user)
	return TRUE
end


:w00t::w00t::w00t::w00t: I think it worked and you said OMG!

Well now lets install this lib.
Only create an file on data/lib and add this content:
Lua:
--[[
		~ * ~ Player Class v 1.0 ~ * ~
					By Mock the Bear
MTB

	*Global info:
		-With this lib you create a player object
		-with this object you can change almost all
		-player status like health mana pos etc...
	*Use:
		-First you have to create the class
		- 	local user = Player:new(cid)
		-And then you can use like:
		- 	print(user.health)
		-I the player got 1k of health it will
		-print 1000, and if the player lose like
		-150 health in combat and you print aigan
		-it shows 850.
		-Also you can change the health like:
		-	user.health = 100
		-Or:
		- 	user.addhealth(100)
		-	-- The same
		-   user:addhealth(100)
		-Like:
		- 	user:domove(0)
		-The syntax is:
		-	[OBJ]:[METHOD][VALUE](PARAMS)
		-	user:addhealth(10)
		-	user:domove(0)
		-	user:gethealth()
		-The method get do not need use like as function
		-you can use only user.health because method get is defaut.
		-The avaliable methods is DO ADD and GET
		-The set method is only to events like
		-	user.health = 100
		-If you need change the pos (using teleport in set method)
		-and need one more param use like:
		-	user:setPack(false)
		-	user.position = {x=300,y=200,z=5}
		-To understand better lets think in another function
		-Like setPlayerStorageValue
		-   user:setPack(100)
		- 	user.storage = 4911
		-This code will set the storage value 4911 to value 100
		-And then if you need you can just use like:
		-	user:doMoveCreature(0)
		- 	user:setPlayerStorageValue(4911,100)
		-You can use in ALL functions (works in your self made funcs),
		-the code set the ard #1 to cid and call the function.

	Contact: [email][email protected][/email]


]]
Player = {debug=false,n=0,cid={},defaut='get'}
---Compat some funcions~
function doCreatureSetHealth(cid,h,...)
	local now = getCreatureHealth(cid)
	doCreatureAddHealth(cid,h-now)
end
function doCreatureSetMana(cid,h)
	local now = doCreatureSetMana(cid)
	doPlayerAddMana(cid,h-now)
end
---Get,do,add can be used as print(player.health), player.domove(1) or player.addhealth(100))
Player.get = { --
	--Health
	['health'] 			= getCreatureHealth,
	['maxhealth']		= getCreatureMaxHealth,
	--Mana
	['mana'] 			= getCreatureMana,
	['maxmana'] 		= getCreatureMaxMana,
	['requiredmana']	= getPlayerRequiredMana,
	['spentmana'] 		= getPlayerSpentMana,
	--ETC
	['position']		= getCreaturePosition,
	['rates'] 			= getPlayerRates,
	['stamina'] 		= getPlayerStamina,
	['storage'] 		= getPlayerStorageValue,
	['town'] 			= getPlayerTown,
	['vocation'] 		= getPlayerVocation,
	['voc'] 			= getPlayerVocation,
	['weapon'] 			= getPlayerWeapon,
	['target'] 			= getCreatureTarget,
	['summons'] 		= getCreatureSummons,
	['speed'] 			= getCreatureSpeed,
	['skull'] 			= getCreatureSkull,
	['outfit'] 			= getCreatureOutfit,
	['nomove'] 			= getCreatureNoMove,
	['name'] 			= getCreatureName,
	['lookdir'] 		= getCreatureLookDirection,
	['lastpos'] 		= getCreatureLastPosition,
	['condition'] 		= getCreatureCondition,
	['basespeed'] 		= getCreatureBaseSpeed,
	['access'] 			= getPlayerAccess,
	['account'] 		= getPlayerAccount,
	['accountid'] 		= getPlayerAccountId,
	['blessing'] 		= getPlayerBlessing,
	['depotitems'] 		= getPlayerDepotItems,
	['exp'] 			= getPlayerExperience,
	['flag'] 			= getPlayerFlagValue,
	['food'] 			= getPlayerFood,
	['freecap'] 		= getPlayerFreeCap,
	['guid'] 			= getPlayerGUID,
	['groupid'] 		= getPlayerGroupId,
	['guildid'] 		= getPlayerGuildId,
	['guildlvl'] 		= getPlayerGuildLevel,
	['guildname'] 		= getPlayerGuildName,
	['guildnick'] 		= getPlayerGuildNick,
	['guildrank'] 		= getPlayerGuildRank,
	['guildrankid'] 	= getPlayerGuildRankId,
	['idle'] 			= getPlayerIdleTime,
	['ip'] 				= getPlayerIp,
	['instantcount'] 	= getPlayerInstantSpellCount,
	['itembyid'] 		= getPlayerItemById,
	['itemcount'] 		= getPlayerItemCount,
	['lastload'] 		= getPlayerLastLoad,
	['lastlogin'] 		= getPlayerLastLogin,
	['lastsave'] 		= getPlayerLastLoginSaved,
	['masterpos'] 		= getPlayerMasterPos,
	['skill'] 			= getPlayerSkill,
	['skilllevel'] 		= getPlayerSkillLevel,
	['skilltries']		= getPlayerSkillTries,
	['skullend'] 		= getPlayerSkullEnd,
	['skulltype'] 		= getPlayerSkullType,
	['slotitem'] 		= getPlayerSlotItem,
	['soul'] 			= getPlayerSoul,
}
Player.add = {
	['health'] 			= doCreatureAddHealth,
	['mana']			= doPlayerAddMana,
	['spentmana']		= doPlayerAddSpentMana,
	['addons'] 			= doPlayerAddAddons,
	['bless'] 			= doPlayerAddBlessing,
	['blessing'] 		= doPlayerAddBlessing,
	['exp'] 			= doPlayerAddExperience,
	['item'] 			= doPlayerAddItem,
	['itemex'] 			= doPlayerAddItemEx,
	['level']			= doPlayerAddLevel,
	['maglevel']		= doPlayerAddMagLevel,
	['mapmark'] 		= doPlayerAddMapMark,
	['outfit'] 			= doPlayerAddOutfit,
	['skill'] 			= doPlayerAddSkill,
	['skilltry'] 		= doPlayerAddSkillTry,
	['soul'] 			= doPlayerAddSoul,
	['spell'] 			= doPlayerAddSpell,
	['stamina'] 		= doPlayerAddStamina,
	['feed'] 			= doPlayerFeed,
	['joinparty'] 		= doPlayerJoinParty,
	['learnspell'] 		= doPlayerLearnInstantSpell,
	['fyi'] 			= doPlayerPopupFYI,
	['removeoutfit'] 	= doPlayerRemOutfit,
	['removeitem'] 		= doPlayerRemoveItem,
	['resetidle'] 		= doPlayerResetIdleTime,



	['money'] 			= function(cid,amn,...) if amn > 0 then return doPlayerAddMoney(cid,amn,...) else return doPlayerRemoveMoney(cid,amn,...) end end,
	['premdays'] 		= function(cid,amn,...) if amn > 0 then return doPlayerAddPremiumDays(cid,amn,...) else return doPlayerRemovePremiumDays(cid,amn,...) end end,


}
Player['do'] = {
	['move'] 			= doMoveCreature,
	['summom'] 			= doSummonCreature,
	['remove'] 			= doRemoveCreature,
	['say'] 			= doCreatureSay,
	['mute'] 			= doMutePlayer,
	['broadcast'] 		= doPlayerBroadcastMessage,
	['buyitem'] 		= doPlayerBuyItem,
	['buyitemcontainer']= doPlayerBuyItemContainer,
	['save'] 			= doPlayerSave,
	['sendcancel'] 		= doPlayerSendCancel,
	['cancel'] 			= doPlayerSendCancel,
	['channelmessage'] 	= doPlayerSendChannelMessage,
	['defautcancel'] 	= doPlayerSendDefaultCancel,
	['outfitwindow'] 	= doPlayerSendOutfitWindow,
	['textmessage'] 	= doPlayerSendTextMessage,
	['message'] 		= doPlayerSendTextMessage,
	['tutorial'] 		= doPlayerSendTutorial,
	['removeaccban'] 	= doRemoveAccountBanishment,
	['removecondition']	= doRemoveCondition,
	['removeconditions']= doRemoveConditions,

}

---Set can be used like: player.health = 1000
Player.set = {
	--Health
	['health'] 			= doCreatureSetHealth,
	['maxhealth']		= setCreatureMaxHealth,
	--Mana
	['mana'] 			= doCreatureSetHealth,
	['maxmana']			= setCreatureMaxMana,
	--Etc
	['position']		= doTeleportThing,
	['outfit'] 			= doSetCreatureOutfit,
	['light'] 			= doSetCreatureLight,
	['skull'] 			= doCreatureSetSkullType,
	['nomove'] 			= doCreatureSetNoMove,
	['lookdir'] 		= doCreatureSetLookDirection,
	['dir'] 			= doCreatureSetLookDirection,
	['changeoutfit'] 	= doCreatureChangeOutfit,
	['idle'] 			= doPlayerSetIdleTime,
	['level'] 			= doPlayerSetLevel,
	['exprate'] 		= doPlayerSetExperienceRate,
	['groupid'] 		= doPlayerSetGroupId,
	['guildid'] 		= doPlayerSetGuildId,
	['guildlevel'] 		= doPlayerSetGuildLevel,
	['guildnick'] 		= doPlayerSetGuildNick,
	['losspercentlevel']= doPlayerSetLossPercent,
	['losspercentskill']= doPlayerSetLossSkill,
	['magicrate'] 		= doPlayerSetMagicRate,
	['maxcap'] 			= doPlayerSetMaxCapacity,
	['rate'] 			= doPlayerSetRate,
	['sex'] 			= doPlayerSetSex,
	['skillrate'] 		= doPlayerSetSkillRate,
	['skullend']		= doPlayerSetSkullEnd,
	['stamina'] 		= doPlayerSetStamina,
	['storage'] 		= doPlayerSetStorageValue,
	['town'] 			= doPlayerSetTown,
	['vocation'] 		= doPlayerSetVocation,



}
function table.skipOne(t)
	local tr = {}
	for i,b in pairs(t) do
		if not i ~= 1 then
			tr[i-1] = b
		end
	end
	return #tr ~= 0 and tr or {nil}
end
function Player:check(cid)
	if not isPlayer(cid) then
		self.cid[cid] = nil
		return false
	end
	return true
end
function Player:new(cid)
	assert(cid ,'Player not found')
	if self.cid[cid] then
		return self.cid[cid]
	end
	self.n = self.n+1
	local player={}
	local t_ = newproxy(true)
	local _t = player
	player = {}
	getmetatable(t_).cid = cid
	getmetatable(t_).pack = {}
	getmetatable(t_).mid = self.n
	getmetatable(t_).setPack = function(...)
		getmetatable(t_).packet = {}
		collectgarbage()
		getmetatable(t_).packet = table.skipOne({...})
	end
	getmetatable(t_).getPack  = function()
		local pack = getmetatable(t_).packet
		getmetatable(t_).packet = {}
		return pack
	end

	getmetatable(t_).pack = function(...)
		return {pack=true,unpack(table.skipOne({...}))}
	end
	getmetatable(t_).unpack = function(cid,pack_)
		if pack_ and #pack_ ~= 0 then
			pack_.pack = nil
			return cid,unpack(pack_)
		else
			return cid
		end
	end
	getmetatable(t_).__index = function (t,k,q)
        if self.debug then
			print("[PLAYER DEBUG] Ascess value: "..tostring(t).."[" .. tostring(k)..'] on player '..getCreatureName(getmetatable(t_).cid)..' - '..getmetatable(t_).cid,q)
		end
		if self:check(getmetatable(t_).cid) then
			if k == 'unpack' then
				return getmetatable(t_).unpack
			elseif k == 'pack' then
				return function(...)
					return getmetatable(t_).pack(...)
				end
			elseif k == 'getPack' then
				return getmetatable(t_).getPack()
			elseif k == 'setPack' then
				return function(...)
					return getmetatable(t_).setPack(...)
				end
			end

			local k_ = tostring(k):lower()
			if k_:sub(1,3) == 'get' then
				if Player.get[k_:sub(4,-1)] then
					return function(...)
						local v1 = table.skipOne({...})
						local v2 = getmetatable(t_).getPack()
						local ret = #v1 ~= 0 and v1 or v2
						return Player.get[k_:sub(4,-1)](getmetatable(t_).cid,unpack(ret))
					end
				end
			elseif k_:sub(1,3) == 'add' then
				if Player.add[k_:sub(4,-1)] then
					return function(...)
						local v1 = table.skipOne({...})
						local v2 = getmetatable(t_).getPack()
						local ret = #v1 ~= 0 and v1 or v2
						return Player.add[k_:sub(4,-1)](getmetatable(t_).cid,unpack(ret))
					end
				end
			elseif _G[k] then
				return function(...)
					local cid = getmetatable(t_).cid
					local npack = {...}
					local last = 0
					for i,b in pairs(npack) do
						last = i
						if i ~= 1 then
							npack[i-1] = b
						end
					end
					npack[last] = nil
					collectgarbage()
					return _G[k](cid,unpack(npack))
				end
			elseif k_:sub(1,2) == 'do' then
				if Player['do'][k_:sub(3,-1)] then
					return function(...)
						local v1 = table.skipOne({...})
						local v2 = getmetatable(t_).getPack()
						local ret = #v1 ~= 0 and v1 or v2
						return Player['do'][k_:sub(3,-1)](getmetatable(t_).cid,unpack(ret))
					end
				end
			else
				if Player[self.defaut][k_] then
					return Player[self.defaut][k_](getmetatable(t_).cid,unpack(getmetatable(t_).getPack()))
				else
					return _t[k]
				end
			end
			return _t[k]
		else
			return false
		end
	end
	getmetatable(t_).__newindex = function (t,k,v,...)
		if self:check(getmetatable(t_).cid) then
			if self.debug then
				print("[PLAYER DEBUG] Change k: "..tostring(t).."[" .. tostring(k)..'] = '..tostring(v)..' on player '..getCreatureName(getmetatable(t_).cid)..' - '..getmetatable(t_).cid)
			end
			if _t[k] then
				_t[k] = v
			else
				if Player.set[k:lower()] then
					Player.set[k:lower()](getmetatable(t_).unpack(getmetatable(t_).cid,v))
				else
					_t[k] = v
				end
			end
		end
    end
    setmetatable(player, getmetatable(t_))
	self.cid[cid] = player
	return player,self.n
end


Bugs fixed and features add!

You can use the command now like:
Lua:
U = Player:new(cid)
U.storage = U:pack(6544,25)
U.skillrate = U:pack(SKILLID,RATE)
--- ^ this is equal to
setPayerStorageValue(cid,6544,25)
doPlayerSetSkillRate(cid,SKILLID,RATE)

and please report bugs :(

Need contact me? mail me [email protected]
 
Last edited:
So, if i got you, ehm...
I can just do DB queries without the player off?
Example: user.health = 100, user.level = 1
Will make players hp 100 and make them level 1? o.o
 
So, if i got you, ehm...
I can just do DB queries without the player off?
Example: user.health = 100, user.level = 1
Will make players hp 100 and make them level 1? o.o

yes :D!
this lib get some pre defined indexes to call functions. So using the function doPlayerSetLevel as 'level' index and setHealth as 'health' index, yes you can do
Code:
local user = Player:new(cid)
user.health = 100
user.level = 1
BUT it not work on player offline. Every time the CID change you have to create a new object to a player.
^ the same code work at the same like this:
Code:
local user = Player:new(cid)
user:doCreatureSetHealth(100)
user:doPlayerSetLevel(1)

Maby in tfs are missing the function doPlayerSetLevel... if it was just tell me and i post it too.
 
A perfect simulation of RevScript
Rly good work and one of the mosts hard script that I saw here =o
I prefer make the scripts in the tradictional method but your is one of the bests.
This will make easy do scripts

thanks mock
 
Conde, the clean code is:
Lua:
function Player:check(cid)
	if not isPlayer(cid) then
		self.cid[cid] = nil
		return false
	end
	return true
end
function Player:new(cid)
	assert(cid ,'Player not found')
	if self.cid[cid] then
		return self.cid[cid]
	end
	self.n = self.n+1
	local player={}
	local t_ = newproxy(true)
	local _t = player
	player = {}
	getmetatable(t_).cid = cid
	getmetatable(t_).pack = {}
	getmetatable(t_).mid = self.n
	getmetatable(t_).setPack = function(...)
		getmetatable(t_).pack = {}
		collectgarbage()
		getmetatable(t_).pack = {...}
	end
	getmetatable(t_).getPack  = function()
		local pack = getmetatable(t_).pack
		getmetatable(t_).pack = {}
		return pack
	end
	getmetatable(t_).__index = function (t,k)
        if self.debug then
			print("[PLAYER DEBUG] Ascess value: "..tostring(t).."[" .. tostring(k)..'] on player '..getCreatureName(getmetatable(t_).cid)..' - '..getmetatable(t_).cid)
		end
		if self:check(getmetatable(t_).cid) then
			if k == 'getPack' then
				return getmetatable(t_).getPack()
			elseif k == 'setPack' then
				return function(...)
					return getmetatable(t_).setPack(...)
				end
			end
			local k_ = tostring(k):lower()
			if k_:sub(1,3) == 'get' then
				if Player.get[k_:sub(4,-1)] then
					return Player.get[k_:sub(4,-1)](getmetatable(t_).cid,unpack(getmetatable(t_).getPack()))
				end
			elseif k_:sub(1,3) == 'add' then
				if Player.add[k_:sub(4,-1)] then
					return function (...) return Player.add[k_:sub(4,-1)](getmetatable(t_).cid,unpack(getmetatable(t_).getPack())) end
				end
			elseif _G[k] then
				return function(...)
					local cid = getmetatable(t_).cid
					local npack = {...}
					local last = 0
					for i,b in pairs(npack) do
						last = i
						if i ~= 1 then
							npack[i-1] = b
						end
					end
					npack[last] = nil
					collectgarbage()
					return _G[k](cid,unpack(npack))
				end
			elseif k_:sub(1,2) == 'do' then
				if Player['do'][k_:sub(3,-1)] then
					print('line')
					return function(...) return Player['do'][k_:sub(3,-1)](getmetatable(t_).cid,...) end
				end
			else
				if Player[self.defaut][k_] then
					return Player[self.defaut][k_](getmetatable(t_).cid,unpack(getmetatable(t_).getPack()))
				else
					return _t[k]
				end
			end
			return _t[k]
		else
			return false
		end
	end
	getmetatable(t_).__newindex = function (t,k,v,...)
		if self:check(getmetatable(t_).cid) then
			if self.debug then
				print("[PLAYER DEBUG] Change k: "..tostring(t).."[" .. tostring(k)..'] = '..tostring(v)..' on player '..getCreatureName(getmetatable(t_).cid)..' - '..getmetatable(t_).cid)
			end
			if _t[k] then
				_t[k] = v
			else
				if Player.set[k:lower()] then
					local pack = getmetatable(t_).getPack()
					Player.set[k:lower()](getmetatable(t_).cid,v,unpack(pack))
				else
					_t[k] = v
				end
			end
		end
    end
    setmetatable(player, getmetatable(t_))
	self.cid[cid] = player
	return player,self.n
end

All the other things are credits and some vars :p
 
yes :D!
this lib get some pre defined indexes to call functions. So using the function doPlayerSetLevel as 'level' index and setHealth as 'health' index, yes you can do
Code:
local user = Player:new(cid)
user.health = 100
user.level = 1

OMGGGG , THIS IS JUST WHAT I NEEEDEDDDDDD
amo vc :A
so, player ONLINE, i can change his health, his level, everything?!!!?!?!?!? kkkkkkkkkkkk <3
 
OMGGGG , THIS IS JUST WHAT I NEEEDEDDDDDD
amo vc :A
so, player ONLINE, i can change his health, his level, everything?!!!?!?!?!? kkkkkkkkkkkk <3

not all
Lua:
Player.get = { --
	--Health
	['health'] = getCreatureHealth,
	['maxhealth'] = getCreatureMaxHealth,
	--Mana
	['mana'] = getCreatureMana,
	['maxmana'] = getCreatureMaxMana,
	['requiredmana'] = getPlayerRequiredMana,
	['spentmana'] = getPlayerSpentMana,
	--ETC
	['position'] = getCreaturePosition,
	['rates'] = getPlayerRates,
	['stamina'] = getPlayerStamina,
	['storage'] = getPlayerStorageValue,
	['town'] = getPlayerTown,
	['vocation'] = getPlayerVocation,
	['voc'] = getPlayerVocation,
	['weapon'] = getPlayerWeapon,
	['target'] = getCreatureTarget,
	['summons'] = getCreatureSummons,
	['speed'] = getCreatureSpeed,
	['skull'] = getCreatureSkull,
	['outfit'] = getCreatureOutfit,
	['nomove'] = getCreatureNoMove,
	['name'] = getCreatureName,
	['lookdir'] = getCreatureLookDirection,
	['lastpos'] = getCreatureLastPosition,
	['condition'] = getCreatureCondition,
	['basespeed'] = getCreatureBaseSpeed,
	['access'] = getPlayerAccess,
	['account'] = getPlayerAccount,
	['accountid'] = getPlayerAccountId,
	['blessing'] = getPlayerBlessing,
	['depotitems'] = getPlayerDepotItems,
	['exp'] = getPlayerExperience,
	['flag'] = getPlayerFlagValue,
	['food'] = getPlayerFood,
	['freecap'] = getPlayerFreeCap,
	['guid'] = getPlayerGUID,
	['groupid'] = getPlayerGroupId,
	['guildid'] = getPlayerGuildId,
	['guildlvl'] = getPlayerGuildLevel,
	['guildname'] = getPlayerGuildName,
	['guildnick'] = getPlayerGuildNick,
	['guildrank'] = getPlayerGuildRank,
	['guildrankid'] = getPlayerGuildRankId,
	['idle'] = getPlayerIdleTime,
	['ip'] = getPlayerIp,
	['instantcount'] = getPlayerInstantSpellCount,
	['itembyid'] = getPlayerItemById,
	['itemcount'] = getPlayerItemCount,
	['lastload'] = getPlayerLastLoad,
	['lastlogin'] = getPlayerLastLogin,
	['lastsave'] = getPlayerLastLoginSaved,
	['masterpos'] = getPlayerMasterPos,
	['skill'] = getPlayerSkill,
	['skilllevel'] = getPlayerSkillLevel,
	['skilltries'] = getPlayerSkillTries,
	['skullend'] = getPlayerSkullEnd,
	['skulltype'] = getPlayerSkullType,
	['slotitem'] = getPlayerSlotItem,
	['soul'] = getPlayerSoul,
}
Player.add = {
	['health'] = doCreatureAddHealth,
	['mana'] = doPlayerAddMana,
	['spentmana'] = doPlayerAddSpentMana,
	['addons'] = doPlayerAddAddons,
	['bless'] = doPlayerAddBlessing,
	['blessing'] = doPlayerAddBlessing,
	['exp'] = doPlayerAddExperience,
	['item'] = doPlayerAddItem,
	['itemex'] = doPlayerAddItemEx,
	['level'] = doPlayerAddLevel,
	['maglevel'] = doPlayerAddMagLevel,
	['mapmark'] = doPlayerAddMapMark,
	['outfit'] = doPlayerAddOutfit,
	['skill'] = doPlayerAddSkill,
	['skilltry'] = doPlayerAddSkillTry,
	['soul'] = doPlayerAddSoul,
	['spell'] = doPlayerAddSpell,
	['stamina'] = doPlayerAddStamina,
	['feed'] = doPlayerFeed,
	['joinparty'] = doPlayerJoinParty,
	['learnspell'] = doPlayerLearnInstantSpell,
	['fyi'] = doPlayerPopupFYI,
	['removeoutfit'] = doPlayerRemOutfit,
	['removeitem'] = doPlayerRemoveItem,
	['resetidle'] = doPlayerResetIdleTime,
 
 
 
	['money'] = function(cid,amn,...) if amn > 0 then return doPlayerAddMoney(cid,amn,...) else return doPlayerRemoveMoney(cid,amn,...) end end,
	['premdays'] = function(cid,amn,...) if amn > 0 then return doPlayerAddPremiumDays(cid,amn,...) else return doPlayerRemovePremiumDays(cid,amn,...) end end,
 
 
}
Player['do'] = {
	['move'] = doMoveCreature,
	['summom'] = doSummonCreature,
	['remove'] = doRemoveCreature,
	['say'] = doCreatureSay,
	['mute'] = doMutePlayer,
	['broadcast'] = doPlayerBroadcastMessage,
	['buyitem'] = doPlayerBuyItem,
	['buyitemcontainer']= doPlayerBuyItemContainer,
	['save'] = doPlayerSave,
	['sendcancel'] = doPlayerSendCancel,
	['cancel'] = doPlayerSendCancel,
	['channelmessage'] = doPlayerSendChannelMessage,
	['defautcancel'] = doPlayerSendDefaultCancel,
	['outfitwindow'] = doPlayerSendOutfitWindow,
	['textmessage'] = doPlayerSendTextMessage,
	['message'] = doPlayerSendTextMessage,
	['tutorial'] = doPlayerSendTutorial,
	['removeaccban'] = doRemoveAccountBanishment,
	['removecondition'] = doRemoveCondition,
	['removeconditions']= doRemoveConditions,
 
}
 
---Set can be used like: player.health = 1000
Player.set = {
	--Health
	['health'] = doCreatureSetHealth,
	['maxhealth'] = setCreatureMaxHealth,
	--Mana
	['mana'] = doCreatureSetHealth,
	['maxmana'] = setCreatureMaxMana,
	--Etc
	['position'] = doTeleportThing,
	['outfit'] = doSetCreatureOutfit,
	['light'] = doSetCreatureLight,
	['skull'] = doCreatureSetSkullType,
	['nomove'] = doCreatureSetNoMove,
	['lookdir'] = doCreatureSetLookDirection,
	['dir'] = doCreatureSetLookDirection,
	['changeoutfit'] = doCreatureChangeOutfit,
	['idle'] = doPlayerSetIdleTime,
	['level'] = doPlayerSetLevel,
	['exprate'] = doPlayerSetExperienceRate,
	['groupid'] = doPlayerSetGroupId,
	['guildid'] = doPlayerSetGuildId,
	['guildlevel'] = doPlayerSetGuildLevel,
	['guildnick'] = doPlayerSetGuildNick,
	['losspercentlevel']= doPlayerSetLossPercent,
	['losspercentskill']= doPlayerSetLossSkill,
	['magicrate'] = doPlayerSetMagicRate,
	['maxcap'] = doPlayerSetMaxCapacity,
	['rate'] = doPlayerSetRate,
	['sex'] = doPlayerSetSex,
	['skillrate'] = doPlayerSetSkillRate,
	['skullend'] = doPlayerSetSkullEnd,
	['stamina'] = doPlayerSetStamina,
	['storage'] = doPlayerSetStorageValue,
	['town'] = doPlayerSetTown,
	['vocation'] = doPlayerSetVocation,
 
 
 
}

You can do anything inside this table limitations.
In case to do table you run:
user:domove
in case GET only
return user.position
In case ADD use:
user.addhealth = 100
if you need one more param in Add use:
user.setPack(trith param)
user.addfunc = 10

and get only:
print(user.health)


a bit fixed on script :p a little error update the code...
 
Nice code, i did something like that some time ago but never went so deep. Metamethods are probably the most powerfull tools that Lua can offer.
 
Nice work little bear :D

That's really going to make scripting easier =)

Well, that's the proof that bears have inteligence. Há, suck, cientists! \../
 
Bugs fixed and features add!

You can use the command now like:
Lua:
U = Player:new(cid)
U.storage = U:pack(6544,25)
U.skillrate = U:pack(SKILLID,RATE)
--- ^ this is equal to
setPayerStorageValue(cid,6544,25)
doPlayerSetSkillRate(cid,SKILLID,RATE)

and please report bugs :(
 
Last edited:
Bugs and features add!

You can use the command now like:
Lua:
U = Player:new(cid)
U.storage = U:pack(6544,25)
U.skillrate = U:pack(SKILLID,RATE)
--- ^ this is equal to
setPayerStorageValue(cid,6544,25)
doPlayerSetSkillRate(cid,SKILLID,RATE)

and please report bugs :(

So.... it seems you have added bugs? :trollface
 
Back
Top