weapons.qc (4194B)
1 2 void(float to) SwitchWeapon = 3 { 4 if(self.weapon == to) 5 return; 6 if(time < self.ready && self.readystate != SWITCHING) 7 return; 8 if(!(self.items & to)) 9 { 10 sprint(self, PRINT_HIGH, "No weapon.\n"); 11 return; 12 } 13 14 self.ready = time + 0.150; 15 self.readystate = SWITCHING; 16 17 // sound(self, CHAN_BODY, "sounds/player/land.wav", 1, 1.75); 18 19 self.weapon = to; 20 21 WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); 22 WriteByte(MSG_MULTICAST, EVENT_WEAPONCHANGE); 23 WriteByte(MSG_MULTICAST, to); 24 msg_entity = self; 25 multicast('0 0 0', MULTICAST_ONE); 26 27 } 28 29 //called by shotgun 30 //TODO: combine multiple shots into single damage call 31 void(float shotcount, float spread, float damage) FireBullets = 32 { 33 local vector vorg, dir; 34 makevectors(self.v_angle); 35 36 msg_entity = self; 37 38 while (shotcount > 0) 39 { 40 dir = v_forward + (v_right * (random() - 0.5)*spread) + (v_up * (random() - 0.5)*spread); 41 vorg = self.origin + '0 0 22'; 42 traceline(vorg, vorg + dir * 16000, FALSE, self); 43 44 //handled by CSQC_Parse_Event 45 WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); 46 WriteByte(MSG_MULTICAST, EVENT_PISTOLFIRE); 47 WriteEntity(MSG_MULTICAST, self); 48 WriteCoord(MSG_MULTICAST, trace_endpos_x); 49 WriteCoord(MSG_MULTICAST, trace_endpos_y); 50 WriteCoord(MSG_MULTICAST, trace_endpos_z); 51 WriteCoord(MSG_MULTICAST, trace_plane_normal_x); 52 WriteCoord(MSG_MULTICAST, trace_plane_normal_y); 53 WriteCoord(MSG_MULTICAST, trace_plane_normal_z); 54 WriteEntity(MSG_MULTICAST, trace_ent); 55 multicast(trace_endpos, MULTICAST_PHS); 56 57 shotcount = shotcount - 1; 58 T_Damage(trace_ent, self, self, damage); 59 } 60 } 61 62 void() FirePistol = 63 { 64 if(self.ammo_pistol <= 0) 65 { 66 return; 67 } 68 //local float damage; 69 local vector vorg, dir; 70 makevectors(self.v_angle); 71 dir = v_forward + (v_right * (random() - 0.5)*0.005) + (v_up * (random() - 0.5)*0.005); 72 vorg = self.origin + '0 0 22'; 73 traceline(vorg, vorg + dir * 16000, FALSE, self); 74 msg_entity = self; 75 76 //write some stuff for CSQC that is handled in CSQC_Parse_Event 77 WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); 78 WriteByte(MSG_MULTICAST, EVENT_PISTOLFIRE); 79 WriteEntity(MSG_MULTICAST, self); 80 WriteCoord(MSG_MULTICAST, trace_endpos_x); 81 WriteCoord(MSG_MULTICAST, trace_endpos_y); 82 WriteCoord(MSG_MULTICAST, trace_endpos_z); 83 WriteCoord(MSG_MULTICAST, trace_plane_normal_x); 84 WriteCoord(MSG_MULTICAST, trace_plane_normal_y); 85 WriteCoord(MSG_MULTICAST, trace_plane_normal_z); 86 WriteEntity(MSG_MULTICAST, trace_ent); 87 multicast(trace_endpos, MULTICAST_PHS); 88 89 // sound(self, CHAN_WEAPON, "sounds/weapons/mg.wav", 1, 0.4, 100 + (random() - 0.5) * 5); 90 self.ready = time + 0.15; 91 self.readystate = FIRING_SEMI; 92 self.ammo_pistol -= 1; 93 } 94 95 void() FireMG = 96 { 97 if(self.ammo_mg <= 0) 98 { 99 return; 100 } 101 //local float damage; 102 local vector vorg, dir; 103 makevectors(self.v_angle); 104 dir = v_forward + (v_right * (random() - 0.5)*0.025) + (v_up * (random() - 0.5)*0.025); 105 vorg = self.origin + '0 0 22'; 106 traceline(vorg, vorg + dir * 16000, FALSE, self); 107 msg_entity = self; 108 109 //write some stuff for CSQC that is handled in CSQC_Parse_Event 110 WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); 111 WriteByte(MSG_MULTICAST, EVENT_MGFIRE); 112 WriteEntity(MSG_MULTICAST, self); 113 WriteCoord(MSG_MULTICAST, trace_endpos_x); 114 WriteCoord(MSG_MULTICAST, trace_endpos_y); 115 WriteCoord(MSG_MULTICAST, trace_endpos_z); 116 WriteCoord(MSG_MULTICAST, trace_plane_normal_x); 117 WriteCoord(MSG_MULTICAST, trace_plane_normal_y); 118 WriteCoord(MSG_MULTICAST, trace_plane_normal_z); 119 WriteEntity(MSG_MULTICAST, trace_ent); 120 multicast(trace_endpos, MULTICAST_PHS); 121 122 sound(self, CHAN_WEAPON, "sounds/weapons/mg.wav", 1, 0.4, 100 + (random() - 0.5) * 5); 123 self.ready = time + 0.075; 124 self.readystate = FIRING; 125 self.ammo_mg -= 1; 126 } 127 128 void() FireWeapon = 129 { 130 if(time > self.ready) 131 { 132 if(self.readystate == FIRING_SEMI) 133 return; 134 else 135 self.readystate = READY; 136 137 switch(self.weapon) 138 { 139 case(IT_MG): 140 FireMG(); 141 break; 142 case(IT_PISTOL): //TODO: put all this in a function 143 if(self.ammo_pistol > 0) 144 { 145 sound(self, CHAN_WEAPON, "sounds/shotgun.wav", 1, ATTN_NORM); 146 FireBullets(14, .1, 20); 147 self.ready = time + 1.5; 148 self.readystate = FIRING; 149 self.ammo_pistol -= 1; 150 } 151 break; 152 } 153 } 154 }