Ticket #966: api_projectile_destroyed.lua

File api_projectile_destroyed.lua, 1.3 KB (added by Bluestone, 7 years ago)

gadget part

Line 
1function gadget:GetInfo()
2 return {
3 name = "Projectile Destroyed",
4 desc = "Passes projectile destroyed event to widgets",
5 author = "Bluestone",
6 date = "",
7 license = "GPL v2 or later",
8 layer = 0,
9 enabled = true -- loaded by default
10 }
11end
12
13if gadgetHandler:IsSyncedCode() then
14
15 function gadget:Initialize()
16 for wDID,_ in pairs(WeaponDefs) do
17 Script.SetWatchWeapon(wDID, true) --it would be better not to watch everything if we don't have too, i suspect there is a performance cost to this
18 end
19 end
20
21 function gadget:ProjectileDestroyed(proID)
22 Spring.Echo("synced gadget", proID)
23 local x,y,z = Spring.GetProjectilePosition(proID)
24 SendToUnsynced("ProjectileDestroyed", proID, x, y, z)
25 end
26
27else
28
29 function gadget:Initialize()
30 gadgetHandler:AddSyncAction("ProjectileDestroyed", ProjectileDestroyed)
31 end
32
33 function ProjectileDestroyed(_,proID,x,y,z)
34 Spring.Echo("unsynced gadget", proID)
35 if Script.LuaUI and Script.LuaUI("ReceiveProjectileDestroyed") then
36 Script.LuaUI.ReceiveProjectileDestroyed(proID, x, y, z)
37 end
38 end
39
40 function gadget:Shutdown()
41 gadgetHandler:RemoveSyncAction("ProjectileDestroyed")
42 end
43
44end