-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.txt
170 lines (130 loc) · 6.33 KB
/
api.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Tables
------
projectile.registered_projectiles
A per-category list of lists, the categories being types of ranged weapons like "bow", "slingshot", etc.
Within each category, key-value pairs are listed to link together the entity and item forms of ammo
The item's name is the key, the entity's name is the value.
projectile.charge_levels
A per-player list of lists that keeps track of data regarding ranged weapons that are currently being used.
Whenever a weapon charge-up is cancelled, the charge_levels entry for that player will be cleared.
When a weapon is being charged up, a table for that weapon's user is created containing the following:
{
slot = <index of wielded ranged weapon>,
charge = <number>
}
Regristration Functions
-----------------------
projectile.register_weapon(name, definition)
--Register a new ranged weapon
--Inherits from minetest.register_tool
description = "Description",
inventory_image = "image.png",
inventory_image_2 = "image_charged.png",
inventory_image_3 = "image_charged_full.png",
--When creating a weapon that can be charged, you should provide different sprites when charging the weapon
--and when the weapon is fully charged.
durability = 100,
--Defines how many times this weapon can be used before breaking.
rw_category = "category",
--A projectile weapon may only fire ammo types in the same category.
--This mod provides "bow", "flintlock", and "slingshot"
--You can use a custom category, as long as you also register custom ammo
charge = false,
--If true, right clicking will put the weapon in a charging state.
--Once charging, right-click again to fire, or left-click to cancel.
--If a weapon doesn't charge, right-clicking will always fire.
--Defaults to false
fire_while_charging = false,
--If true, the weapon doesn't need to be fully charged to be fired.
--A partially charged shot will still be weaker than a fully charged one, however.
--Does nothing if charge is false
--Defaults to false
charge_time = 1,
--The amount of time in seconds to finish charging.
--Does nothing if charge is false
--Defaults to false.
damage = 1,
--A damage multiplier applied to fired projectiles
speed = 1,
--A multiplier to the projectile's initial velocity
can_fire = function(weapon, user)
--Use this to create extra conditions for when a weapon can be fired.
--Can't be used to negate the need for ammo.
--Defaults to always return true.
on_charge_begin = function(wep, user)
--This function is called just after the user right-clicks to start charging the weapon.
--Has no return value.
on_charge_full = function(wep, user)
--This function is called the moment that the weapon becomes fully charged.
--Has no return value.
on_cancel = function(weapon, user)
--This function is called whenever a charge is cut short, either by left-clicking, switching the selected hotbar index, or leaving the game.
--Has no return value.
on_fire = function(wep, user)
--This function is called just before the projectile is created.
--Has no return value.
after_fire = function(weapon, user)
--This function is called just after the projectile is created.
--Has no return value.
projectile.register_projectile(name, usable_by, ammo, definition)
--Register a new projectile entity and an associated ammo item.
--Note that this function will NOT register a new item for you. Use one of minetest's normal item registration functions instead.
--Inherits from minetest.register_entity.
--usable_by: This should match the rw_category of the weapon that you want to use this ammo.
--ammo: The name of the item that is consumed to create this projectile.
image = "image.png",
--A shortcut for initial_properties.texture. You can ignore this if you define a mesh for the projectile.
damage = 5,
--The base damage that this projectile deals.
speed = 15,
--The base initial velocity of this projectile, in meters/nodes per second.
count = 1,
--The amount of projectiles that is created per shot.
--Meant for shotgun-like effects.
--defaults to 1
spread = 0,
--The radius, in degrees, that projectiles can spread away from the player's look direction.
--Defaults to 0
collide_self = true,
--As long as its true, a player can shoot their own projectiles.
--If false, two projectiles owned by the same player will phase through each other.
--Defaults to true.
_on_step = function(self, dtime, moveresult)
--Use this function to give your projectile an on_step callback.
--If you try to use the regular on_step, it will be overwritten.
on_impact = function(self, collisions)
--This function is called when a node or object is struck.
--Has no return value.
--collisions is a table taken from on_step's moveresult, which contains the following:
{
type = string, -- "node" or "object",
axis = string, -- "x", "y" or "z"
node_pos = vector, -- if type is "node"
object = ObjectRef, -- if type is "object"
old_velocity = vector,
new_velocity = vector,
}
Misc Functions
--------------
projectile.shoot(wep, user, level)
--Shoot out a projectile at the user's position.
--Afterwards, deplete the ammo used and add wear to the weapon used.
--level: The charge level at the time of firing.
function projectile.in_same_party(projectile, target)
--If the parties mod is enabled, this checks if the projectile's owner is in the same party as the target.
--Always returns false if the parties mod is not present.
projectile.autorotate_arrow(self)
--Meant to be given to an arrow projectile's _on_step method, when that arrow uses a mesh.
--This causes the arrow to spin as it travels.
--Spin speed is dependent on velocity.
projectile.needs_gunpowder(wep, user)
--Meant to be given to a flintlock's can_fire function.
--Searches the user's main inventory for tnt:gunpowder.
--If none is found, return false to prevent firing.
--If some is found, consume it and return true.
--If the player is already charging, skip this check and automatically return true. No need to take two gunpowder.
projectile.return_gunpowder(wep, user)
--Meant to be used with a flintlock's on_cancel function.
--projectile.needs_gunpowder takes gunpowder right before a charge is started.
--This means that gunpowder needs to be added back to the inventory if the charge is cancelled.
--If no space is left in the inventory for the gunpowder, drop it on the ground instead.