Skip to content

Commit

Permalink
Update readme, move EZWand.CreateVirtualWand to wand:Deploy
Browse files Browse the repository at this point in the history
Make deployed wands start visible instead of hidden
  • Loading branch information
TheHorscht committed Jul 14, 2024
1 parent 0faa3ee commit f60d41a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
13 changes: 6 additions & 7 deletions EZWand.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- #########################################
-- ####### EZWand version vIF YOU SEE THIS I FORGOT TO UPDATE THE VERSION NUMBER AGAIN #######
-- ####### EZWand v2.2.0 #######
-- #########################################

dofile_once("data/scripts/gun/procedural/gun_action_utils.lua")
Expand Down Expand Up @@ -1525,10 +1525,6 @@ local function create_virtual_wand(from, rng_seed_x, rng_seed_y)
-- Update the sprite to add the 0.5 offset
o:SetSprite(o:GetSprite())
local wand_entity_id = wand.entity_id
for i, comp in ipairs(EntityGetComponent(wand_entity_id, "SpriteComponent") or {}) do
EntitySetComponentIsEnabled(wand_entity_id, comp, false)
ComponentRemoveTag(comp, "enabled_in_hand")
end
protected.hotspot_comp = EntityGetFirstComponentIncludingDisabled(wand_entity_id, "HotspotComponent", "shoot_pos")
if protected.hotspot_comp then
protected.shoot_offset_x, protected.shoot_offset_y = ComponentGetValue2(protected.hotspot_comp, "offset")
Expand All @@ -1555,6 +1551,10 @@ local function create_virtual_wand(from, rng_seed_x, rng_seed_y)
return o
end

function wand:Deploy(x, y)
return create_virtual_wand(self.entity_id, x, y)
end

local function shoot_spell_sequence(sequence, from_x, from_y, target_x, target_y, herd)
local wand = create_virtual_wand({
shuffle = false,
Expand Down Expand Up @@ -1586,8 +1586,7 @@ return setmetatable({}, {
RenderTooltip = render_tooltip,
IsWand = entity_is_wand,
GetHeldWand = get_held_wand,
ShootSpellSequence = shoot_spell_sequence,
CreateVirtualWand = create_virtual_wand
ShootSpellSequence = shoot_spell_sequence
})[key]
end
})
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ local image_file, offset_x, offset_y, tip_x, tip_y = wand:GetSprite()
-- freeze_wand {boolean} prevents spells from being added to the wand or moved
-- freeze_spells {boolean} prevents the spells from being removed
wand:SetFrozen(freeze_wand, freeze_spells)
-- Create an invisible wand and shoot it once!
EZWand.ShootSpellSequence({ "LIGHT_BULLET_TRIGGER", "BOMB" }, source_x, source_y, target_x, target_y)
-- Create an invisible wand and shoot it once! 'herd' is a herd string like "player" or "zombie"
-- Won't hurt anyone who is the same herd, if not specified will default to player
EZWand.ShootSpellSequence({ "LIGHT_BULLET_TRIGGER", "BOMB" }, source_x, source_y, target_x, target_y, herd)
-- This will give the wand to an entity and make the entity be able to use wands, entity will drop the wand on death
-- !!! DON'T USE THIS FOR THE PLAYER, use wand:PutInPlayersInventory() instead !!!
wand:GiveTo(entity_id)
```
***
Naming convention for the functions is Add/Remove for regular spells and Attach/Detach for always cast spells.
Expand Down Expand Up @@ -169,6 +173,26 @@ You can always use your regular functions like EntityGetComponent etc using
```lua
EntityHasTag(wand.entity_id, "wand")
```
## Shooting a virtual wand / Deploying a controllable wand
```lua
-- Create the wand however you like
local wand = EZWand()
local deployed_wand = wand:Deploy(x, y) -- Takes the x and y coordinates where it should be deployed
-- Can use it's sprite or be invisible, when invisible will shoot from the entity center, otherwise from its usual wand sprite shoot offset
deployed_wand.visible = false
deployed_wand.rotation = 0 -- Angle in radians
-- All wand manipulation functions are available for it too:
deployed_wand:AddSpells("BOMB")
-- Here's what is exclusvie to deployed wands:
-- Will turn towards the target
deployed_wand:AimAt(target_x, target_y)
-- Will turn and shoot at a specified position
deployed_wand:ShootAt(target_x, target_y)
-- Shoots in the direction it is currently pointing
deployed_wand:Shoot()
-- Moves the wand to target location
deployed_wand:SetPosition(x, y)
```
## Rendering a wand tooltip
To render a wand tooltip you can use EZWand.RenderTooltip() to render a tooltip based on some predefined properties (no need for the wand to exist), or you can use
wand:RenderTooltip() to render the tooltip of an existing wand.
Expand Down
4 changes: 2 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
UNRELEASED:
- Add EZWand.CreateVirtualWand(from_wand_type, x, y)
v2.2.0:
- Add wand:Deploy(x, y)
- Add wand:GiveTo(entity_id)
- Add a herd argument to EZWand.ShootSpellSequence(sequence, source_x, source_y, target_x, target_y, herd)

Expand Down

0 comments on commit f60d41a

Please sign in to comment.