Skip to content

Commit b3f46a8

Browse files
committed
Account functions
1 parent 134ca2f commit b3f46a8

File tree

71 files changed

+1077
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1077
-72
lines changed

functions/Account/addAccount.yaml

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/addAccount
21
server:
32
name: addAccount
4-
description: TODO
5-
incomplete: true
3+
pair: removeAccount
4+
notes:
5+
- type: info
6+
content: |
7+
- Minimal account name/password length is 1 character.
8+
- Account name/password can not be equal to <code>*****</code>.
9+
- Account names are case-sensitive if *allowCaseVariations* is **true**.
10+
- Maximum account password length was 30 characters until version **1.5.4-11138**. Currently there is no upper limit.
11+
oop:
12+
element: Account
13+
method: add
14+
description: This function adds an [[account]] to the list of registered accounts of the current server.
15+
parameters:
16+
- name: name
17+
type: string
18+
description: The name of the [account](account) you wish to make, this normally is the player's name.
19+
- name: pass
20+
type: string
21+
description: The password to set for this [account](account) for future logins.
22+
- name: allowCaseVariations
23+
type: bool
24+
description: Whether the username is case sensitive (if this is set to true, usernames "Bob" and "bob" will refer to different accounts).
25+
default: 'false'
26+
returns:
27+
values:
28+
- type: account|false
29+
name: result
30+
description: Returns an [[account]] or false if the account already exists or an error occured.
31+
examples:
32+
- path: 'examples/addAccount-1.lua'
33+
description: This enables players to register on your server by using /register <password> in the chat window.
34+
- path: 'examples/addAccount-2.lua'
35+
description: This enables players to register on your server by using /register <username> <password> in the chat window.
36+
- path: 'examples/addAccount-3.lua'
37+
description: This code differs again so the user can only register once /register <username> <password>.
38+
meta:
39+
- changelog:
40+
- version: 1.5.4-11138
41+
description: The 30-character password length limit has been removed.
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/copyAccountData
21
server:
32
name: copyAccountData
4-
description: TODO
5-
incomplete: true
3+
description: This function copies all of the data from one [[account]] to another.
4+
oop:
5+
element: account
6+
method: copyDataTo
7+
parameters:
8+
- name: theAccount
9+
type: account
10+
description: The [account](account) you wish to copy the data to.
11+
- name: fromAccount
12+
type: account
13+
description: The [account](account) you wish to copy the data from.
14+
returns:
15+
values:
16+
- type: bool
17+
name: result
18+
description: Returns a **true** if the accounts were valid, **false** otherwise.
19+
examples:
20+
- path: 'examples/copyAccountData-1.lua'
21+
description: This example copies the account data from the 'guest' to a registered account when they login.
22+
- path: examples/copyAccountData_OOP-1.lua
23+
description: This example copies the account data from the 'guest' to a registered account when they login.
24+
oop: true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function registerPlayer ( source, commandName, password )
2+
-- Check if the password field is blank or not (only blank if they didnt enter one)
3+
if ( password and #password > 0 ) then
4+
--Attempt to add the account, and save its value in a var
5+
local accountAdded = addAccount(getPlayerName(source), password)
6+
if ( accountAdded ) then
7+
-- Tell the user all is done
8+
outputChatBox ( "Thank you " .. getPlayerName(source) .. ", you're now registed, you can login with /login", source )
9+
else
10+
-- There was an error making the account, tell the user
11+
outputChatBox ( "Error creating account, contact the server admin", source )
12+
end
13+
else
14+
-- There was an error in the syntax, tell the user the correct syntax.
15+
outputChatBox ( "Error creating account, correct syntax: /register <password>", source )
16+
end
17+
end
18+
addCommandHandler ( "register", registerPlayer ) -- add the command handler
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function registerPlayer ( source, commandName, username, password )
2+
if (username and #username > 0 and password and #password > 0) then
3+
local accountAdded = addAccount(username,password)
4+
if (accountAdded) then
5+
outputChatBox("Thank you " .. getPlayerName(source) .. ", you're now registed, you can login with /login",source)
6+
else
7+
outputChatBox("Error creating account, contact the server admin.",source)
8+
end
9+
else
10+
outputChatBox("Error creating account, correct syntax: /register <nick> <pass>",source)
11+
end
12+
end
13+
addCommandHandler ( "register", registerPlayer ) -- add the command handler
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
local bRegisteredOnce = {}
2+
3+
function registerPlayer ( source, commandName, username, password )
4+
if ((password and #password > 0) and (username and #username > 0) and not bRegisteredOnce[source]) then
5+
local accountAdded = addAccount(username,password)
6+
if (accountAdded) then
7+
outputChatBox("Thank you " .. getPlayerName(source) .. ", you're now registed, you can login with /login",source)
8+
bRegisteredOnce[source] = true
9+
else
10+
outputChatBox("Error creating account, contact the server admin.",source)
11+
end
12+
else
13+
if (bRegisteredOnce[source]) then
14+
outputChatBox("You already registered on this server!",source)
15+
else
16+
outputChatBox("Error creating account, correct syntax: /register <nick> <pass>",source)
17+
end
18+
end
19+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function copyDataOnLogin ( previousAccount, currentAccount )
2+
copyAccountData ( currentAccount, previousAccount )
3+
end
4+
addEventHandler ( "onPlayerLogin", getRootElement(), copyDataOnLogin )
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function copyDataOnLogin ( previousAccount, currentAccount )
2+
previousAccount:copyDataTo(currentAccount)
3+
end
4+
addEventHandler ( "onPlayerLogin", getRootElement(), copyDataOnLogin )
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
addCommandHandler("checkaccount",
2+
function(player, cmd, account)
3+
if hasObjectPermissionTo(player, "function.banPlayer" ) then -- if the player typing /checkaccount command has permission to banPlayer
4+
if account and account ~= "" then -- if the account name was mentioned
5+
if getAccount(account) then -- if the account exists
6+
outputChatBox("Account "..account.." exists in the database!", player, 0, 255, 0)
7+
else -- if the account doesn't exist
8+
outputChatBox("Account "..account.." does not exist in database", player, 0, 255, 0)
9+
end
10+
else
11+
outputChatBox("Syntax is /checkaccount [account name]", player, 255, 0, 0)
12+
end
13+
end
14+
end
15+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
addCommandHandler("getAccount", function (player, cmd, id)
2+
local id = tonumber(id)
3+
local account = getAccountByID(id)
4+
if (account) then
5+
outputChatBox("The name of the account with that ID is: "..getAccountName(account), player)
6+
else
7+
outputChatBox("There is no account with this ID.", player)
8+
end
9+
end)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function onPlayerQuit()
2+
local playerAccount = getPlayerAccount(source) -- get his account
3+
if (playerAccount) then -- if we got the account then
4+
local playerMoney = getPlayerMoney(source) -- get his money amount
5+
setAccountData(playerAccount, "piraterpg.money", playerMoney) -- store his current money amount in his account data
6+
end
7+
end
8+
addEventHandler("onPlayerQuit", root, onPlayerQuit) -- add an event handler
9+
10+
function onPlayerLogin(_,account)
11+
local playerMoney = getAccountData(account, "piraterpg.money") -- get the money amount was store in his account data
12+
-- make sure there was actually a value saved under this key (check if playerMoney is not false).
13+
-- this will for example not be the case when a player plays the gametype for the first time
14+
if (playerMoney) then
15+
setPlayerMoney(source, playerMoney)
16+
end
17+
end
18+
addEventHandler("onPlayerLogin", root, onPlayerLogin) -- add an event handler

0 commit comments

Comments
 (0)