1 .vector spawn_origin, spawn_angles;
3 void physical_item_think()
7 self.alpha = self.owner.alpha; // apply fading and ghosting
9 if(!self.cnt) // map item, not dropped
11 // copy ghost item properties
12 self.colormap = self.owner.colormap;
13 self.colormod = self.owner.colormod;
14 self.glowmod = self.owner.glowmod;
16 // if the item is not spawned, make sure the invisible / ghost item returns to its origin and stays there
17 if(autocvar_g_physical_items_reset)
19 if(self.owner.nextthink > time) // awaiting respawn
21 setorigin(self, self.spawn_origin);
22 self.angles = self.spawn_angles;
23 self.solid = SOLID_NOT;
24 self.movetype = MOVETYPE_NONE;
28 self.solid = SOLID_CORPSE;
29 self.movetype = MOVETYPE_PHYSICS;
34 if(!self.owner.modelindex)
35 remove(self); // the real item is gone, remove this
38 void physical_item_touch()
40 if(!self.cnt) // not for dropped items
41 if (ITEM_TOUCH_NEEDKILL())
43 setorigin(self, self.spawn_origin);
44 self.angles = self.spawn_angles;
48 void physical_item_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
50 if(!self.cnt) // not for dropped items
51 if(ITEM_DAMAGE_NEEDKILL(deathtype))
53 setorigin(self, self.spawn_origin);
54 self.angles = self.spawn_angles;
58 MUTATOR_HOOKFUNCTION(item_spawning)
60 if(self.owner == world && autocvar_g_physical_items <= 1)
62 if (self.spawnflags & 1) // floating item
65 // The actual item can't be physical and trigger at the same time, so make it invisible and use a second entity for physics.
66 // Ugly hack, but unless SOLID_TRIGGER is gotten to work with MOVETYPE_PHYSICS in the engine it can't be fixed.
69 setmodel(wep, self.model);
70 setsize(wep, self.mins, self.maxs);
71 setorigin(wep, self.origin);
72 wep.angles = self.angles;
73 wep.velocity = self.velocity;
76 wep.solid = SOLID_CORPSE;
77 wep.movetype = MOVETYPE_PHYSICS;
78 wep.takedamage = DAMAGE_AIM;
79 wep.effects |= EF_NOMODELFLAGS; // disable the spinning
80 wep.colormap = self.owner.colormap;
81 wep.glowmod = self.owner.glowmod;
82 wep.damageforcescale = autocvar_g_physical_items_damageforcescale;
83 wep.dphitcontentsmask = self.dphitcontentsmask;
84 wep.cnt = (self.owner != world);
86 wep.think = physical_item_think;
88 wep.touch = physical_item_touch;
89 wep.event_damage = physical_item_damage;
91 wep.spawn_origin = self.origin;
92 wep.spawn_angles = self.angles;
94 self.effects |= EF_NODRAW; // hide the original weapon
95 self.movetype = MOVETYPE_FOLLOW;
96 self.aiment = wep; // attach the original weapon
101 MUTATOR_DEFINITION(mutator_physical_items)
103 MUTATOR_HOOK(Item_Spawn, item_spawning, CBC_ORDER_ANY);
105 // check if we have a physics engine
108 if (!(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")))
110 dprint("Warning: Physical items are enabled but no physics engine can be used. Reverting to old items.\n");
115 MUTATOR_ONROLLBACK_OR_REMOVE
117 // nothing to roll back
122 print("This cannot be removed at runtime\n");