10-27-2014, 12:40 AM
Specifically, I want to modify the void cPlayer::HandleFood(void) function (https://github.com/mc-server/MCServer/bl....cpp#L1934) in order to disable natural regen to emulate the Ultra Hardcore game mode.
Having said that, while digging around the code to find the part that I would want to modify, I also found that one could also lower or raise the threshold at which natural regen occurs as well as extending the time between food tick timer loops. I'd prefer to be able to change these things with a plugin rather than having to recompile every time I change for testing purposes (because what else are plugins for?) and since I am proficient with Lua I'm now wondering how to go about this. Is there a tutorial/guide somewhere?
Firstly, does this new functionality require a new hook? HOOK_PLAYER_FOOD_TICK perhaps? Its function could be:
The only issue with this approach is it doesn't give the chance to modify the hunger threshold for doing food ticks (m_FoodLevel >= 18 by default). Should this whole plugin be done instead with HOOK_TICK? That way I could just replace cplayer::HandleFood with some Lua:
Anyway, I'm super excited about being able to write plugins in Lua because I'm very comfortable with Lua, I'm just not sure how high the barrier for entry to this project is and am looking for guidance on the matter.
I'm new to the project as of today having seen reference to it in /r/admincraft and am already very impressed by everything I've seen! Except the lack of tutorials I guess
Having said that, while digging around the code to find the part that I would want to modify, I also found that one could also lower or raise the threshold at which natural regen occurs as well as extending the time between food tick timer loops. I'd prefer to be able to change these things with a plugin rather than having to recompile every time I change for testing purposes (because what else are plugins for?) and since I am proficient with Lua I'm now wondering how to go about this. Is there a tutorial/guide somewhere?
Firstly, does this new functionality require a new hook? HOOK_PLAYER_FOOD_TICK perhaps? Its function could be:
Code:
function OnPlayerFoodTick(Player, FoodTickTimer)
The only issue with this approach is it doesn't give the chance to modify the hunger threshold for doing food ticks (m_FoodLevel >= 18 by default). Should this whole plugin be done instead with HOOK_TICK? That way I could just replace cplayer::HandleFood with some Lua:
Code:
Player:HandleFood()
foodThreshold = 18
foodTickCycle = 80
foodExhaustion = 3
if IsGameModeCreative() then
// Hunger is disabled for Creative
return
end
// Apply food exhaustion that has accumulated:
if Player.FoodExhaustionLevel > 4 then
Player.FoodExhaustionLevel = FoodExhaustionLevel - 4
if Player.FoodSaturationLevel > 0 then
Player.FoodSaturationLevel = math.max(Player.FoodSaturationLevel - 1, 0)
else
Player:SetFoodLevel(Player.FoodLevel - 1)
end
end
// Heal or damage, based on the food level, using the m_FoodTickTimer:
if Player.FoodLevel >= foodThreshold or Player.FoodLevel <= 0 then
{
Player.FoodTickTimer = Player.FoodTickTimer + 1
if Player.FoodTickTimer >= foodTickCycle then
Player.FoodTickTimer = 0;
if Player.FoodLevel >= foodThreshold and Player.GetHealth() < Player.GetMaxHealth() then
// Regenerate health from food, incur x pts of food exhaustion:
Player:Heal(1)
Player:AddFoodExhaustion(foodExhaustion)
elseif Player.FoodLevel <= 0 and Player.Health > 1 then
// Damage from starving
Player:TakeDamage(dtStarving, nullptr, 1, 1, 0)
end
end
else
Player.FoodTickTimer = 0
end
end
Anyway, I'm super excited about being able to write plugins in Lua because I'm very comfortable with Lua, I'm just not sure how high the barrier for entry to this project is and am looking for guidance on the matter.
I'm new to the project as of today having seen reference to it in /r/admincraft and am already very impressed by everything I've seen! Except the lack of tutorials I guess