PlayerHUD

Modular gamification block for Moodle — full documentation.

English | Português

View on GitHub Download .zip

Moodle License Status Latest Release PlayerGames Ecosystem Core Component Author

Moodle Plugin CI MDL Shield Last Commit Open Issues

The PlayerHUD Block is a modular gamification system for Moodle that introduces structured progression mechanics based on XP, Levels, Inventory, Quests, Trade, and RPG progression.

It provides a dynamic HUD (Head-Up Display) inside courses, allowing students to track their progress in real time while teachers configure engagement mechanics aligned with pedagogical objectives.

👈 Use the sidebar to jump to any section on this page.


🖼️ Screenshots

Browse with the arrows, the dots, or the left/right keys. Click the image to zoom.

✨ Features

🏆 Group Ranking Behavior

When the group ranking is enabled, each group’s average XP is calculated only from members who are actively participating — meaning members who have both:

Members who have opted out of gamification or hidden their ranking are completely excluded from the group’s sum and count. The denominator used to calculate the average reflects only the number of active participants, not the total group size.

Practical implication: a group with many opted-out members may show a higher average than expected, because the average is computed over a smaller subset. Teachers should be aware that a group’s displayed average does not represent all enrolled members — only those actively participating in the ranking.

Integration with PlayerGroup

The group ranking reads directly from Moodle’s native group tables ({groups} / {groups_members}). It works with any Moodle group — whether created manually by a teacher or automatically via the PlayerGroup activity module.

When PlayerGroup (mod_playergroup) is installed alongside PlayerHUD, an additional integration activates inside the HUD header (not the ranking tab): the student’s group badge, group name, member count, and capacity (e.g. 3/5) are displayed at the top of the block. This information is fetched via PlayerGroup’s public API (\mod_playergroup\api\group_info) and is only available for groups created through PlayerGroup activities — manually created Moodle groups are not shown there.

The two features are independent:

Scenario Group Ranking tab HUD header group info
No PlayerGroup installed ✅ Works with any Moodle group — Not shown
PlayerGroup installed, student has a PlayerGroup group ✅ Group appears in ranking ✅ Badge + name + slots displayed
PlayerGroup installed, student is in a manual group only ✅ Group appears in ranking — Not shown (manual groups not in PlayerGroup API)

Student in more than one PlayerGroup group

A course can host multiple PlayerGroup activity instances, each with its own grouping. Within a single instance a student can only belong to one group, but nothing stops them from joining a group in each different instance within the same course.

When that happens, the HUD header shows the group the student joined most recently (the highest timeadded in the groups_members table), not a “primary” group or one tied to a specific instance. The Group Ranking tab has no such limitation — since it reads directly from Moodle’s native group tables, all of the student’s groups appear normally.

⚖️ Economy Health Panel

The Config tab in the management panel includes an Economy Health widget that compares the total XP a student can earn (all items × their drop limits + quest rewards) against the configured XP cap (XP per level × number of levels).

Coverage Status
Exactly 100% ✅ Green — “Balanced configuration”
Below 100% ⚠️ Yellow — students cannot reach the maximum level; add more items or quests, or lower the cap
Above 100% 🔴 Red — students can exceed the cap; reduce item/quest XP or increase the cap

The widget also shows a collapsible breakdown table listing every item and quest with its individual XP contribution, making it easy to identify which content is over- or under-contributing to the economy.

Drops that are not placed yet

The figures above count every drop, but a drop only pays XP once its shortcode sits where students can see it. When the panel finds drops in no activity description, page content or the news forum, it adds a notice under the balance message with how many drops they are and how much XP they would pay, and links to Distribute Drops. That XP is part of the total above but cannot be earned until the drops are placed.

The check reads the same places as the Distribute Drops screen. A drop placed somewhere it does not look (a book chapter, a section summary, a forum post) is reported as “not found”; in that case the notice can be ignored.

🩺 Usage & Diagnostics Page

Site administrators get a page at Site administration > Reports > PlayerHUD usage and diagnostics (capability moodle/site:config). Every figure is counted on the site itself — nothing is sent outside it.

Adoption

How widely the block is used, counted per course (the block allows one instance per course):

Engagement

Figures are cached for 10 minutes; a Refresh button recounts them.

Data integrity and cleanup

Sites that removed the block before v1.7.0 may still hold the data of those blocks, and earlier versions could leave rows behind when an item, quest, chapter, scene, trade or assistant run was deleted. None of it appears on any page or counts towards anything in the game.

Deleting needs an explicit confirmation and runs in one transaction. Before deleting, a copy of every row is saved as a JSON file in the site data directory (moodledata/block_playerhud/orphan_backups/). The page lists these copies with Download and Delete buttons. The copies contain personal data (user IDs and XP) of the deleted rows, so a scheduled task deletes them automatically after 30 days (you can delete them earlier from the page), and they are removed when the plugin is uninstalled.

🎓 Educational Purpose

PlayerHUD is designed to:

Suitable for:

🕹️ PlayerGames Ecosystem

PlayerHUD is part of the PlayerGames gamification ecosystem. Together, these plugins transform Moodle into an immersive experience:

🧩 Optional Integration: AI Hub

PlayerHUD’s optional AI features (Content Generator and Game Master Assistant) can draw on AI Hub (local_aihub, by the same author, part of the shared PlayerGames ecosystem services). When AI Hub is installed, any personal or site key a teacher or admin has already configured there is automatically available to PlayerHUD — no key needs to be re-entered. AI Hub’s keys sit between PlayerHUD’s own keys and Moodle’s core_ai fallback in the AI Provider Chain. Without AI Hub installed, PlayerHUD simply skips those two tiers and resolves from its own keys or core_ai.

👉 https://github.com/jeanlucio/moodle-local_aihub

🧩 Optional Integration: Late Penalty

The Deadline Extension item power (see Features) does not work on its own — it requires the separate Late Penalty plugin (local_latepenalty, by the same author, but not part of the PlayerGames family). When installed, redeeming a Deadline Extension item pushes back the activity’s effective deadline for that student and triggers Late Penalty’s automatic recalculation, waiving or reducing any late-submission grade penalty already applied. Without Late Penalty installed, the item power fails gracefully with a “not installed” message instead of granting the extension.

👉 https://github.com/jeanlucio/moodle-local_latepenalty

📦 Requirements

Component Version
Moodle 4.5+
PHP 8.1+

🛠️ Installation

  1. Download the .zip file or clone this repository.
  2. Extract the folder into your Moodle blocks/ directory.
  3. Rename the folder to playerhud (if necessary). Final path: your-moodle/blocks/playerhud/
  4. Install the recommended PlayerHUD Filter plugin (needed to place item drops via shortcodes in course content).
  5. Visit Site administration > Notifications to complete installation.
  6. Add the block to a course.

Administrators can follow how the block is used, and clean data left by removed blocks, at Site administration > Reports > PlayerHUD usage and diagnostics — see Usage & Diagnostics Page.

📖 Usage

  1. Add the PlayerHUD Block to your course.
  2. Access the Management Panel (Teacher role required).
  3. Choose how to set it up:
    • Quick start: run the Gamification Wizard to auto-generate items, quests, ranking, and other mechanics in one pass (see Features above).
    • Manual setup: configure each mechanic yourself:
      • Items
      • XP values
      • Number of levels
      • XP thresholds
      • Drop placements
      • Recharge time (Cooldown)
      • Collection limits
  4. Students collect items directly within course sections.
  5. XP, levels, and ranking update automatically.

Removing the block from a course deletes the whole game and every student’s progress at once, and it cannot be undone from the block. Back up the course with user data first, or use Hide in the block menu to take the game out of sight without losing anything. The teacher manual (the ? button of the management panel) explains this under Removing the block.

🌱 Demo Environment (Quick Start)

The plugin includes two CLI seed scripts that create a fully configured demo course in minutes — useful for local development or for evaluating the full feature set without manual setup.

Script Course language
cli/seed.php English
cli/seed_pt_br.php Brazilian Portuguese

What is created:

Resulting ranking after seed:

Rank Username Name XP
1 seed_carol Carol Staff 195
2 seed_bob Bob Bow 150
3 seed_alice Alice Sword 65
4 seed_dave Dave Shield 60
5 seed_eve Eve Dagger 10

Usage:

# Run once
php blocks/playerhud/cli/seed.php --password=YourDevPassword

# Wipe and recreate from scratch
php blocks/playerhud/cli/seed.php --password=YourDevPassword --reset

# Bypass the non-development-site guard (custom dev domains)
php blocks/playerhud/cli/seed.php --password=YourDevPassword --force

The --password flag is required and sets the login password for all seed accounts. The script refuses to run on non-development URLs (localhost, *.local, *.test) unless --force is passed.

Via Docker Compose: docker compose exec <webserver-service> php blocks/playerhud/cli/seed.php --password=YourDevPassword

🧪 Automated Tests

PlayerHUD ships with an extensive test suite covering both business logic (PHPUnit) and browser acceptance (Behat). Every CI push runs against the full matrix (Moodle 4.5 → 5.x, PostgreSQL & MariaDB).

PHPUnit — Unit & Integration Tests

Test file Cases
ai/chat_test.php 2
ai/generator_test.php 19
ai/hub_usage_reporting_test.php 2
backup_restore_item_images_test.php 1
backup_restore_test.php 3
block_dashboard_test.php 3
collection_tab_test.php 17
db_access_test.php 2
db_upgrade_test.php 9
drop_guard_test.php 11
edit_form_test.php 5
form/edit_item_form_test.php 8
form/edit_scene_form_test.php 3
game_test.php 48
gamemaster_test.php 6
instance_delete_test.php 2
item_delete_cascade_test.php 25
karma_test.php 11
lib_test.php 27
privacy_provider_test.php 26
quest_test.php 53
rpg_classes_test.php 3
story_manager_test.php 34
suggest_trades_state_test.php 4
template_strings_test.php 3
trade_test.php 12
uninstall_test.php 2
utils_test.php 23
Subtotal 364

Local Business-Logic Tests (tests/local/)

Test file Cases
analytics_test.php 13
audit_log_test.php 16
diagnostics/integrity_test.php 14
diagnostics/report_test.php 3
diagnostics/usage_test.php 2
drop_distribution_test.php 13
external_items_test.php 27
latepenalty_bridge_test.php 2
wizard_test.php 22
xp_budget_test.php 15
Subtotal 127

Web Services Tests (tests/external/)

Test file Cases
chat_message_test.php 4
collect_item_test.php 5
create_avatar_pack_test.php 7
create_class_pack_test.php 8
create_playercoin_test.php 4
execute_chat_action_test.php 6
generate_ai_content_test.php 4
generate_class_oracle_test.php 4
generate_story_test.php 4
insert_drop_shortcode_test.php 12
load_recap_test.php 3
load_scene_test.php 4
make_choice_test.php 3
remove_drop_shortcode_test.php 8
setup_playercoin_drop_test.php 7
use_item_test.php 13
wizard_apply_suggested_levels_test.php 3
wizard_generate_helpers_test.php 13
wizard_list_runs_test.php 4
wizard_rollback_test.php 4
wizard_run_step_test.php 57
wizard_start_test.php 9
Subtotal 186

Controller Tests (tests/controller/)

Test file Cases
aikeys_test.php 4
chapters_test.php 17
classes_test.php 7
drops_test.php 19
export_test.php 10
items_test.php 26
manage_entry_points_test.php 34
quests_test.php 14
scenes_test.php 6
suggestions_test.php 4
trades_test.php 10
Subtotal 151

Output / Renderer Tests (tests/output/)

Test file Cases
admin/diagnostics_test.php 6
chapters_escaping_test.php 8
manage/item_delete_confirm_test.php 12
manage/item_disable_confirm_test.php 3
manage/quest_delete_confirm_test.php 3
manage/tab_chapters_test.php 4
manage/tab_config_test.php 4
manage/tab_items_escaping_test.php 7
manage/tab_items_test.php 3
manage/tab_quests_test.php 4
manage/tab_reports_test.php 22
player_screens_escaping_test.php 18
profile_content_test.php 1
quests_escaping_test.php 5
reports_escaping_test.php 6
trades_escaping_test.php 4
view/header_test.php 2
view/tab_chapters_test.php 6
view/tab_history_test.php 4
view/tab_quests_test.php 6
view/tab_ranking_test.php 13
view/tab_rules_test.php 2
view/tab_shop_test.php 4
Subtotal 147
Grand Total 975
vendor/bin/phpunit --testsuite block_playerhud

Overall line coverage (moodle-coverage, PHPUnit + Xdebug): 81%.

Full test-by-test breakdown and coverage table →

🔐 Security & Compliance

🔎 Third-party Service Disclosure

PlayerHUD includes optional AI-powered features: a Content Generator (items, chapters, class backstories) and a Game Master Assistant (a conversational chat for teachers that can also trigger game actions).

Is the AI feature required?

No. The plugin works fully without any external AI service. All content can be created manually inside Moodle. The AI features are productivity tools — the assistant also accepts confirmation before saving anything.

AI Provider Chain

PlayerHUD resolves the AI provider tier by tier, following the shared PlayerGames ecosystem ladder. An explicitly configured key always wins over the institutional default; core_ai sits at the bottom.

Resolution ladder (highest priority first):

Tier Source
1 Own personal key — teacher’s own key set in PlayerHUD (Configurações tab → API keys)
2 Hub personal key — teacher’s own key set in local_aihub (if installed)
3 Own site key — admin key set in PlayerHUD settings
4 Hub site key — admin key set in local_aihub settings (if installed)
5 Moodle core_ai — providers configured in Site administration → AI → AI providers. No API key stored in PlayerHUD.

Tier-first, not provider-first. Each tier above is evaluated as a whole: the first tier that holds any key is used exclusively. So a teacher’s own personal key (tier 1) always wins over a hub key (tier 2) — even a hub key for a higher-priority provider. For example, a teacher’s own custom-endpoint key is not overridden by a Gemini key that happens to live in the hub. core_ai is consulted only when no tier holds a key.

Within the chosen tier, the direct providers are tried in the order Gemini → Groq → OpenAI-compatible (first key found is used; if its call fails, the next is tried).

This also means: if a teacher configured their own key in the AI Hub, PlayerHUD uses it automatically — no need to re-enter the key in PlayerHUD.

Supported Direct Providers

These services operate under their own terms of service and privacy policies.

How to obtain an API key

API keys must be created directly on the provider’s official website:

Both Gemini and Groq currently offer free usage tiers. However, pricing policies may change and paid plans may apply depending on usage limits.

The PlayerHUD plugin does not provide API keys.

Where API keys are configured

API keys may be configured through any of the following sources (in decreasing priority):

  1. PlayerHUD personal key — set by each teacher individually in the Configurações tab of the management panel.
  2. AI Hub personal key — set by each teacher in local_aihub → My AI keys (if the hub is installed).
  3. PlayerHUD site key — set by the site admin in Site administration → Plugins → Blocks → PlayerHUD.
  4. AI Hub site key — set by the site admin in local_aihub settings (if the hub is installed).
  5. Moodle core_ai — configured by the site admin in Site administration → AI → AI providers (no key stored in PlayerHUD; used only when no key above is set).

Data Transmission

When the AI feature is used, user-entered prompts are transmitted to the selected provider for processing.

The plugin:

No external communication occurs unless an AI feature is explicitly used.

Demo Credentials

Not applicable — PlayerHUD requires no credentials to install or use. Every AI feature is entirely opt-in and the block works fully without any key configured.

📄 License

This project is licensed under the GNU General Public License v3 (GPLv3).

Copyright: 2026 Jean Lúcio