Skip to content

Instantly share code, notes, and snippets.

@jocelynduc
Created July 20, 2014 21:06
Show Gist options
  • Save jocelynduc/7313dd64f1bb40195790 to your computer and use it in GitHub Desktop.
Save jocelynduc/7313dd64f1bb40195790 to your computer and use it in GitHub Desktop.
void CActor::OnDrink(float fWater) {
if (fWater > 0.0f) {
float oldWater = GetWater();
float newWater = oldWater + fWater;
SetWater(newWater);
}
}
function BasicActor:OnDrink(fWater)
self.actor:OnDrink(fWater);
end
SCRIPT_REG_TEMPLFUNC(OnDrink, "fWater");
...
int CScriptBind_Actor::OnDrink(IFunctionHandler *pH, float fWater)
{
CActor *pActor = GetActor(pH);
if (!pActor) return pH->EndFunction();
pActor->OnDrink(fWater);
return pH->EndFunction();
}
<Entity
Name="Well"
Script="Scripts/Entities/Others/Well.lua"
/>
Script.ReloadScript( "Scripts/Entities/Actor/BasicActor.lua");
Well = {
Properties = {
-- need a model...
object_Model = "Objects/props/furniture/appliances/ceiling_fan/ceiling_fan.cgf",
fWater = 20,
bUsable = 1,
sUseMessage = "Drink",
Physics = {
bRigidBody = 0,
bRigidBodyActive = 0,
bRigidBodyAfterDeath =1,
bResting = 1,
Density = -1,
Mass = 150,
},
},
Editor = {
Icon = "animobject.bmp",
IconOnTop = 1,
}
}
MakeUsable(Well);
-- Default entity functions
function Well:OnInit()
self:OnReset();
end
function Well:OnSpawn()
self:OnReset();
end
function Well:OnReset()
if (self.Properties.object_Model ~= "") then
self:LoadObject(0, self.Properties.object_Model);
end
self:PhysicalizeThis();
end
function Well:PhysicalizeThis()
EntityCommon.PhysicalizeRigid(self, 0, self.Properties.Physics, 1);
end
function Well:OnPropertyChange()
self:OnReset();
end
-- Usable entity functions
function Well:IsUsable(userId)
index = 1;
return index;
end
function Well:GetUsableMessage(index)
return self.Properties.sUseMessage;
end
function Well:OnUsed(userId, index)
userId:OnDrink(tonumber(20));
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment