mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 01:30:38 +01:00
Added skeleton of pclasses
- This. Is. A. Skeleton. Not finished YET.
This commit is contained in:
parent
c71b1a0ac3
commit
117b25bc36
67
mods/pclasses/README.md
Executable file
67
mods/pclasses/README.md
Executable file
@ -0,0 +1,67 @@
|
||||
Player Classes
|
||||
==============
|
||||
|
||||
Yet another class mod for Minetest.
|
||||
|
||||
# TODO
|
||||
- Flush and read system for `pclasses.datas.players`
|
||||
|
||||
|
||||
# Namespaces
|
||||
|
||||
## pclasses
|
||||
- All our stuff
|
||||
|
||||
### pclasses.api
|
||||
- All functions used to declare, get, set classes
|
||||
|
||||
### pclasses.classes
|
||||
- All classes and their specs
|
||||
|
||||
### pclasses.datas
|
||||
- Miscellaneous datas
|
||||
|
||||
#### pclasses.datas.players
|
||||
- List of all players' class. Index is player's name and value is the class's name
|
||||
|
||||
#### pclasses.datas.hud_ids
|
||||
- Surely useful in the future with a hypothetical hud to show current class
|
||||
|
||||
|
||||
# Functions
|
||||
|
||||
### pclasses.api.create_class_id
|
||||
- Arguments : None
|
||||
- Indicates the next free id/index in the classes' table
|
||||
|
||||
### pclasses.api.id_for_class
|
||||
- Arguments : cname (class' name)
|
||||
- Returns the id/index corresponding the class in the classes' table
|
||||
- Returns 0 if not found, nil if no name given
|
||||
|
||||
### pclasses.api.register_class(cname)
|
||||
- Argument : cname
|
||||
- Registers a class in the classes' table
|
||||
- Pretty useless at the moment
|
||||
- Returns class' id or nil if any error
|
||||
|
||||
### pclasses.api.get_class_by_id
|
||||
- Argument : id
|
||||
- Return the class' specs (table) corresponding an id or nil when not found
|
||||
|
||||
### pclasses.api.get_class_by_name
|
||||
- Argument : cname
|
||||
- Return the class' specs (table) corresponding a class name or nil if not found
|
||||
|
||||
### pclasses.api.get_player_class
|
||||
- Argument : pname (player's name)
|
||||
- Return the player's current class' name
|
||||
|
||||
### pclasses.api.get_class_players
|
||||
- Argument : cname
|
||||
- Return a list (table) of all players with class cname
|
||||
|
||||
### pclasses.api.set_player_class
|
||||
- Arguments : pname, cname
|
||||
- Assign a player the cname class
|
||||
|
94
mods/pclasses/init.lua
Executable file
94
mods/pclasses/init.lua
Executable file
@ -0,0 +1,94 @@
|
||||
-------------------
|
||||
-- Player Classes
|
||||
--
|
||||
|
||||
-- NOTE: This is a very simple interface for classes, more features will be
|
||||
-- added depending on the various mechanisms we will need
|
||||
|
||||
-- Global namespace
|
||||
pclasses = {}
|
||||
|
||||
-- API
|
||||
pclasses.api = {}
|
||||
|
||||
-- Classes
|
||||
pclasses.classes = {}
|
||||
|
||||
-- Data
|
||||
pclasses.datas = {}
|
||||
pclasses.datas.players = {}
|
||||
pclasses.datas.hud_ids = {} -- HUD maybe?
|
||||
|
||||
|
||||
-- Various utility functions
|
||||
|
||||
-- Get an ID number dedicated to the class
|
||||
function pclasses.api.create_class_id()
|
||||
return table.getn(pclasses.classes)+1
|
||||
end
|
||||
|
||||
function pclasses.api.id_for_class(cname)
|
||||
if cname then
|
||||
for k,v in ipairs(pclasses.classes) do
|
||||
if v and v.name and v.name == cname then
|
||||
return k
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Register the class (basic registration)
|
||||
function pclasses.api.register_class(cname)
|
||||
if not cname then
|
||||
minetest.log("error", "[PClasses] Error registering unamed class")
|
||||
return
|
||||
end
|
||||
|
||||
local c_id = pclasses.api.create_class()
|
||||
pclasses.classes[c_id] = {name = cname}
|
||||
return c_id
|
||||
end
|
||||
|
||||
------------------------
|
||||
-- Getters and Setters
|
||||
--
|
||||
|
||||
-- Get class specs
|
||||
-- by id
|
||||
function pclasses.api.get_class_by_id(id)
|
||||
return pclasses.classes[id]
|
||||
end
|
||||
|
||||
-- by name
|
||||
function pclasses.api.get_class_by_name(cname)
|
||||
return pclasses.classes[pclasses.api.id_for_class(cname)]
|
||||
end
|
||||
|
||||
|
||||
-- Get single player
|
||||
function pclasses.api.get_player_class(pname)
|
||||
return pclasses.datas.player[pname]
|
||||
end
|
||||
|
||||
-- Get all players for a class
|
||||
function pclasses.api.get_class_players(cname)
|
||||
local pnames = {}
|
||||
if pclasses.api.get_class_by_name(cname) then
|
||||
for p,c in ipairs(pclasses.datas.players) do
|
||||
if c == cname then
|
||||
table.insert(pnames, table.getn(pnames)+1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Set single player
|
||||
function pclasses.api.set_player_class(pname, cname)
|
||||
if pclasses.api.get_class_by_name(cname) then
|
||||
pclasses.datas.players[pname] = cname
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
Loading…
Reference in New Issue
Block a user