Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
467fc0dd
Commit
467fc0dd
authored
10 years ago
by
Loïc Blot
Browse files
Options
Downloads
Patches
Plain Diff
Add a Lua call to do damages / heals
parent
8f2e9bfb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
doc/lua_api.txt
+1
-0
1 addition, 0 deletions
doc/lua_api.txt
src/script/lua_api/l_object.cpp
+38
-3
38 additions, 3 deletions
src/script/lua_api/l_object.cpp
src/script/lua_api/l_object.h
+6
-0
6 additions, 0 deletions
src/script/lua_api/l_object.h
with
45 additions
and
3 deletions
doc/lua_api.txt
+
1
−
0
View file @
467fc0dd
...
...
@@ -2336,6 +2336,7 @@ This is basically a reference to a C++ `ServerActiveObject`
* `right_click(clicker)`; `clicker` is another `ObjectRef`
* `get_hp()`: returns number of hitpoints (2 * number of hearts)
* `set_hp(hp)`: set number of hitpoints (2 * number of hearts)
* `apply_damage(damage)`: set amount of damage to object. If damage < 0, heal the target
* `get_inventory()`: returns an `InvRef`
* `get_wield_list()`: returns the name of the inventory list the wielded item is in
* `get_wield_index()`: returns the index of the wielded item
...
...
This diff is collapsed.
Click to expand it.
src/script/lua_api/l_object.cpp
+
38
−
3
View file @
467fc0dd
...
...
@@ -29,6 +29,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include
"content_sao.h"
#include
"server.h"
#include
"hud.h"
#include
"settings.h"
#include
"main.h"
struct
EnumString
es_HudElementType
[]
=
...
...
@@ -255,10 +257,10 @@ int ObjectRef::l_set_hp(lua_State *L)
ObjectRef
*
ref
=
checkobject
(
L
,
1
);
luaL_checknumber
(
L
,
2
);
ServerActiveObject
*
co
=
getobject
(
ref
);
if
(
co
==
NULL
)
return
0
;
if
(
co
==
NULL
)
return
0
;
int
hp
=
lua_tonumber
(
L
,
2
);
/*infostream<<"ObjectRef::l_set_hp(): id="<<co->getId()
<<" hp="<<hp<<std::endl;*/
// Do it
co
->
setHP
(
hp
);
if
(
co
->
getType
()
==
ACTIVEOBJECT_TYPE_PLAYER
)
{
...
...
@@ -289,6 +291,38 @@ int ObjectRef::l_get_hp(lua_State *L)
return
1
;
}
// apply_damage(self, damage)
// damage = amount of damage to apply
// if damage is negative, heal the player
// returns: nil
int
ObjectRef
::
l_apply_damage
(
lua_State
*
L
)
{
NO_MAP_LOCK_REQUIRED
;
ObjectRef
*
ref
=
checkobject
(
L
,
1
);
luaL_checknumber
(
L
,
2
);
ServerActiveObject
*
co
=
getobject
(
ref
);
if
(
co
==
NULL
)
return
0
;
int
damage
=
lua_tonumber
(
L
,
2
);
// No damage, no heal => do nothing
if
(
damage
==
0
)
return
0
;
// If damage is positive (not healing) and damage is disabled, ignore
if
(
damage
>
0
&&
g_settings
->
getBool
(
"enable_damage"
)
==
false
)
return
0
;
// Do damage/heal
co
->
setHP
(
co
->
getHP
()
-
damage
);
if
(
co
->
getType
()
==
ACTIVEOBJECT_TYPE_PLAYER
)
{
getServer
(
L
)
->
SendPlayerHPOrDie
(((
PlayerSAO
*
)
co
)
->
getPeerID
(),
co
->
getHP
()
==
0
);
}
return
0
;
}
// get_inventory(self)
int
ObjectRef
::
l_get_inventory
(
lua_State
*
L
)
{
...
...
@@ -1345,6 +1379,7 @@ const luaL_reg ObjectRef::methods[] = {
luamethod
(
ObjectRef
,
right_click
),
luamethod
(
ObjectRef
,
set_hp
),
luamethod
(
ObjectRef
,
get_hp
),
luamethod
(
ObjectRef
,
apply_damage
),
luamethod
(
ObjectRef
,
get_inventory
),
luamethod
(
ObjectRef
,
get_wield_list
),
luamethod
(
ObjectRef
,
get_wield_index
),
...
...
This diff is collapsed.
Click to expand it.
src/script/lua_api/l_object.h
+
6
−
0
View file @
467fc0dd
...
...
@@ -83,6 +83,12 @@ class ObjectRef : public ModApiBase {
// 0 if not applicable to this type of object
static
int
l_get_hp
(
lua_State
*
L
);
// apply_damage(self, damage)
// damage = amount of damage to apply
// if damage is negative, heal the player
// returns: nil
static
int
l_apply_damage
(
lua_State
*
L
);
// get_inventory(self)
static
int
l_get_inventory
(
lua_State
*
L
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment