Resource:Exp system: Difference between revisions
(Created page with "<pageclass class="resource" subcaption="Resource"></pageclass> A level/experience system made from scratch by Castillo.<br> It uses SQLite to save level and exp...") |
(Double 'with') |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Resource page}} | |||
A level/experience system made from scratch by [[User:Castillo|Castillo]].<br> | A level/experience system made from scratch by [[User:Castillo|Castillo]].<br> | ||
It uses SQLite to save level and experience. | It uses SQLite to save level and experience. | ||
Line 10: | Line 10: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool getPlayerLevel(player thePlayer) | bool getPlayerLevel ( player thePlayer ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 17: | Line 17: | ||
==Returns== | ==Returns== | ||
Returns a number | Returns a number with the level of the player. | ||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "mylevel", | |||
function ( thePlayer ) | |||
local myLevel = exports.exp_system:getPlayerLevel ( thePlayer ) | |||
outputChatBox ( "Your level is: ".. myLevel, thePlayer ) | |||
end | |||
) | |||
</section> | </section> | ||
Line 25: | Line 33: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool setPlayerLevel(player thePlayer, int theLevel) | bool setPlayerLevel ( player thePlayer, int theLevel ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 34: | Line 42: | ||
==Returns== | ==Returns== | ||
Returns a bool, whether the level was set successfully or not. | Returns a bool, whether the level was set successfully or not. | ||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "setmylevel", | |||
function ( thePlayer, commandName, theLevel ) | |||
local theLevel = tonumber ( theLevel ) or 1 | |||
exports.exp_system:setPlayerLevel ( thePlayer, theLevel ) | |||
end | |||
) | |||
</section> | </section> | ||
Line 41: | Line 56: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool getPlayerEXP(player thePlayer) | bool getPlayerEXP ( player thePlayer ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 49: | Line 64: | ||
==Returns== | ==Returns== | ||
Returns a number with with the experience of the player. | Returns a number with with the experience of the player. | ||
==Example== | |||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "myexp", | |||
function ( thePlayer ) | |||
local myExp = exports.exp_system:getPlayerEXP ( thePlayer ) | |||
outputChatBox ( "Your experience is: ".. myExp, thePlayer ) | |||
end | |||
) | |||
</section> | </section> | ||
<section name="Server" class="server" show="true"> | <section name="Server" class="server" show="true"> | ||
Line 56: | Line 78: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool setPlayerEXP(player thePlayer, int theExperience) | bool setPlayerEXP ( player thePlayer, int theExperience ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 65: | Line 87: | ||
==Returns== | ==Returns== | ||
Returns a bool, whether the experience was set successfully or not. | Returns a bool, whether the experience was set successfully or not. | ||
==Example== | |||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "setmyexp", | |||
function ( thePlayer, commandName, theExp ) | |||
local theExp = tonumber ( theExp ) or 0 | |||
exports.exp_system:setPlayerEXP ( thePlayer, theExp ) | |||
end | |||
) | |||
</section> | </section> | ||
<section name="Server" class="server" show="true"> | <section name="Server" class="server" show="true"> | ||
Line 72: | Line 101: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool addPlayerEXP(player thePlayer, int theExperience) | bool addPlayerEXP ( player thePlayer, int theExperience ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 83: | Line 112: | ||
==Example== | ==Example== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addEvent("onZombieWasted",true) | addEvent ( "onZombieWasted", true ) | ||
addEventHandler("onZombieWasted",root, | addEventHandler ( "onZombieWasted", root, | ||
function ( | function ( theKiller ) | ||
exports.exp_system:addPlayerEXP( | exports.exp_system:addPlayerEXP ( theKiller, 5 ) | ||
end | |||
) | |||
</section> | |||
<section name="Server" class="server" show="true"> | |||
This function is used to get an account level. | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
bool getAccountLevel ( account theAccount ) | |||
</syntaxhighlight> | |||
==Required Arguments== | |||
*'''theAccount''': The player element you wish you get the level. | |||
==Returns== | |||
Returns a number with with the level of the account. | |||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "mylevel", | |||
function ( thePlayer ) | |||
local account = getPlayerAccount ( thePlayer ) | |||
local myExp = exports.exp_system:getAccountLevel ( account ) | |||
outputChatBox ( "Your account level is: ".. myLevel, thePlayer ) | |||
end | |||
) | |||
</section> | |||
<section name="Server" class="server" show="true"> | |||
This function is used to set an account level. | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
bool setAccountLevel ( account theAccount, int theLevel ) | |||
</syntaxhighlight> | |||
==Required Arguments== | |||
*'''theAccount''': The player element you wish you set the level. | |||
*'''theLevel''': The level you want to set. | |||
==Returns== | |||
Returns a bool, whether the level was set successfully or not. | |||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "setmylevel", | |||
function ( thePlayer, commandName, theLevel ) | |||
local account = getPlayerAccount ( thePlayer ) | |||
local theLevel = tonumber ( theLevel ) or 1 | |||
exports.exp_system:setAccountLevel ( account, theLevel ) | |||
end | |||
) | |||
</section> | |||
<section name="Server" class="server" show="true"> | |||
This function is used to get an account experience. | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
bool getAccountEXP ( account theAccount ) | |||
</syntaxhighlight> | |||
==Required Arguments== | |||
*'''theAccount''': The player element you wish you get the experience. | |||
==Returns== | |||
Returns a number with with the experience of the player. | |||
==Example== | |||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "myexp", | |||
function ( thePlayer ) | |||
local account = getPlayerAccount ( thePlayer ) | |||
local myExp = exports.exp_system:getAccountEXP ( account ) | |||
outputChatBox ( "Your account experience is: ".. myExp, thePlayer ) | |||
end | end | ||
) | ) | ||
</section> | |||
<section name="Server" class="server" show="true"> | |||
This function is used to set an account experience. | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
bool setAccountEXP ( account theAccount, int theExperience ) | |||
</syntaxhighlight> | |||
==Required Arguments== | |||
*'''theAccount''': The player element you wish you set the experience. | |||
*'''theExperience''': The exprience you want to set. | |||
==Returns== | |||
Returns a bool, whether the experience was set successfully or not. | |||
==Example== | |||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "setmyexp", | |||
function ( thePlayer, commandName, theExp ) | |||
local account = getPlayerAccount ( thePlayer ) | |||
local theExp = tonumber ( theExp ) or 0 | |||
exports.exp_system:setAccountEXP ( account, theExp ) | |||
end | |||
) | |||
</section> | |||
<section name="Server" class="server" show="true"> | |||
This function is used to refresh the levels. | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
bool loadLevelsFromXML( ) | |||
</syntaxhighlight> | |||
==Required Arguments== | |||
*'''None''' | |||
==Example== | |||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "refreshlevels", | |||
function ( ) | |||
exports.exp_system:loadLevelsFromXML ( ) | |||
end | |||
) | |||
</section> | |||
<section name="Server" class="server" show="true"> | |||
This function is used to obtain the name and experience required of a level. | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
getLevelData ( int theLevel ) | |||
</syntaxhighlight> | |||
==Required Arguments== | |||
*'''theLevel''' | |||
==Returns== | |||
Returns the name of the level and the experience required. | |||
==Example== | |||
<syntaxhighlight lang="lua"> | |||
addCommandHandler ( "getleveldata", | |||
function ( thePlayer ) | |||
local level = exports.exp_system:getPlayerLevel ( thePlayer ) | |||
local name, expreq = exports.exp_system:getLevelData ( level ) | |||
outputChatBox ( name ..": ".. expreq, thePlayer ) | |||
end | |||
) | |||
</section> | |||
=Custom Events= | |||
<section name="Server" class="server" show="true"> | |||
This event is called when a player level changes. | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
event onPlayerChangeLevel | |||
</syntaxhighlight> | |||
==Parameters== | |||
*'''oldLevel''': The player old level. | |||
*'''newLevel''': The player new level. | |||
<!-- Add the event's source in the section below --> | |||
==Source== | |||
The [[event system#Event source|source]] of this event is the [[player]] whose level changed. | |||
</section> | |||
<section name="Server" class="server" show="true"> | |||
This event is called when a player level UP. | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
event onPlayerLevelUP | |||
</syntaxhighlight> | |||
==Parameters== | |||
*'''oldLevel''': The player old level. | |||
*'''newLevel''': The player new level. | |||
<!-- Add the event's source in the section below --> | |||
==Source== | |||
The [[event system#Event source|source]] of this event is the [[player]] who leveled UP. | |||
</section> | </section> | ||
Latest revision as of 21:05, 16 October 2013
A level/experience system made from scratch by Castillo.
It uses SQLite to save level and experience.
Exported Functions
This function is used to get a player level.
Syntax
bool getPlayerLevel ( player thePlayer )
Required Arguments
- thePlayer: The player element you wish you get the level.
Returns
Returns a number with the level of the player. <syntaxhighlight lang="lua"> addCommandHandler ( "mylevel", function ( thePlayer )
local myLevel = exports.exp_system:getPlayerLevel ( thePlayer )
outputChatBox ( "Your level is: ".. myLevel, thePlayer ) end )
This function is used to set a player level.
Syntax
bool setPlayerLevel ( player thePlayer, int theLevel )
Required Arguments
- thePlayer: The player element you wish you set the level.
- theLevel: The level you want to set.
Returns
Returns a bool, whether the level was set successfully or not. <syntaxhighlight lang="lua"> addCommandHandler ( "setmylevel", function ( thePlayer, commandName, theLevel )
local theLevel = tonumber ( theLevel ) or 1
exports.exp_system:setPlayerLevel ( thePlayer, theLevel ) end )
This function is used to get a player experience.
Syntax
bool getPlayerEXP ( player thePlayer )
Required Arguments
- thePlayer: The player element you wish you get the experience.
Returns
Returns a number with with the experience of the player.
Example
<syntaxhighlight lang="lua"> addCommandHandler ( "myexp", function ( thePlayer )
local myExp = exports.exp_system:getPlayerEXP ( thePlayer )
outputChatBox ( "Your experience is: ".. myExp, thePlayer ) end )
This function is used to set a player experience.
Syntax
bool setPlayerEXP ( player thePlayer, int theExperience )
Required Arguments
- thePlayer: The player element you wish you set the experience.
- theExperience: The exprience you want to set.
Returns
Returns a bool, whether the experience was set successfully or not.
Example
<syntaxhighlight lang="lua"> addCommandHandler ( "setmyexp", function ( thePlayer, commandName, theExp )
local theExp = tonumber ( theExp ) or 0
exports.exp_system:setPlayerEXP ( thePlayer, theExp ) end )
This function is used to give a player experience.
Syntax
bool addPlayerEXP ( player thePlayer, int theExperience )
Required Arguments
- thePlayer: The player element you wish you to give the experience.
- theExperience: The exprience you want to give.
Returns
Returns a bool, whether the experience was given successfully or not.
Example
<syntaxhighlight lang="lua"> addEvent ( "onZombieWasted", true ) addEventHandler ( "onZombieWasted", root, function ( theKiller ) exports.exp_system:addPlayerEXP ( theKiller, 5 ) end )
This function is used to get an account level.
Syntax
bool getAccountLevel ( account theAccount )
Required Arguments
- theAccount: The player element you wish you get the level.
Returns
Returns a number with with the level of the account. <syntaxhighlight lang="lua"> addCommandHandler ( "mylevel", function ( thePlayer ) local account = getPlayerAccount ( thePlayer )
local myExp = exports.exp_system:getAccountLevel ( account )
outputChatBox ( "Your account level is: ".. myLevel, thePlayer ) end )
This function is used to set an account level.
Syntax
bool setAccountLevel ( account theAccount, int theLevel )
Required Arguments
- theAccount: The player element you wish you set the level.
- theLevel: The level you want to set.
Returns
Returns a bool, whether the level was set successfully or not. <syntaxhighlight lang="lua"> addCommandHandler ( "setmylevel", function ( thePlayer, commandName, theLevel ) local account = getPlayerAccount ( thePlayer )
local theLevel = tonumber ( theLevel ) or 1
exports.exp_system:setAccountLevel ( account, theLevel ) end )
This function is used to get an account experience.
Syntax
bool getAccountEXP ( account theAccount )
Required Arguments
- theAccount: The player element you wish you get the experience.
Returns
Returns a number with with the experience of the player.
Example
<syntaxhighlight lang="lua"> addCommandHandler ( "myexp", function ( thePlayer ) local account = getPlayerAccount ( thePlayer )
local myExp = exports.exp_system:getAccountEXP ( account )
outputChatBox ( "Your account experience is: ".. myExp, thePlayer ) end )
This function is used to set an account experience.
Syntax
bool setAccountEXP ( account theAccount, int theExperience )
Required Arguments
- theAccount: The player element you wish you set the experience.
- theExperience: The exprience you want to set.
Returns
Returns a bool, whether the experience was set successfully or not.
Example
<syntaxhighlight lang="lua"> addCommandHandler ( "setmyexp", function ( thePlayer, commandName, theExp ) local account = getPlayerAccount ( thePlayer )
local theExp = tonumber ( theExp ) or 0
exports.exp_system:setAccountEXP ( account, theExp ) end )
This function is used to refresh the levels.
Syntax
bool loadLevelsFromXML( )
Required Arguments
- None
Example
<syntaxhighlight lang="lua"> addCommandHandler ( "refreshlevels", function ( ) exports.exp_system:loadLevelsFromXML ( ) end )
This function is used to obtain the name and experience required of a level.
Syntax
getLevelData ( int theLevel )
Required Arguments
- theLevel
Returns
Returns the name of the level and the experience required.
Example
<syntaxhighlight lang="lua"> addCommandHandler ( "getleveldata", function ( thePlayer ) local level = exports.exp_system:getPlayerLevel ( thePlayer ) local name, expreq = exports.exp_system:getLevelData ( level ) outputChatBox ( name ..": ".. expreq, thePlayer ) end )
Custom Events
This event is called when a player level changes.
Syntax
event onPlayerChangeLevel
Parameters
- oldLevel: The player old level.
- newLevel: The player new level.
Source
This event is called when a player level UP.
Syntax
event onPlayerLevelUP
Parameters
- oldLevel: The player old level.
- newLevel: The player new level.