PlayerHUD

Modular gamification block for Moodle — full documentation.

English | Português

View on GitHub Download .zip

Moodle Plugin CI MDL Shield Moodle License Status PlayerGames Ecosystem Core Component

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

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.

Source code: github.com/jeanlucio/moodle-block_playerhud


✨ 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)

⚖️ 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.

🎓 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: 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 required PlayerHUD Filter plugin.
  5. Visit Site administration > Notifications to complete installation.
  6. Add the block to a course.

📖 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.

🌱 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/generator_test.php 2
backup_restore_test.php 3
collection_tab_test.php 8
content_crud_test.php 13
cross_instance_security_test.php 12
drop_guard_test.php 7
game_test.php 36
gamemaster_test.php 6
instance_delete_test.php 1
item_delete_cascade_test.php 17
karma_test.php 11
privacy_provider_test.php 10
quest_test.php 34
rpg_classes_test.php 7
story_manager_test.php 15
suggest_trades_state_test.php 4
trade_test.php 8
utils_test.php 4
Subtotal 198

Local Business-Logic Tests (tests/local/)

Test file Cases
analytics_test.php 11
audit_log_test.php 5
drop_distribution_test.php 12
external_items_test.php 18
wizard_test.php 17
xp_budget_test.php 15
Subtotal 78

Web Services Tests (tests/external/)

Test file Cases
chat_message_test.php 2
collect_item_test.php 4
create_avatar_pack_test.php 6
create_class_pack_test.php 7
create_playercoin_test.php 3
execute_chat_action_test.php 4
generate_ai_content_test.php 2
generate_class_oracle_test.php 2
generate_story_test.php 2
insert_drop_shortcode_test.php 7
load_recap_test.php 3
load_scene_test.php 3
make_choice_test.php 3
remove_drop_shortcode_test.php 5
setup_playercoin_drop_test.php 6
use_item_test.php 6
wizard_apply_suggested_levels_test.php 3
wizard_generate_helpers_test.php 10
wizard_list_runs_test.php 4
wizard_run_step_test.php 56
wizard_start_test.php 8
Subtotal 146

Controller Tests (tests/controller/)

Test file Cases
aikeys_test.php 4
chapters_test.php 13
classes_test.php 7
collect_test.php 3
drops_test.php 11
export_test.php 7
items_test.php 15
quests_test.php 12
scenes_test.php 6
suggestions_test.php 4
trades_test.php 7
Subtotal 89

Output / Renderer Tests (tests/output/)

Test file Cases
manage/item_delete_confirm_test.php 9
manage/quest_delete_confirm_test.php 3
manage/tab_chapters_test.php 4
Subtotal 16
Grand Total 527
vendor/bin/phpunit --testsuite block_playerhud

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

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