5 .vector spawn_origin, spawn_angles;
7 void physical_item_think()
11 self.alpha = self.owner.alpha; // apply fading and ghosting
13 if(!self.cnt) // map item, not dropped
15 // copy ghost item properties
16 self.colormap = self.owner.colormap;
17 self.colormod = self.owner.colormod;
18 self.glowmod = self.owner.glowmod;
20 // if the item is not spawned, make sure the invisible / ghost item returns to its origin and stays there
21 if(autocvar_g_physical_items_reset)
23 if(self.owner.nextthink > time) // awaiting respawn
25 setorigin(self, self.spawn_origin);
26 self.angles = self.spawn_angles;
27 self.solid = SOLID_NOT;
28 self.movetype = MOVETYPE_NONE;
32 self.solid = SOLID_CORPSE;
33 self.movetype = MOVETYPE_PHYSICS;
38 if(!self.owner.modelindex)
39 remove(self); // the real item is gone, remove this
42 void physical_item_touch()
44 if(!self.cnt) // not for dropped items
45 if (ITEM_TOUCH_NEEDKILL())
47 setorigin(self, self.spawn_origin);
48 self.angles = self.spawn_angles;
52 void physical_item_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
54 if(!self.cnt) // not for dropped items
55 if(ITEM_DAMAGE_NEEDKILL(deathtype))
57 setorigin(self, self.spawn_origin);
58 self.angles = self.spawn_angles;
62 MUTATOR_HOOKFUNCTION(item_spawning)
64 if(self.owner == world && autocvar_g_physical_items <= 1)
66 if (self.spawnflags & 1) // floating item
69 // The actual item can't be physical and trigger at the same time, so make it invisible and use a second entity for physics.
70 // Ugly hack, but unless SOLID_TRIGGER is gotten to work with MOVETYPE_PHYSICS in the engine it can't be fixed.
73 setmodel(wep, self.model);
74 setsize(wep, self.mins, self.maxs);
75 setorigin(wep, self.origin);
76 wep.angles = self.angles;
77 wep.velocity = self.velocity;
80 wep.solid = SOLID_CORPSE;
81 wep.movetype = MOVETYPE_PHYSICS;
82 wep.takedamage = DAMAGE_AIM;
83 wep.effects |= EF_NOMODELFLAGS; // disable the spinning
84 wep.colormap = self.owner.colormap;
85 wep.glowmod = self.owner.glowmod;
86 wep.damageforcescale = autocvar_g_physical_items_damageforcescale;
87 wep.dphitcontentsmask = self.dphitcontentsmask;
88 wep.cnt = (self.owner != world);
90 wep.think = physical_item_think;
92 wep.touch = physical_item_touch;
93 wep.event_damage = physical_item_damage;
95 wep.spawn_origin = self.origin;
96 wep.spawn_angles = self.angles;
98 self.effects |= EF_NODRAW; // hide the original weapon
99 self.movetype = MOVETYPE_FOLLOW;
100 self.aiment = wep; // attach the original weapon
105 MUTATOR_DEFINITION(mutator_physical_items)
107 MUTATOR_HOOK(Item_Spawn, item_spawning, CBC_ORDER_ANY);
109 // check if we have a physics engine
112 if (!(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")))
114 dprint("Warning: Physical items are enabled but no physics engine can be used. Reverting to old items.\n");
119 MUTATOR_ONROLLBACK_OR_REMOVE
121 // nothing to roll back
126 print("This cannot be removed at runtime\n");