This also contains a half-assed attempt at an "actor" system, which could be considered an artificial player disguised as an NPC for "intelligent" npc systems, though this is far from implemented. Unfortunately, I no longer have the Lua scripts on hand, but it shouldn't be too hard to figure out
I can't help you a whole lot with the scripts other than providing a few examples that I toyed around with, but you should be able to figure it out from reading the functions and models that is exposed in the ShaiyaScriptingEngine project.
Code:
:
NAKED_MAP_ID = 60 -- The map id for naked events to be hosted on
-- Disallow users to equip items on the naked map
on_can_equip(function(user, item, slot)
if (user.map == NAKED_MAP_ID) then
user:send_notice("You cannot equip items on this map!")
return false
end
return true
end)
The following are valid functions:
Code:
on_login(function(user) end) on_enter_map(function(user)) end on_item_effect(effect, function(user, variant) end on_can_recreate(function(itemdef, runedef, stats) end) on_recreation(function(itemdef, runedef, stats, maxreroll, rerollcount) end) on_can_equip(function(user, item, slot) end)
Code:
/**
* Defines the CUser type.
*/
void ScriptingEnvironment::defineUser() {
using namespace Shaiya::Models;
lua.new_usertype<CUser>("user",
// Get user fields
"get_name", [](CUser* self) -> const char* {
return self->name;
},
// Stats
"level", &CUser::level,
"kills", &CUser::kills,
"deaths", &CUser::deaths,
"victories", &CUser::victories,
"defeats", &CUser::defeats,
"statpoints", &CUser::statpoints,
"skillpoints", &CUser::skillpoints,
"current_hitpoints", &CUser::hitpoints,
"max_hitpoints", &CUser::maxHitpoints,
"current_mana", &CUser::mana,
"max_mana", &CUser::maxMana,
"current_stamina", &CUser::stamina,
"max_stamina", &CUser::maxStamina,
// Position
"zone", &CUser::zone,
"map", &CUser::map,
"x", &CUser::posX,
"y", &CUser::posY,
"z", &CUser::posZ,
// Appearance
"gender", &CUser::gender,
// Items
"equipment", &CUser::equipment,
// Ability Values
"health_regen", &CUser::regenHitpoints,
"mana_regen", &CUser::regenMana,
"stamina_regen", &CUser::regenStamina,
// Account
"points", &CUser::points,
"status", &CUser::adminStatus,
// Teleports the user
"teleport", [](CUser * self, int map, float x, float y, float z) {
Shaiya::Utils::UserUtils::teleport(self, map, x, y, z);
},
// Heals the user
"heal", [](CUser* self, int heal) {
int health[3] = { heal, 0, 0 };
Shaiya::Utils::UserUtils::heal(self, health);
},
// Send a notice to the user
"send_notice", [](CUser* self, std::string message) {
Shaiya::Utils::UserUtils::sendNotice(self, message);
},
// Get an item to the user
"give_item", [](CUser* self, int type, int typeId, int count) {
Shaiya::Utils::UserUtils::giveItem(self, type, typeId, count);
},
// Delete an item from the user's inventory
"delete_item", [](CUser* self, int bag, int slot) {
Shaiya::Utils::UserUtils::deleteItem(self, bag, slot);
},
// Spawn a mob on the user
"spawn_mob", [](CUser* self, int mob) {
Shaiya::Utils::MobUtils::spawnMob(self, mob);
}
);
}
/**
* Defines the item types
*/
void ScriptingEnvironment::defineItems() {
using namespace Shaiya::Models;
// Item definition
lua.new_usertype<stItemInfo>("item_info",
"type", &stItemInfo::type,
"type_id", &stItemInfo::typeId,
"item_id", &stItemInfo::itemId,
"effect", &stItemInfo::effect,
"variant", &stItemInfo::variant,
"max_reroll", &stItemInfo::maxReroll,
"reroll_count", &stItemInfo::rerollCount,
"get_name", [](stItemInfo* self) {
return self->name;
}
);
}
/**
* Defines the actor type
*/
void ScriptingEnvironment::defineActors() {
using namespace Shaiya::Entity;
// Attributes
lua.new_usertype<Attributes>("Attributes",
"hitpoints", &Attributes::hitpoints,
"max_hitpoints", &Attributes::maxHitpoints
);
// Position
lua.new_usertype<Position>("Position",
"map", &Position::map,
"x", &Position::x,
"y", &Position::y,
"z", &Position::z
);
// Render Info
lua.new_usertype<RenderInfo>("RenderInfo",
"set_mob_transform", &RenderInfo::setMobTransformation,
"get_mob_transform", &RenderInfo::getMobTransformation,
"is_visible", &RenderInfo::isVisible,
"set_visible", &RenderInfo::setVisible
);
// Actor definition
lua.new_usertype<Actor>("Actor",
// Define the constructor for the actor
"create", [](std::string name) -> Actor* {
return new Actor(name);
},
"get_render_info", &Actor::getRenderInfo,
"get_position", &Actor::getPosition,
"set_position", [](Actor* self, int map, float x, float y, float z) {
auto position = self->getPosition();
position.x = x;
position.y = y;
position.z = z;
}
);
}






,