标签:des style blog io ar color os sp for
Weapon.inc
1 new const m_flNextAttack = 83 2 new const m_flVelocityModifier = 108 3 new const m_iTeam = 114 4 new const m_iAccount = 115 5 new const m_iWeaponVolume = 239 6 new const m_pActiveItem = 373 7 new const m_rgpPlayerItems[] = { 367, 368, 369, 370, 371, 372 } 8 new const m_rgAmmo[] = { 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407 } // int 9 new const m_szAnimExtention = 492 * 4 10 new const m_iAutoWepSwitch = 509 11 new const m_pPlayer = 41 12 new const m_pNext = 42 13 new const m_iId = 43 14 new const m_flNextPrimaryAttack = 46 15 new const m_flNextSecondaryAttack = 47 16 new const m_flTimeWeaponIdle = 48 17 new const m_iPrimaryAmmoType = 49 18 new const m_iClip = 51 19 new const m_fInReload = 54 20 new const m_fInSpecialReload = 55 21 new const m_iWeaponState = 74 22 new const m_flLastFire = 63 23 24 new g_fwPlayerPostThink 25 26 #define SLOT_PRIMARY 1 27 #define SLOT_SECONDARY 2 28 #define SLOT_MELEE 3 29 #define SLOT_THROW 4 30 31 #define KNIFE_BODYHIT_VOLUME 128 32 #define KNIFE_WALLHIT_VOLUME 512 33 34 #define CLASS_PLAYER 2 35 #define CLASS_HUMAN_PASSIVE 3 36 37 #define RESULT_HIT_NONE 0 38 #define RESULT_HIT_PLAYER 1 39 #define RESULT_HIT_WORLD 2 40 41 new const g_szWpnName[][] = { "", "weapon_p228", "", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10", "weapon_aug", "weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550", "weapon_galil", "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249", "weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552", "weapon_ak47", "weapon_knife", "weapon_p90" } 42 43 new const g_iWpnPrimary = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90) 44 new const g_iWpnSecondary = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE) 45 new const g_iWpnMelee = (1<<CSW_KNIFE) 46 new const g_iWpnThrow = (1<<CSW_HEGRENADE)|(1<<CSW_SMOKEGRENADE)|(1<<CSW_FLASHBANG) 47 48 new const g_iWpnAnimReload[] = { 0, 5, 0, 3, 0, 7, 0, 1, 1, 0, 14, 4, 1, 3, 1, 1, 13, 7, 4, 1, 3, 7, 11, 1, 3, 0, 4, 1, 1, 0, 1 } 49 50 enum WpnData_e 51 { 52 _iWpnId, 53 _szModel[48], 54 _szModel_P[128], 55 _szModel_V[128], 56 _szModel_W[128], 57 _szName[48], 58 _szAnimExtention[32], 59 _szShootSound[128], 60 _szExplodeSound[128], 61 _iType, 62 _iClip, 63 _iAmmo, 64 _iZoom, 65 _iExplodeSpr, // He 66 _iSprSize, // He 67 _iSprFps, // He 68 _iTailLen, // He 69 _iTailSize, // He 70 _iTailR, // He 71 _iTailG, // He 72 _iTailB, // He 73 _iTailA, // He 74 Float:_flDeploy, 75 Float:_flReload, 76 Float:_flAttackInterval, 77 Float:_flAttackInterval_Stab, // Knife & (pir/sec melee attack) 78 Float:_flMaxSpeed, 79 Float:_flKnockback, 80 Float:_flKnockback_Stab, // Knife 81 Float:_flRecoil, 82 Float:_flDamage, 83 Float:_flDamage_Stab, // Knife & (pir/sec melee attack) 84 Float:_flRange, // Knife & (pir/sec melee attack) 85 Float:_flRange_Stab, // Knife 86 Float:_flAngle, // Knife & (pir/sec melee attack) 87 Float:_flAngle_Stab, // Knife 88 Float:_flDelay, // Knife & (pir/sec melee attack) && He 89 Float:_flDelayStab, // Knife 90 Float:_flGravity, // He 91 Float:_flVelocity, // He 92 Float:_flVelocityModifier 93 } 94 95 #define WPNDATA_FILE "WpnData.ini" 96 97 const MAX_WPN = 256 98 99 new g_WpnData[MAX_WPN][WpnData_e] 100 new g_iWpnCount 101 102 enum UserWpn_e 103 { 104 _qWpnIndex, 105 _qClip, 106 _qBpAmmo 107 } 108 109 new g_UserWpn[33][6][UserWpn_e] 110 new Float:g_PunchAngle[33][3] 111 112 new g_iHeSprEffect 113 114 #define TASK_MELEE (iPlayer + 100) 115 116 new g_iFwResult 117 new g_fwPlayerSpawn 118 new g_fwPlayerDeath 119 new g_fwLoadWpn 120 new g_fwWpnDeploy 121 new g_fwUpdateAmmo
Weapon.sma
1 #include <amxmodx> 2 #include <hamsandwich> 3 #include <fakemeta> 4 #include <xs> 5 6 #include "acg.inc" 7 8 #include "Weapon.inc" 9 10 public plugin_init() 11 { 12 register_plugin("SUIC_WPN", "0.0.0.1", "crsky") 13 14 // Engine Message 15 register_message(get_user_msgid("Money"), "Fw_UpdateMoney") 16 register_message(get_user_msgid("WeapPickup"), "Fw_WeapPickup") 17 register_message(get_user_msgid("AmmoPickup"), "Fw_AmmoPickup") 18 register_message(get_user_msgid("CurWeapon"), "Fw_UpdateAmmo") 19 20 // Fakemeta Forward 21 g_fwPlayerPostThink = register_forward(FM_PlayerPostThink, "Fw_PlayerPostThink") 22 register_forward(FM_SetModel, "Fw_SetEntityModel") 23 register_forward(FM_PlaybackEvent, "Fw_PlaybackEvent") 24 register_forward(FM_EmitSound, "Fw_EmitSound") 25 26 // Ham Forward for Weapon 27 for(new i = 1; i < 31; i++) 28 { 29 if(!strlen(g_szWpnName[i])) continue 30 31 RegisterHam(Ham_Item_Deploy, g_szWpnName[i], "Fw_WeaponDeploy_Post", 1) 32 RegisterHam(Ham_Weapon_PrimaryAttack, g_szWpnName[i], "Fw_WeaponPrimaryAttack_Post", 1) 33 RegisterHam(Ham_Weapon_PrimaryAttack, g_szWpnName[i], "Fw_WeaponPrimaryAttack") 34 RegisterHam(Ham_Weapon_SecondaryAttack, g_szWpnName[i], "Fw_WeaponSecondaryAttack") 35 RegisterHam(Ham_Item_PostFrame, g_szWpnName[i], "Fw_WeaponPostFrame_Post", 1) 36 RegisterHam(Ham_Item_PostFrame, g_szWpnName[i], "Fw_WeaponPostFrame") 37 } 38 39 // Ham Forward 40 RegisterHam(Ham_Spawn, "player", "Fw_PlayerSpawn_Post", 1) 41 RegisterHam(Ham_Killed, "player", "Fw_PlayerDeath_Post", 1) 42 RegisterHam(Ham_Touch, "weaponbox", "Fw_TouchWeaponBox") 43 RegisterHam(Ham_TraceAttack, "player", "Fw_TraceAttack") 44 RegisterHam(Ham_TakeDamage, "player", "Fw_TakeDamage") 45 RegisterHam(Ham_TakeDamage, "player", "Fw_TakeDamage_Post", 1) 46 RegisterHam(Ham_Think, "grenade", "Fw_ThinkGrenade") 47 48 // Client Command 49 register_clcmd("qq", "Fw_Debug") 50 51 // Cvars 52 register_cvar("suic_wpn_wmodel_gravity", "2.5") 53 register_cvar("suic_wpn_wmodel_velocity", "0.8") 54 55 // Forward 56 g_fwPlayerSpawn = CreateMultiForward("Forward_PlayerSpawn", ET_IGNORE, FP_CELL) 57 g_fwPlayerDeath = CreateMultiForward("Forward_PlayerDeath", ET_IGNORE, FP_CELL) 58 g_fwLoadWpn = CreateMultiForward("Forward_LoadWpn", ET_IGNORE, FP_STRING) 59 g_fwWpnDeploy = CreateMultiForward("Forward_WpnDeploy", ET_IGNORE, FP_CELL) 60 g_fwUpdateAmmo = CreateMultiForward("Forward_UpdateAmmo", ET_IGNORE, FP_CELL) 61 } 62 63 public Fw_Debug(iPlayer) 64 { 65 66 return PLUGIN_HANDLED 67 } 68 69 public plugin_natives() 70 { 71 register_native("SUIC_GetWpnSlot", "Native_GetWpnSlot", 1) 72 } 73 74 public plugin_cfg() 75 { 76 server_cmd("mp_consistency 0") 77 } 78 79 public plugin_precache() 80 { 81 g_iHeSprEffect = engfunc(EngFunc_PrecacheModel, "sprites/shadow_circle.spr") 82 83 Stock_LoadWpnData() 84 } 85 86 public Fw_UpdateMoney(iMsg, iDest, iEnt) 87 { 88 set_pdata_int(iEnt, m_iAccount, 0) 89 return PLUGIN_HANDLED 90 } 91 92 public Fw_WeapPickup(iMsg, iDest, iEnt) 93 { 94 return PLUGIN_HANDLED 95 } 96 97 public Fw_AmmoPickup(iMsg, iDest, iEnt) 98 { 99 return PLUGIN_HANDLED 100 } 101 102 public Fw_UpdateAmmo(iMsg, iDest, iEnt) 103 { 104 if(!is_user_alive(iEnt) || !get_msg_arg_int(1)) return 105 ExecuteForward(g_fwUpdateAmmo, g_iFwResult, iEnt) 106 } 107 108 public Fw_PlayerPostThink(iPlayer) 109 { 110 if(!is_user_bot(iPlayer)) 111 return 112 113 unregister_forward(FM_PlayerPostThink, g_fwPlayerPostThink) 114 115 // Ham Forward for bot 116 RegisterHamFromEntity(Ham_Spawn, iPlayer, "Fw_PlayerSpawn_Post", 1) 117 RegisterHamFromEntity(Ham_Killed, iPlayer, "Fw_PlayerDeath_Post", 1) 118 RegisterHamFromEntity(Ham_TraceAttack, iPlayer, "Fw_TraceAttack") 119 RegisterHamFromEntity(Ham_TakeDamage, iPlayer, "Fw_TakeDamage") 120 RegisterHamFromEntity(Ham_TakeDamage, iPlayer, "Fw_TakeDamage_Post", 1) 121 } 122 123 public Fw_PlayerSpawn_Post(iPlayer) 124 { 125 if(!get_pdata_int(iPlayer, m_iTeam)) return 126 127 for(new i = 1; i < 6; i++) 128 { 129 Stock_StripSlot(iPlayer, i) 130 131 g_UserWpn[iPlayer][i][_qWpnIndex] = 0 132 g_UserWpn[iPlayer][i][_qClip] = 0 133 g_UserWpn[iPlayer][i][_qBpAmmo] = 0 134 } 135 136 // Default Wpn 137 Stock_GiveWeapon(iPlayer, "SHOVEL") 138 139 Stock_GiveWeapon(iPlayer, "BARRET") 140 Stock_GiveWeapon(iPlayer, "DUALDESERTEAGLE") 141 Stock_GiveWeapon(iPlayer, "HEGRENADE") 142 143 // Execute Spawn Forward 144 ExecuteForward(g_fwPlayerSpawn, g_iFwResult, iPlayer) 145 } 146 147 public Fw_PlayerDeath_Post(iPlayer) 148 { 149 if(task_exists(TASK_MELEE)) 150 remove_task(TASK_MELEE) 151 152 // Execute Death Forward 153 ExecuteForward(g_fwPlayerDeath, g_iFwResult, iPlayer) 154 } 155 156 public Fw_WeaponDeploy_Post(iWpnEnt) 157 { 158 new iPlayer = get_pdata_cbase(iWpnEnt, m_pPlayer) 159 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 160 new iWpnIndex = g_UserWpn[iPlayer][iSlot][_qWpnIndex] 161 162 // Remove MeleeAttack 163 if(task_exists(TASK_MELEE)) 164 remove_task(TASK_MELEE) 165 166 // Execute WpnDeploy Forward 167 ExecuteForward(g_fwWpnDeploy, g_iFwResult, iWpnEnt) 168 169 if(!iWpnIndex) 170 { 171 // server_print("[WPN] Unknow weapon deploy.") 172 return 173 } 174 175 // Set Weapon Model 176 set_pev(iPlayer, pev_weaponmodel2, g_WpnData[iWpnIndex][_szModel_P]) 177 set_pev(iPlayer, pev_viewmodel2, g_WpnData[iWpnIndex][_szModel_V]) 178 set_pdata_string(iPlayer, m_szAnimExtention, g_WpnData[iWpnIndex][_szAnimExtention], -1, 20) 179 180 // Set DeployTime 181 set_pdata_float(iPlayer, m_flNextAttack, g_WpnData[iWpnIndex][_flDeploy]) 182 set_pdata_float(iWpnEnt, m_flNextPrimaryAttack, -1.0) 183 set_pdata_float(iWpnEnt, m_flNextSecondaryAttack, -1.0) 184 185 // Guns 186 if(iSlot == SLOT_PRIMARY || iSlot == SLOT_SECONDARY) 187 { 188 new iAmmoType = get_pdata_int(iWpnEnt, m_iPrimaryAmmoType) 189 new iClip = get_pdata_int(iWpnEnt, m_iClip) 190 new iBpAmmo = get_pdata_int(iPlayer, m_rgAmmo[iAmmoType]) 191 192 // Update Ammo 193 g_UserWpn[iPlayer][iSlot][_qClip] = iClip 194 g_UserWpn[iPlayer][iSlot][_qBpAmmo] = iBpAmmo 195 } 196 197 } 198 199 public Fw_SetEntityModel(iEntity, const szModel[]) 200 { 201 if(!pev_valid(iEntity)) return FMRES_IGNORED 202 203 new iPlayer = pev(iEntity, pev_owner) 204 if(!is_user_connected(iPlayer)) return FMRES_IGNORED 205 206 // Grenade 207 if(equal(szModel, "models/w_hegrenade.mdl")) 208 { 209 new iWpnIndex = g_UserWpn[iPlayer][SLOT_THROW][_qWpnIndex] 210 if(!iWpnIndex) return FMRES_IGNORED 211 212 engfunc(EngFunc_SetModel, iEntity, g_WpnData[iWpnIndex][_szModel_W]) 213 214 set_pev(iEntity, pev_iuser1, iWpnIndex) 215 set_pev(iEntity, pev_gravity, g_WpnData[iWpnIndex][_flGravity]) 216 set_pev(iEntity, pev_dmgtime, get_gametime() + g_WpnData[iWpnIndex][_flDelay]) 217 218 new Float:velocity[3] 219 pev(iEntity, pev_velocity, velocity) 220 xs_vec_mul_scalar(velocity, g_WpnData[iWpnIndex][_flVelocity], velocity) 221 set_pev(iEntity, pev_velocity, velocity) 222 223 Stock_CreateEntityTail( 224 iEntity, 225 g_WpnData[iWpnIndex][_iTailLen], 226 g_WpnData[iWpnIndex][_iTailSize], 227 g_WpnData[iWpnIndex][_iTailR], 228 g_WpnData[iWpnIndex][_iTailG], 229 g_WpnData[iWpnIndex][_iTailB], 230 g_WpnData[iWpnIndex][_iTailA] 231 ) 232 233 g_UserWpn[iPlayer][SLOT_THROW][_qWpnIndex] = 0 234 return FMRES_SUPERCEDE 235 } 236 237 new szClassName[32] 238 pev(iEntity, pev_classname, szClassName, sizeof szClassName) 239 240 if(!equal(szClassName, "weaponbox")) 241 return FMRES_IGNORED 242 243 new szBuffer[128] 244 format(szBuffer, sizeof szBuffer, "%s", szModel) 245 246 replace(szBuffer, sizeof szBuffer, "models/w_", "") 247 replace(szBuffer, sizeof szBuffer, ".mdl", "") 248 249 if(equal(szBuffer, "mp5")) format(szBuffer, sizeof szBuffer, "mp5navy") 250 format(szBuffer, sizeof szBuffer, "weapon_%s", szBuffer) 251 252 new iWpnId = get_weaponid(szBuffer) 253 if(!iWpnId) return FMRES_IGNORED 254 255 new iSlot = Stock_GetWpnSlot(iWpnId) 256 new iWpnIndex = g_UserWpn[iPlayer][iSlot][_qWpnIndex] 257 258 if(!iWpnIndex) return FMRES_IGNORED 259 260 engfunc(EngFunc_SetModel, iEntity, g_WpnData[iWpnIndex][_szModel_W]) 261 262 set_pev(iEntity, pev_gravity, get_cvar_float("suic_wpn_wmodel_gravity")) 263 264 new Float:velocity[3] 265 pev(iEntity, pev_velocity, velocity) 266 xs_vec_mul_scalar(velocity, get_cvar_float("suic_wpn_wmodel_velocity"), velocity) 267 set_pev(iEntity, pev_velocity, velocity) 268 269 set_pev(iEntity, pev_iuser1, iWpnIndex) 270 set_pev(iEntity, pev_iuser2, g_UserWpn[iPlayer][iSlot][_qClip]) 271 set_pev(iEntity, pev_iuser3, g_UserWpn[iPlayer][iSlot][_qBpAmmo]) 272 273 g_UserWpn[iPlayer][iSlot][_qWpnIndex] = 0 274 g_UserWpn[iPlayer][iSlot][_qClip] = 0 275 g_UserWpn[iPlayer][iSlot][_qBpAmmo] = 0 276 277 return FMRES_SUPERCEDE 278 } 279 280 public Fw_TouchWeaponBox(iWeaponBox, iPlayer) 281 { 282 if(!pev_valid(iWeaponBox) || !is_user_connected(iPlayer)) 283 return HAM_IGNORED 284 285 new Float:vec[3] 286 pev(iWeaponBox, pev_velocity, vec) 287 288 if(vec[0] != 0.0 || vec[1] != 0.0 || vec[2] != 0.0) 289 return HAM_IGNORED 290 291 set_pdata_int(iPlayer, m_iAutoWepSwitch, 0) 292 293 new iWpnIndex = pev(iWeaponBox, pev_iuser1) 294 new iClip = pev(iWeaponBox, pev_iuser2) 295 new iBpAmmo = pev(iWeaponBox, pev_iuser3) 296 297 if(!iWpnIndex) return HAM_IGNORED 298 299 new iSlot = Stock_GetWpnSlot(g_WpnData[iWpnIndex][_iWpnId]) 300 new iItem = get_pdata_cbase(iPlayer, m_rgpPlayerItems[iSlot]) 301 302 // Now has weapon 303 if(iItem != -1) return HAM_IGNORED 304 305 if(!Stock_GiveWeapon(iPlayer, g_WpnData[iWpnIndex][_szModel])) 306 { 307 server_print("[WPN] Can not give weapon %s.", g_WpnData[iWpnIndex][_szModel]) 308 return HAM_SUPERCEDE 309 } 310 311 iItem = get_pdata_cbase(iPlayer, m_rgpPlayerItems[iSlot]) 312 313 if(!pev_valid(iItem)) 314 { 315 server_print("[WPN] Can not get %s entity.", g_WpnData[iWpnIndex][_szModel]) 316 return HAM_SUPERCEDE 317 } 318 319 new iAmmoType = get_pdata_int(iItem, m_iPrimaryAmmoType) 320 321 set_pdata_int(iItem, m_iClip, iClip) 322 set_pdata_int(iPlayer, m_rgAmmo[iAmmoType], iBpAmmo) 323 324 engfunc(EngFunc_RemoveEntity, iWeaponBox) 325 326 Stock_AutoWepSwitch(iPlayer) 327 return HAM_SUPERCEDE 328 } 329 330 public Fw_WeaponPrimaryAttack_Post(iWpnEnt) 331 { 332 new iPlayer = get_pdata_cbase(iWpnEnt, m_pPlayer) 333 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 334 new iWpnIndex = g_UserWpn[iPlayer][iSlot][_qWpnIndex] 335 336 if(!iWpnIndex) return 337 338 if(iSlot == SLOT_PRIMARY || iSlot == SLOT_SECONDARY) 339 { 340 new iAmmoType = get_pdata_int(iWpnEnt, m_iPrimaryAmmoType) 341 new iClip = get_pdata_int(iWpnEnt, m_iClip) 342 new iBpAmmo = get_pdata_int(iPlayer, m_rgAmmo[iAmmoType]) 343 344 // Set AttackInterval 345 set_pdata_float(iWpnEnt, m_flNextPrimaryAttack, g_WpnData[iWpnIndex][_flAttackInterval]) 346 347 // Set Recoil 348 new Float:push[3] 349 pev(iPlayer, pev_punchangle, push) 350 xs_vec_sub(push, g_PunchAngle[iPlayer], push) 351 xs_vec_mul_scalar(push, g_WpnData[iWpnIndex][_flRecoil], push) 352 xs_vec_add(push, g_PunchAngle[iPlayer], push) 353 set_pev(iPlayer, pev_punchangle, push) 354 355 // Update Ammo 356 g_UserWpn[iPlayer][iSlot][_qClip] = iClip 357 g_UserWpn[iPlayer][iSlot][_qBpAmmo] = iBpAmmo 358 359 } 360 } 361 362 public Fw_WeaponPrimaryAttack(iWpnEnt) 363 { 364 new iPlayer = get_pdata_cbase(iWpnEnt, m_pPlayer) 365 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 366 new iWpnIndex = g_UserWpn[iPlayer][iSlot][_qWpnIndex] 367 368 if(!iWpnIndex) return 369 370 if(iSlot == SLOT_PRIMARY || iSlot == SLOT_SECONDARY) 371 { 372 // Save punchangle for recoil 373 pev(iPlayer, pev_punchangle, g_PunchAngle[iPlayer]) 374 } 375 } 376 377 public Fw_WeaponSecondaryAttack(iWpnEnt) 378 { 379 new iPlayer = get_pdata_cbase(iWpnEnt, m_pPlayer) 380 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 381 new iWpnIndex = g_UserWpn[iPlayer][iSlot][_qWpnIndex] 382 383 if(!iWpnIndex) return HAM_IGNORED 384 385 if(iSlot == SLOT_PRIMARY || iSlot == SLOT_SECONDARY) 386 { 387 new iWpnId = get_pdata_int(iWpnEnt, m_iId) 388 if((iWpnId == CSW_AUG || iWpnId == CSW_SG552) && !g_WpnData[iWpnIndex][_iZoom]) 389 return HAM_SUPERCEDE 390 } 391 392 return HAM_IGNORED 393 } 394 395 public Fw_WeaponPostFrame_Post(iWpnEnt) 396 { 397 new iPlayer = get_pdata_cbase(iWpnEnt, m_pPlayer) 398 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 399 new iWpnIndex = g_UserWpn[iPlayer][iSlot][_qWpnIndex] 400 401 if(!iWpnIndex) return 402 403 if(iSlot == SLOT_PRIMARY || iSlot == SLOT_SECONDARY) 404 { 405 new iButton = pev(iPlayer, pev_button) 406 new iClip = get_pdata_int(iWpnEnt, m_iClip) 407 new iAmmoType = get_pdata_int(iWpnEnt, m_iPrimaryAmmoType) 408 new iBpAmmo = get_pdata_int(iPlayer, m_rgAmmo[iAmmoType]) 409 new iWpnId = get_pdata_int(iWpnEnt, m_iId) 410 411 if(iButton & IN_RELOAD || get_pdata_int(iWpnEnt, m_fInSpecialReload)) 412 { 413 set_pdata_int(iWpnEnt, m_fInReload, 1) 414 set_pdata_int(iWpnEnt, m_fInSpecialReload, 0) 415 } 416 if(get_pdata_int(iWpnEnt, m_fInReload)) 417 { 418 if(iClip < g_WpnData[iWpnIndex][_iClip] && iBpAmmo) 419 { 420 set_pdata_float(iPlayer, m_flNextAttack, g_WpnData[iWpnIndex][_flReload]) 421 set_pdata_float(iWpnEnt, m_flTimeWeaponIdle, g_WpnData[iWpnIndex][_flReload] + 0.5) 422 Stock_SendWeaponAnim(iPlayer, g_iWpnAnimReload[iWpnId]) 423 } 424 else 425 { 426 set_pdata_float(iPlayer, m_flNextAttack, -1.0) 427 set_pdata_float(iWpnEnt, m_flTimeWeaponIdle, 0.5) 428 Stock_SendWeaponAnim(iPlayer, 0) 429 } 430 } 431 } 432 } 433 434 public Fw_WeaponPostFrame(iWpnEnt) 435 { 436 new iPlayer = get_pdata_cbase(iWpnEnt, m_pPlayer) 437 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 438 new iWpnIndex = g_UserWpn[iPlayer][iSlot][_qWpnIndex] 439 440 if(!iWpnIndex) return 441 442 new iButton = pev(iPlayer, pev_button) 443 444 if(iSlot == SLOT_PRIMARY || iSlot == SLOT_SECONDARY) 445 { 446 new iClip = get_pdata_int(iWpnEnt, m_iClip) 447 448 if(iClip >= g_WpnData[iWpnIndex][_iClip] && (iButton & IN_RELOAD)) 449 { 450 set_pev(iPlayer, pev_button, iButton & ~IN_RELOAD) 451 return 452 } 453 454 if(get_pdata_int(iWpnEnt, m_fInReload)) 455 { 456 457 new iAmmoType = get_pdata_int(iWpnEnt, m_iPrimaryAmmoType) 458 new iBpAmmo = get_pdata_int(iPlayer, m_rgAmmo[iAmmoType]) 459 460 new j = g_WpnData[iWpnIndex][_iClip] - iClip 461 j = min ( j, iBpAmmo ) 462 463 set_pdata_int(iWpnEnt, m_iClip, iClip + j) 464 set_pdata_int(iPlayer, m_rgAmmo[iAmmoType], iBpAmmo - j) 465 466 set_pdata_int(iWpnEnt, m_fInReload, 0) 467 } 468 return 469 } 470 if(iSlot == SLOT_MELEE) 471 { 472 set_pev(iPlayer, pev_button, iButton & ~(IN_ATTACK|IN_ATTACK2)) 473 474 new Float:flNextPrimaryAttack = get_pdata_float(iWpnEnt, m_flNextPrimaryAttack) 475 new Float:flNextSecondaryAttack = get_pdata_float(iWpnEnt, m_flNextSecondaryAttack) 476 477 if(flNextPrimaryAttack > 0.0 || flNextSecondaryAttack > 0.0) 478 return 479 480 if(iButton & IN_ATTACK) 481 { 482 new Float:AttackInterval = g_WpnData[iWpnIndex][_flAttackInterval] 483 484 set_pdata_float(iWpnEnt, m_flNextPrimaryAttack, AttackInterval) 485 set_pdata_float(iWpnEnt, m_flNextSecondaryAttack, AttackInterval) 486 set_pdata_float(iWpnEnt, m_flTimeWeaponIdle, AttackInterval + 0.5) 487 488 if(get_gametime() - get_pdata_float(iWpnEnt, m_flLastFire) > AttackInterval+0.25) 489 set_pdata_int(iWpnEnt, m_iWeaponState, 0) 490 491 set_pdata_float(iWpnEnt, m_flLastFire, get_gametime()) 492 493 if(!get_pdata_int(iWpnEnt, m_iWeaponState)) 494 { 495 set_pdata_int(iWpnEnt, m_iWeaponState, 1) 496 Stock_SendWeaponAnim(iPlayer, 1) 497 } 498 else 499 { 500 set_pdata_int(iWpnEnt, m_iWeaponState, 0) 501 Stock_SendWeaponAnim(iPlayer, 2) 502 } 503 504 Stock_UseDelayMeleeAttack(iPlayer, iWpnIndex, 0) 505 return 506 } 507 if(iButton & IN_ATTACK2) 508 { 509 new Float:AttackInterval = g_WpnData[iWpnIndex][_flAttackInterval_Stab] 510 511 set_pdata_float(iWpnEnt, m_flNextPrimaryAttack, AttackInterval) 512 set_pdata_float(iWpnEnt, m_flNextSecondaryAttack, AttackInterval) 513 set_pdata_float(iWpnEnt, m_flTimeWeaponIdle, AttackInterval + 0.5) 514 515 Stock_SendWeaponAnim(iPlayer, 4) 516 Stock_UseDelayMeleeAttack(iPlayer, iWpnIndex, 1) 517 return 518 } 519 return 520 } 521 } 522 523 public Fw_TraceAttack(iVictim, iAttacker, Float:flDamage, Float:Direction[3], iTracehandle, iDamageType) 524 { 525 if(!is_user_connected(iVictim) || !is_user_connected(iAttacker) || iVictim == iAttacker) 526 return 527 528 if(get_pdata_int(iVictim, m_iTeam) == get_pdata_int(iAttacker, m_iTeam)) 529 return 530 531 new iWpnEnt = get_pdata_cbase(iAttacker, m_pActiveItem) 532 if(!pev_valid(iWpnEnt)) return 533 534 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 535 new iWpnIndex = g_UserWpn[iAttacker][iSlot][_qWpnIndex] 536 537 if(!iWpnIndex) return 538 539 new Float:velocity[3] 540 pev(iVictim, pev_velocity, velocity) 541 xs_vec_mul_scalar(Direction, flDamage, Direction) 542 xs_vec_mul_scalar(Direction, g_WpnData[iWpnIndex][_flKnockback], Direction) 543 xs_vec_add(velocity, Direction, Direction) 544 set_pev(iVictim, pev_velocity, Direction) 545 546 } 547 548 public Fw_TakeDamage(iVictim, iInflictor, iAttacker, Float:flDamage, iDamageType) 549 { 550 if(!pev_valid(iVictim) || !pev_valid(iInflictor) || !is_user_connected(iAttacker) || iVictim == iAttacker) 551 return 552 553 if(get_pdata_int(iVictim, m_iTeam) == get_pdata_int(iAttacker, m_iTeam)) 554 return 555 556 new szClassName[32] 557 pev(iInflictor, pev_classname, szClassName, sizeof szClassName) 558 559 new iWpnEnt = get_pdata_cbase(iAttacker, m_pActiveItem) 560 if(!pev_valid(iWpnEnt)) return 561 562 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 563 564 // Ignore Melee 565 if(iSlot == SLOT_MELEE) return 566 567 // Grenade or Guns 568 new iWpnIndex = equal(szClassName, "grenade") ? pev(iInflictor, pev_iuser1) : g_UserWpn[iAttacker][iSlot][_qWpnIndex] 569 570 if(!iWpnIndex) return 571 572 SetHamParamFloat(4, flDamage * g_WpnData[iWpnIndex][_flDamage]) 573 574 } 575 576 public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:flDamage, iDamageType) 577 { 578 if(!pev_valid(iVictim) || !pev_valid(iInflictor) || !is_user_connected(iAttacker) || iVictim == iAttacker) 579 return 580 581 if(get_pdata_int(iVictim, m_iTeam) == get_pdata_int(iAttacker, m_iTeam)) 582 return 583 584 new iWpnEnt = get_pdata_cbase(iAttacker, m_pActiveItem) 585 if(!pev_valid(iWpnEnt)) return 586 587 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 588 589 // Ignore Melee 590 if(iSlot == SLOT_MELEE) return 591 592 new iWpnIndex = g_UserWpn[iAttacker][iSlot][_qWpnIndex] 593 594 if(!iWpnIndex) return 595 596 // Set VelocityModifier 597 set_pdata_float(iVictim, m_flVelocityModifier, g_WpnData[iWpnIndex][_flVelocityModifier]) 598 } 599 600 public Fw_PlaybackEvent(iFlags, iPlayer, iEvent, Float:fDelay, Float:vecOrigin[3], Float:vecAngle[3], Float:flParam1, Float:flParam2, iParam1, iParam2, bParam1, bParam2) 601 { 602 if(!is_user_connected(iPlayer)) return 603 604 new iWpnEnt = get_pdata_cbase(iPlayer, m_pActiveItem) 605 if(!pev_valid(iWpnEnt)) return 606 607 new iSlot = ExecuteHam(Ham_Item_ItemSlot, iWpnEnt) 608 609 new iWpnIndex = g_UserWpn[iPlayer][iSlot][_qWpnIndex] 610 if(!iWpnIndex) return 611 612 engfunc(EngFunc_EmitSound, iPlayer, CHAN_AUTO, g_WpnData[iWpnIndex][_szShootSound], VOL_NORM, ATTN_NORM, 0, PITCH_NORM) 613 614 } 615 616 public Fw_TaskMeleeAttack(const iParam[]) 617 { 618 Stock_UseMeleeAttack(iParam[0], iParam[1], iParam[2]) 619 } 620 621 public Fw_ThinkGrenade(iEntity) 622 { 623 if(!pev_valid(iEntity) || pev(iEntity, pev_iuser2)) 624 return 625 626 new Float:flDmgTime 627 pev(iEntity, pev_dmgtime, flDmgTime) 628 629 if(flDmgTime > get_gametime()) 630 return 631 632 set_pev(iEntity, pev_iuser2, 1) 633 634 new iWpnIndex = pev(iEntity, pev_iuser1) 635 if(!iWpnIndex) return 636 637 engfunc(EngFunc_EmitSound, iEntity, CHAN_AUTO, g_WpnData[iWpnIndex][_szExplodeSound], 1.0, ATTN_NORM, 0, PITCH_NORM) 638 Stock_CreateEntityExplode(iEntity, g_WpnData[iWpnIndex][_iExplodeSpr], g_WpnData[iWpnIndex][_iSprSize], g_WpnData[iWpnIndex][_iSprFps]) 639 640 } 641 642 public Fw_EmitSound(iPlayer, iChan, const szSample[], Float:flVolume, Float:flAttn, iFlags, iPitch) 643 { 644 if(equal(szSample, "weapons/knife_deploy1.wav")) return FMRES_SUPERCEDE 645 if(equal(szSample, "items/gunpickup2.wav")) return FMRES_SUPERCEDE 646 if(equal(szSample, "weapons/debris1.wav")) return FMRES_SUPERCEDE 647 if(equal(szSample, "weapons/debris2.wav")) return FMRES_SUPERCEDE 648 if(equal(szSample, "weapons/debris3.wav")) return FMRES_SUPERCEDE 649 return FMRES_IGNORED 650 } 651 652 public Native_GetWpnSlot(iWpnId) 653 { 654 return Stock_GetWpnSlot(iWpnId) 655 } 656 657 stock Stock_LoadWpnData() 658 { 659 new szConfigDir[64] 660 get_localinfo("amxx_configsdir", szConfigDir, sizeof szConfigDir) 661 662 new szPath[64] 663 format(szPath, sizeof szPath, "%s/%s", szConfigDir, WPNDATA_FILE) 664 665 new hFile = fopen(szPath, "rb") 666 667 if(!hFile) 668 { 669 set_fail_state("Can not open WpnData.ini file.") 670 return 671 } 672 673 g_iWpnCount = 1 674 675 new szBuffer[128] 676 677 while(!feof(hFile)) 678 { 679 fgets(hFile, szBuffer, sizeof szBuffer) 680 trim(szBuffer) 681 682 if(szBuffer[0] != ‘[‘) continue 683 684 replace(szBuffer, sizeof szBuffer, "[", "") 685 replace(szBuffer, sizeof szBuffer, "]", "") 686 687 if(!strlen(szBuffer)) continue 688 689 Stock_LoadWpn(szPath, szBuffer) 690 } 691 692 fclose(hFile) 693 } 694 695 stock Stock_LoadWpn(const szPath[], const szModel[]) 696 { 697 if(!Stock_ReadConfigInt(szPath, szModel, "Load")) return 698 699 if(g_iWpnCount >= MAX_WPN) return 700 701 new i = g_iWpnCount 702 703 format(g_WpnData[i][_szModel], 48, "%s", szModel) 704 705 g_WpnData[i][_iWpnId] = Stock_GetWpnId(Stock_ReadConfigString2(szPath, szModel, "WeaponID")) 706 g_WpnData[i][_iType] = Stock_ReadConfigInt(szPath, szModel, "Type") 707 708 // Model 709 format(g_WpnData[i][_szModel_P], 48, "models/suic_wpn/p_%s.mdl", szModel) 710 format(g_WpnData[i][_szModel_V], 48, "models/suic_wpn/v_%s.mdl", szModel) 711 format(g_WpnData[i][_szModel_W], 48, "models/suic_wpn/p_%s.mdl", szModel) 712 engfunc(EngFunc_PrecacheModel, g_WpnData[i][_szModel_P]) 713 engfunc(EngFunc_PrecacheModel, g_WpnData[i][_szModel_V]) 714 engfunc(EngFunc_PrecacheModel, g_WpnData[i][_szModel_W]) 715 716 new szAmmoIcon[128] 717 format(szAmmoIcon, sizeof szAmmoIcon, "Targa/AMMOICON/%s_LINE.tga", szModel) 718 precache_generic(szAmmoIcon) 719 720 new iSlot = Stock_GetWpnSlot(g_WpnData[i][_iWpnId]) 721 722 // Common 723 Stock_ReadConfigString(szPath, szModel, "Name", g_WpnData[i][_szName], 48) 724 Stock_ReadConfigString(szPath, szModel, "AnimExtention", g_WpnData[i][_szAnimExtention], 32) 725 g_WpnData[i][_flDeploy] = _:Stock_ReadConfigFloat(szPath, szModel, "DeployTime") 726 g_WpnData[i][_flMaxSpeed] = _:Stock_ReadConfigFloat(szPath, szModel, "MaxSpeed") 727 g_WpnData[i][_flDamage] = _:Stock_ReadConfigFloat(szPath, szModel, "Damage") 728 g_WpnData[i][_flVelocityModifier] = _:Stock_ReadConfigFloat(szPath, szModel, "VelocityModifier") 729 730 // Guns 731 if(iSlot == SLOT_PRIMARY || iSlot == SLOT_SECONDARY) 732 { 733 g_WpnData[i][_iClip] = Stock_ReadConfigInt(szPath, szModel, "MaxClip") 734 g_WpnData[i][_iAmmo] = Stock_ReadConfigInt(szPath, szModel, "MaxAmmo") 735 g_WpnData[i][_iZoom] = Stock_ReadConfigInt(szPath, szModel, "Zoom") 736 g_WpnData[i][_flReload] = _:Stock_ReadConfigFloat(szPath, szModel, "ReloadTime") 737 g_WpnData[i][_flRecoil] = _:Stock_ReadConfigFloat(szPath, szModel, "Recoil") 738 739 if(g_WpnData[i][_iType] == 2) // Melee 740 { 741 g_WpnData[i][_flAttackInterval_Stab] = _:Stock_ReadConfigFloat(szPath, szModel, "AttackIntervalStab") 742 g_WpnData[i][_flDamage_Stab] = _:Stock_ReadConfigFloat(szPath, szModel, "DamageStab") 743 g_WpnData[i][_flRange] = _:Stock_ReadConfigFloat(szPath, szModel, "Range") 744 g_WpnData[i][_flAngle] = _:Stock_ReadConfigFloat(szPath, szModel, "Angle") 745 g_WpnData[i][_flDelay] = _:Stock_ReadConfigFloat(szPath, szModel, "Delay") 746 } 747 748 new szShootSound[128] 749 Stock_ReadConfigString(szPath, szModel, "ShootSound", szShootSound, 128) 750 format(g_WpnData[i][_szShootSound], 128, "weapons/suic_wpn/%s/%s_shoot.wav", szShootSound, szShootSound) 751 engfunc(EngFunc_PrecacheSound, g_WpnData[i][_szShootSound]) 752 } 753 754 // Guns & Melee 755 if(iSlot == SLOT_PRIMARY || iSlot == SLOT_SECONDARY || iSlot == SLOT_MELEE) 756 { 757 g_WpnData[i][_flAttackInterval] = _:Stock_ReadConfigFloat(szPath, szModel, "AttackInterval") 758 g_WpnData[i][_flKnockback] = _:Stock_ReadConfigFloat(szPath, szModel, "Knockback") 759 760 // Melee 761 if(iSlot == SLOT_MELEE) 762 { 763 g_WpnData[i][_flAttackInterval_Stab] = _:Stock_ReadConfigFloat(szPath, szModel, "AttackIntervalStab") 764 g_WpnData[i][_flKnockback_Stab] = _:Stock_ReadConfigFloat(szPath, szModel, "KnockbackStab") 765 g_WpnData[i][_flDamage_Stab] = _:Stock_ReadConfigFloat(szPath, szModel, "DamageStab") 766 g_WpnData[i][_flRange] = _:Stock_ReadConfigFloat(szPath, szModel, "Range") 767 g_WpnData[i][_flRange_Stab] = _:Stock_ReadConfigFloat(szPath, szModel, "RangeStab") 768 g_WpnData[i][_flAngle] = _:Stock_ReadConfigFloat(szPath, szModel, "Angle") 769 g_WpnData[i][_flAngle_Stab] = _:Stock_ReadConfigFloat(szPath, szModel, "AngleStab") 770 g_WpnData[i][_flDelay] = _:Stock_ReadConfigFloat(szPath, szModel, "Delay") 771 g_WpnData[i][_flDelayStab] = _:Stock_ReadConfigFloat(szPath, szModel, "DelayStab") 772 } 773 } 774 775 // He 776 if(iSlot == SLOT_THROW) 777 { 778 g_WpnData[i][_flGravity] = _:Stock_ReadConfigFloat(szPath, szModel, "Gravity") 779 g_WpnData[i][_flVelocity] = _:Stock_ReadConfigFloat(szPath, szModel, "Velocity") 780 g_WpnData[i][_flDelay] = _:Stock_ReadConfigFloat(szPath, szModel, "Delay") 781 g_WpnData[i][_iSprSize] = Stock_ReadConfigInt(szPath, szModel, "SprSize") 782 g_WpnData[i][_iSprFps] = Stock_ReadConfigInt(szPath, szModel, "SprFps") 783 g_WpnData[i][_iTailLen] = Stock_ReadConfigInt(szPath, szModel, "TailLen") 784 g_WpnData[i][_iTailSize] = Stock_ReadConfigInt(szPath, szModel, "TailSize") 785 g_WpnData[i][_iTailR] = Stock_ReadConfigInt(szPath, szModel, "TailR") 786 g_WpnData[i][_iTailG] = Stock_ReadConfigInt(szPath, szModel, "TailG") 787 g_WpnData[i][_iTailB] = Stock_ReadConfigInt(szPath, szModel, "TailB") 788 g_WpnData[i][_iTailA] = Stock_ReadConfigInt(szPath, szModel, "TailA") 789 790 new szHeSound[128] 791 Stock_ReadConfigString(szPath, szModel, "ExplodeSound", szHeSound, 128) 792 format(g_WpnData[i][_szExplodeSound], 128, "weapons/suic_wpn/%s/%s_boom.wav", szHeSound, szHeSound) 793 engfunc(EngFunc_PrecacheSound, g_WpnData[i][_szExplodeSound]) 794 795 new szExpSpr[128] 796 Stock_ReadConfigString(szPath, szModel, "ExplodeSpr", szExpSpr, 128) 797 format(szExpSpr, 128, "sprites/suic_wpn/%s_explode.spr", szExpSpr, szExpSpr) 798 g_WpnData[i][_iExplodeSpr] = engfunc(EngFunc_PrecacheModel, szExpSpr) 799 } 800 801 //Execute LoadWpn Forward 802 //ExecuteForward(g_fwLoadWpn, g_iFwResult, "Hello World!!!") 803 804 server_print("[WPN] Load %s (%s)", szModel, g_WpnData[i][_szName]) 805 g_iWpnCount++ 806 } 807 808 stock Stock_ReadConfigInt(const szPath[], const szItem[], const szKey[]) 809 { 810 new szBuffer[128] 811 Stock_ReadConfigString(szPath, szItem, szKey, szBuffer, sizeof szBuffer) 812 return str_to_num(szBuffer) 813 } 814 815 stock Float:Stock_ReadConfigFloat(const szPath[], const szItem[], const szKey[]) 816 { 817 new szBuffer[128] 818 Stock_ReadConfigString(szPath, szItem, szKey, szBuffer, sizeof szBuffer) 819 return str_to_float(szBuffer) 820 } 821 822 stock Stock_ReadConfigString2(const szPath[], const szItem[], const szKey[]) 823 { 824 new szBuffer[128] 825 Stock_ReadConfigString(szPath, szItem, szKey, szBuffer, sizeof szBuffer) 826 return szBuffer 827 } 828 829 stock Stock_ReadConfigString(const szPath[], const szItem[], const szKey[], szString[], iMaxLength) 830 { 831 new hFile = fopen(szPath, "rb") 832 833 if(!hFile) return 834 835 new szBuffer[128], szLeft[128], szRight[128] 836 837 while(!feof(hFile)) 838 { 839 fgets(hFile, szBuffer, sizeof szBuffer) 840 trim(szBuffer) 841 842 if(szBuffer[0] != ‘[‘) continue 843 844 replace(szBuffer, sizeof szBuffer, "[", "") 845 replace(szBuffer, sizeof szBuffer, "]", "") 846 847 if(!equali(szBuffer, szItem)) continue 848 849 while(!feof(hFile)) 850 { 851 fgets(hFile, szBuffer, sizeof szBuffer) 852 trim(szBuffer) 853 854 if(szBuffer[0] == ‘[‘) break 855 856 if(!szBuffer[0] || szBuffer[0] == ‘;‘ || szBuffer[0] == ‘/‘) continue 857 858 strtok(szBuffer, szLeft, sizeof szLeft, szRight, sizeof szRight, ‘=‘) 859 trim(szLeft) 860 trim(szRight) 861 862 if(!equali(szLeft, szKey)) continue 863 864 format(szString, iMaxLength, "%s", szRight) 865 break 866 } 867 break 868 } 869 870 fclose(hFile) 871 } 872 873 stock Stock_GetWpnId(const szName[]) 874 { 875 if(equali(szName, "p228")) return CSW_P228 876 if(equali(szName, "scout")) return CSW_SCOUT 877 if(equali(szName, "hegrenade")) return CSW_HEGRENADE 878 if(equali(szName, "xm1014")) return CSW_XM1014 879 if(equali(szName, "c4")) return CSW_C4 880 if(equali(szName, "mac10")) return CSW_MAC10 881 if(equali(szName, "aug")) return CSW_AUG 882 if(equali(szName, "smokegrenade")) return CSW_SMOKEGRENADE 883 if(equali(szName, "elite")) return CSW_ELITE 884 if(equali(szName, "fiveseven")) return CSW_FIVESEVEN 885 if(equali(szName, "ump45")) return CSW_UMP45 886 if(equali(szName, "sg550")) return CSW_SG550 887 if(equali(szName, "galil")) return CSW_GALIL 888 if(equali(szName, "famas")) return CSW_FAMAS 889 if(equali(szName, "usp")) return CSW_USP 890 if(equali(szName, "glock18")) return CSW_GLOCK18 891 if(equali(szName, "awp")) return CSW_AWP 892 if(equali(szName, "mp5navy")) return CSW_MP5NAVY 893 if(equali(szName, "m249")) return CSW_M249 894 if(equali(szName, "m3")) return CSW_M3 895 if(equali(szName, "m4a1")) return CSW_M4A1 896 if(equali(szName, "tmp")) return CSW_TMP 897 if(equali(szName, "g3sg1")) return CSW_G3SG1 898 if(equali(szName, "flashbang")) return CSW_FLASHBANG 899 if(equali(szName, "deagle")) return CSW_DEAGLE 900 if(equali(szName, "sg552")) return CSW_SG552 901 if(equali(szName, "ak47")) return CSW_AK47 902 if(equali(szName, "knife")) return CSW_KNIFE 903 if(equali(szName, "p90")) return CSW_P90 904 905 return 0 906 } 907 908 stock Stock_GiveWeapon(iPlayer, const szModel[]) 909 { 910 if(!is_user_alive(iPlayer)) return false 911 912 new iWpnIndex = Stock_GetWpnIndex(szModel) 913 914 if(!iWpnIndex) 915 { 916 server_print("[WPN] Weapon %s not found.", szModel) 917 return false 918 } 919 920 new iSlot = Stock_GetWpnSlot(g_WpnData[iWpnIndex][_iWpnId]) 921 Stock_StripSlot(iPlayer, iSlot) 922 923 new szClassName[32] 924 get_weaponname(g_WpnData[iWpnIndex][_iWpnId], szClassName, sizeof szClassName) 925 926 new iWpnEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, szClassName)) 927 928 if(!pev_valid(iWpnEnt)) 929 { 930 server_print("[WPN] Create %s entity fail.", szClassName) 931 return false 932 } 933 934 set_pev(iWpnEnt, pev_spawnflags, pev(iWpnEnt, pev_spawnflags) | SF_NORESPAWN) 935 dllfunc(DLLFunc_Spawn, iWpnEnt) 936 937 set_pdata_int(iPlayer, m_iAutoWepSwitch, 0) 938 939 new iSave = pev(iWpnEnt, pev_solid) 940 dllfunc(DLLFunc_Touch, iWpnEnt, iPlayer) 941 942 if(pev(iWpnEnt, pev_solid) == iSave) 943 { 944 server_print("[WPN] Give %s for player fail.", szClassName) 945 engfunc(EngFunc_RemoveEntity, iWpnEnt) 946 return false 947 } 948 949 g_UserWpn[iPlayer][iSlot][_qWpnIndex] = iWpnIndex 950 951 new iItem = get_pdata_cbase(iPlayer, m_rgpPlayerItems[iSlot]) 952 953 if(!pev_valid(iItem)) 954 { 955 server_print("[WPN] Can not get %s entity.", szClassName) 956 return false 957 } 958 959 if(iSlot == SLOT_PRIMARY || iSlot == SLOT_SECONDARY) 960 { 961 new iAmmoType = get_pdata_int(iItem, m_iPrimaryAmmoType) 962 new iClip = g_WpnData[iWpnIndex][_iClip] 963 new iBpAmmo = g_WpnData[iWpnIndex][_iAmmo] 964 965 set_pdata_int(iItem, m_iClip, iClip) 966 set_pdata_int(iPlayer, m_rgAmmo[iAmmoType], iBpAmmo) 967 968 g_UserWpn[iPlayer][iSlot][_qClip] = iClip 969 g_UserWpn[iPlayer][iSlot][_qBpAmmo] = iBpAmmo 970 } 971 972 if(Stock_GetWpnTypeCount(iPlayer) == 1) 973 { 974 ExecuteHamB(Ham_Item_Deploy, iItem) 975 } 976 977 Stock_AutoWepSwitch(iPlayer) 978 return true 979 } 980 981 stock Stock_GetWpnIndex(const szModel[]) 982 { 983 for(new i = 1; i < g_iWpnCount; i++) 984 { 985 if(equali(g_WpnData[i][_szModel], szModel)) return i 986 } 987 988 return 0 989 } 990 991 stock Stock_GetRandomWpn(iSlot) 992 { 993 new iWpns[MAX_WPN] 994 new cnt = 1 995 for(new i=1; i < g_iWpnCount; i++) 996 { 997 if(Stock_GetWpnSlot(g_WpnData[i][_iWpnId]) == iSlot) 998 { 999 iWpns[cnt] = i 1000 cnt++ 1001 } 1002 } 1003 1004 new szModel[64] 1005 new i = random_num(1, cnt-1) 1006 1007 if(!iWpns[i]) return szModel 1008 1009 format(szModel, sizeof szModel, "%s", g_WpnData[iWpns[i]][_szModel]) 1010 return szModel 1011 } 1012 1013 stock Stock_StripSlot(iPlayer, iSlot) 1014 { 1015 new iItem, iNext 1016 1017 iItem = get_pdata_cbase(iPlayer, m_rgpPlayerItems[iSlot]) 1018 1019 while(iItem > 0) 1020 { 1021 set_pev(iPlayer, pev_weapons, pev(iPlayer, pev_weapons) & ~(1<<get_pdata_int(iItem, m_iId))) 1022 1023 ExecuteHamB(Ham_Weapon_RetireWeapon, iItem) 1024 iNext = get_pdata_cbase(iItem, m_pNext) 1025 1026 ExecuteHamB(Ham_RemovePlayerItem, iPlayer, iItem) 1027 ExecuteHamB(Ham_Item_Kill, iItem) 1028 1029 iItem = iNext 1030 } 1031 1032 set_pdata_cbase(iPlayer, m_rgpPlayerItems[iSlot], -1) 1033 } 1034 1035 stock Stock_GetWpnTypeCount(iPlayer) 1036 { 1037 new count 1038 for(new i=1; i<6; i++) 1039 { 1040 if(get_pdata_cbase(iPlayer, m_rgpPlayerItems[i]) != -1) 1041 count++ 1042 } 1043 return count 1044 } 1045 1046 stock Stock_GetWpnSlot(iWeapon) 1047 { 1048 if((1<<iWeapon) & g_iWpnPrimary) return SLOT_PRIMARY 1049 if((1<<iWeapon) & g_iWpnSecondary) return SLOT_SECONDARY 1050 if((1<<iWeapon) & g_iWpnMelee) return SLOT_MELEE 1051 if((1<<iWeapon) & g_iWpnThrow) return SLOT_THROW 1052 1053 return 0 1054 } 1055 1056 stock Stock_AutoWepSwitch(iPlayer) 1057 { 1058 for(new i=1; i<6; i++) 1059 { 1060 new iItem = get_pdata_cbase(iPlayer, m_rgpPlayerItems[i]) 1061 1062 if(iItem != -1) 1063 { 1064 new iWpnId = get_pdata_int(iItem, m_iId) 1065 new szClassName[32] 1066 get_weaponname(iWpnId, szClassName, sizeof szClassName) 1067 1068 if(strlen(szClassName)) 1069 engclient_cmd(iPlayer, szClassName) 1070 1071 return 1072 } 1073 } 1074 } 1075 1076 stock Stock_SendWeaponAnim(iPlayer, iAnim) 1077 { 1078 set_pev(iPlayer, pev_weaponanim, iAnim) 1079 message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, _, iPlayer) 1080 write_byte(iAnim) 1081 write_byte(pev(iPlayer, pev_body)) 1082 message_end() 1083 } 1084 1085 stock Stock_CreateEntityTail(iEntity, iLength, iSize, iR, iG, iB, iA) 1086 { 1087 message_begin(MSG_BROADCAST, SVC_TEMPENTITY) 1088 write_byte(TE_BEAMFOLLOW) 1089 write_short(iEntity) 1090 write_short(g_iHeSprEffect) 1091 write_byte(iLength) 1092 write_byte(iSize) 1093 write_byte(iR) 1094 write_byte(iG) 1095 write_byte(iB) 1096 write_byte(iA) 1097 message_end() 1098 } 1099 1100 stock Stock_CreateEntityExplode(iEntity, iSprIndex, iSize, iFps) 1101 { 1102 new Float:vecOrigin[3] 1103 pev(iEntity, pev_origin, vecOrigin) 1104 1105 message_begin(MSG_BROADCAST,SVC_TEMPENTITY) 1106 write_byte(TE_EXPLOSION) 1107 engfunc(EngFunc_WriteCoord, vecOrigin[0]) 1108 engfunc(EngFunc_WriteCoord, vecOrigin[1]) 1109 engfunc(EngFunc_WriteCoord, vecOrigin[2]) 1110 write_short(iSprIndex) 1111 write_byte(iSize) 1112 write_byte(iFps) 1113 write_byte(TE_EXPLFLAG_NONE) 1114 message_end() 1115 } 1116 1117 stock Stock_UseDelayMeleeAttack(iPlayer, iWpnIndex, bStab=0) 1118 { 1119 new Float:flDelay = bStab ? g_WpnData[iWpnIndex][_flDelayStab] : g_WpnData[iWpnIndex][_flDelay] 1120 1121 if(flDelay >= 0.0) 1122 { 1123 new iParam[3] 1124 iParam[0] = iPlayer 1125 iParam[1] = iWpnIndex 1126 iParam[2] = bStab 1127 if(task_exists(iPlayer+100)) remove_task(iPlayer+100) 1128 set_task(flDelay, "Fw_TaskMeleeAttack", iPlayer+100, iParam, sizeof iParam) 1129 } 1130 else 1131 { 1132 Stock_UseMeleeAttack(iPlayer, iWpnIndex, bStab) 1133 } 1134 } 1135 1136 stock Stock_UseMeleeAttack(iPlayer, iWpnIndex, bStab) 1137 { 1138 new Float:flKnockBack = bStab ? g_WpnData[iWpnIndex][_flKnockback_Stab] : g_WpnData[iWpnIndex][_flKnockback] 1139 new Float:flAngle = bStab ? g_WpnData[iWpnIndex][_flAngle_Stab] : g_WpnData[iWpnIndex][_flAngle] 1140 new Float:flRange = bStab ? g_WpnData[iWpnIndex][_flRange_Stab] : g_WpnData[iWpnIndex][_flRange] 1141 new Float:flDamage = bStab ? g_WpnData[iWpnIndex][_flDamage_Stab] : g_WpnData[iWpnIndex][_flDamage] 1142 1143 if(flAngle > 0.0) Stock_KnifeAttackAngle(iPlayer, 0, flRange, flAngle, flDamage, flKnockBack, -1) 1144 else Stock_KnifeAttack(iPlayer, 0, flRange, flDamage, flKnockBack, -1) 1145 } 1146 1147 stock Stock_KnifeAttack(id, bStab, Float:flRange, Float:flDamage, Float:flKnockBack, iHitgroup) 1148 { 1149 new Float:vecSrc[3], Float:vecEnd[3], Float:v_angle[3], Float:vecForward[3] 1150 Stock_GetGunPosition(id, vecSrc) 1151 1152 pev(id, pev_v_angle, v_angle) 1153 engfunc(EngFunc_MakeVectors, v_angle) 1154 1155 global_get(glb_v_forward, vecForward) 1156 xs_vec_mul_scalar(vecForward, flRange, vecForward) 1157 1158 xs_vec_add(vecSrc, vecForward, vecEnd) 1159 1160 new tr = create_tr2() 1161 engfunc(EngFunc_TraceLine, vecSrc, vecEnd, 0, id, tr) 1162 1163 new Float:flFraction 1164 get_tr2(tr, TR_flFraction, flFraction) 1165 1166 if (flFraction >= 1.0) 1167 { 1168 engfunc(EngFunc_TraceHull, vecSrc, vecEnd, 0, 3, id, tr) 1169 } 1170 1171 get_tr2(tr, TR_flFraction, flFraction) 1172 1173 new iHitResult = RESULT_HIT_NONE 1174 new Float:flVol = 1.0 1175 1176 if (flFraction < 1.0) 1177 { 1178 new pEntity = get_tr2(tr, TR_pHit) 1179 1180 iHitResult = RESULT_HIT_WORLD 1181 1182 if (pev_valid(pEntity) && (Stock_IsPlayer(pEntity) || Stock_IsHostage(pEntity))) 1183 { 1184 if (Stock_CheckBack(id, pEntity) && bStab && iHitgroup == -1) 1185 flDamage *= 3.0 1186 1187 iHitResult = RESULT_HIT_PLAYER 1188 1189 set_pdata_int(id, m_iWeaponVolume, KNIFE_BODYHIT_VOLUME) 1190 } 1191 1192 if (pev_valid(pEntity)) 1193 { 1194 engfunc(EngFunc_MakeVectors, v_angle) 1195 global_get(glb_v_forward, vecForward) 1196 1197 if (iHitgroup != -1) 1198 set_tr2(tr, TR_iHitgroup, iHitgroup) 1199 1200 ExecuteHam(Ham_TraceAttack, pEntity, id, 0.000001, vecForward, tr, DMG_NEVERGIB | DMG_CLUB/*DMG_BULLET*/) 1201 ExecuteHam(Ham_TakeDamage, pEntity, 1, id, flDamage, DMG_NEVERGIB | DMG_CLUB) 1202 1203 Stock_FakeKnockBack(pEntity, vecSrc, vecEnd, flKnockBack) 1204 1205 if (Stock_IsAlive(pEntity)) 1206 { 1207 free_tr2(tr) 1208 return iHitResult 1209 } 1210 1211 flVol = 0.1 1212 } 1213 } 1214 1215 set_pdata_int(id, m_iWeaponVolume, floatround(flVol * KNIFE_WALLHIT_VOLUME)) 1216 free_tr2(tr) 1217 return iHitResult 1218 } 1219 1220 stock Stock_KnifeAttackAngle(id, bStab, Float:flRange, Float:fAngle, Float:flDamage, Float:flKnockBack, iHitgroup) 1221 { 1222 new Float:vecOrigin[3], Float:vecSrc[3], Float:vecEnd[3], Float:v_angle[3], Float:vecForward[3] 1223 pev(id, pev_origin, vecOrigin) 1224 1225 new iHitResult = RESULT_HIT_NONE 1226 1227 Stock_GetGunPosition(id, vecSrc) 1228 1229 pev(id, pev_v_angle, v_angle) 1230 engfunc(EngFunc_MakeVectors, v_angle) 1231 1232 global_get(glb_v_forward, vecForward) 1233 xs_vec_mul_scalar(vecForward, flRange, vecForward) 1234 1235 xs_vec_add(vecSrc, vecForward, vecEnd) 1236 1237 new tr = create_tr2() 1238 engfunc(EngFunc_TraceLine, vecSrc, vecEnd, 0, id, tr) 1239 1240 new Float:flFraction 1241 get_tr2(tr, TR_flFraction, flFraction) 1242 1243 if (flFraction < 1.0) 1244 iHitResult = RESULT_HIT_WORLD 1245 1246 new Float:vecEndZ = vecEnd[2] 1247 1248 new pEntity = -1 1249 while ((pEntity = engfunc(EngFunc_FindEntityInSphere, pEntity, vecOrigin, flRange)) != 0) 1250 { 1251 if (!pev_valid(pEntity)) 1252 continue 1253 1254 if (id == pEntity) 1255 continue 1256 1257 if (!Stock_IsAlive(pEntity)) 1258 continue 1259 1260 if (!Stock_CheckAngle(id, pEntity, fAngle)) 1261 continue 1262 1263 Stock_GetGunPosition(id, vecSrc) 1264 Stock_GetOrigin(pEntity, vecEnd) 1265 1266 vecEnd[2] = vecSrc[2] + (vecEndZ - vecSrc[2]) * (get_distance_f(vecSrc, vecEnd) / flRange) 1267 1268 xs_vec_sub(vecEnd, vecSrc, vecForward) 1269 xs_vec_normalize(vecForward, vecForward) 1270 xs_vec_mul_scalar(vecForward, flRange, vecForward) 1271 xs_vec_add(vecSrc, vecForward, vecEnd) 1272 1273 engfunc(EngFunc_TraceLine, vecSrc, vecEnd, 0, id, tr) 1274 1275 get_tr2(tr, TR_flFraction, flFraction) 1276 1277 if (flFraction >= 1.0) 1278 engfunc(EngFunc_TraceHull, vecSrc, vecEnd, 0, 3, id, tr) 1279 1280 get_tr2(tr, TR_flFraction, flFraction) 1281 1282 if (flFraction < 1.0) 1283 { 1284 if (Stock_IsPlayer(pEntity) || Stock_IsHostage(pEntity)) 1285 { 1286 iHitResult = RESULT_HIT_PLAYER 1287 1288 if (Stock_CheckBack(id, pEntity) && bStab && iHitgroup == -1) 1289 flDamage *= 3.0 1290 } 1291 1292 if (pev_valid(pEntity) && get_tr2(tr, TR_pHit) == pEntity) 1293 { 1294 engfunc(EngFunc_MakeVectors, v_angle) 1295 global_get(glb_v_forward, vecForward) 1296 1297 if (iHitgroup != -1) 1298 set_tr2(tr, TR_iHitgroup, iHitgroup) 1299 1300 ExecuteHam(Ham_TraceAttack, pEntity, id, 0.000001, vecForward, tr, DMG_NEVERGIB | DMG_CLUB/*DMG_BULLET*/) 1301 ExecuteHam(Ham_TakeDamage, pEntity, 1, id, flDamage, DMG_NEVERGIB | DMG_CLUB) 1302 1303 Stock_FakeKnockBack(pEntity, vecSrc, vecEnd, flKnockBack) 1304 } 1305 } 1306 1307 free_tr2(tr) 1308 1309 } 1310 1311 return iHitResult 1312 } 1313 1314 stock Stock_GetGunPosition(id, Float:vecSrc[3]) 1315 { 1316 new Float:vecViewOfs[3] 1317 pev(id, pev_origin, vecSrc) 1318 pev(id, pev_view_ofs, vecViewOfs) 1319 xs_vec_add(vecSrc, vecViewOfs, vecSrc) 1320 } 1321 1322 stock Stock_IsPlayer(pEntity) 1323 { 1324 return ExecuteHam(Ham_Classify, pEntity) == CLASS_PLAYER; 1325 } 1326 1327 stock Stock_IsHostage(pEntity) 1328 { 1329 return ExecuteHam(Ham_Classify, pEntity) == CLASS_HUMAN_PASSIVE 1330 } 1331 1332 stock Stock_CheckBack(iEnemy,id) 1333 { 1334 new Float:anglea[3], Float:anglev[3] 1335 pev(iEnemy, pev_v_angle, anglea) 1336 pev(id, pev_v_angle, anglev) 1337 new Float:angle = anglea[1] - anglev[1] 1338 if(angle < -180.0) angle += 360.0 1339 if(angle <= 45.0 && angle >= -45.0) return 1 1340 return 0 1341 } 1342 1343 stock Stock_FakeKnockBack(pEntity, Float:vecSrc[3], Float:vecEnd[3], Float:flKnockBack, Float:flRange = 0.0) 1344 { 1345 new flags = pev(pEntity, pev_flags) 1346 1347 new Float:vecDirection[3] 1348 xs_vec_sub(vecEnd, vecSrc, vecDirection) 1349 1350 new Float:flDistance = xs_vec_len(vecDirection) 1351 xs_vec_normalize(vecDirection, vecDirection) 1352 1353 if (!flRange) 1354 { 1355 flRange = 1.0 1356 flDistance = 0.0 1357 } 1358 1359 flKnockBack *= 10.0 1360 1361 new Float:vecVelocity[3], Float:vecOldVelocity[3] 1362 1363 flKnockBack = flKnockBack * (flRange - flDistance) / flRange 1364 if (flags & FL_DUCKING) flKnockBack *= 0.7 1365 1366 xs_vec_mul_scalar(vecDirection, flKnockBack, vecVelocity) 1367 vecVelocity[2] = 0.0 1368 pev(pEntity, pev_velocity, vecOldVelocity) 1369 xs_vec_add(vecVelocity, vecOldVelocity, vecVelocity) 1370 1371 set_pev(pEntity, pev_velocity, vecVelocity) 1372 } 1373 1374 stock Stock_IsAlive(pEntity) 1375 { 1376 if (pEntity < 1) 1377 return 0 1378 1379 return (pev(pEntity, pev_deadflag) == DEAD_NO && pev(pEntity, pev_health) > 0) 1380 } 1381 1382 stock Stock_CheckAngle(iAttacker, iVictim, Float:fAngle) 1383 { 1384 return (Stock_SUIC_CheckAngle(iAttacker, iVictim) > floatcos(fAngle,degrees)) 1385 } 1386 1387 stock Stock_GetOrigin(pEntity, Float:vecOrigin[3]) 1388 { 1389 new Float:maxs[3], Float:mins[3] 1390 if(pev(pEntity, pev_solid) == SOLID_BSP) 1391 { 1392 pev(pEntity, pev_maxs, maxs) 1393 pev(pEntity, pev_mins, mins) 1394 vecOrigin[0] = (maxs[0] - mins[0]) / 2 + mins[0] 1395 vecOrigin[1] = (maxs[1] - mins[1]) / 2 + mins[1] 1396 vecOrigin[2] = (maxs[2] - mins[2]) / 2 + mins[2] 1397 } 1398 else pev(pEntity, pev_origin, vecOrigin) 1399 } 1400 1401 stock Float:Stock_SUIC_CheckAngle(id,iTarget) 1402 { 1403 new Float:vOricross[2],Float:fRad,Float:vId_ori[3],Float:vTar_ori[3],Float:vId_ang[3],Float:fLength,Float:vForward[3] 1404 1405 Stock_Get_Origin(id, vId_ori) 1406 Stock_Get_Origin(iTarget, vTar_ori) 1407 1408 pev(id,pev_angles,vId_ang) 1409 for(new i=0;i<2;i++) 1410 { 1411 vOricross[i] = vTar_ori[i] - vId_ori[i] 1412 } 1413 1414 fLength = floatsqroot(vOricross[0]*vOricross[0] + vOricross[1]*vOricross[1]) 1415 1416 if(fLength<=0.0) 1417 { 1418 vOricross[0]=0.0 1419 vOricross[1]=0.0 1420 } 1421 else 1422 { 1423 vOricross[0]=vOricross[0]*(1.0/fLength) 1424 vOricross[1]=vOricross[1]*(1.0/fLength) 1425 } 1426 1427 engfunc(EngFunc_MakeVectors,vId_ang) 1428 global_get(glb_v_forward,vForward) 1429 1430 fRad = vOricross[0]*vForward[0]+vOricross[1]*vForward[1] 1431 1432 return fRad 1433 } 1434 1435 stock Stock_Get_Origin(id, Float:origin[3]) 1436 { 1437 new Float:maxs[3],Float:mins[3] 1438 if(pev(id,pev_solid)==SOLID_BSP) 1439 { 1440 pev(id,pev_maxs,maxs) 1441 pev(id,pev_mins,mins) 1442 origin[0] = (maxs[0] - mins[0]) / 2 + mins[0] 1443 origin[1] = (maxs[1] - mins[1]) / 2 + mins[1] 1444 origin[2] = (maxs[2] - mins[2]) / 2 + mins[2] 1445 } 1446 else pev(id,pev_origin,origin) 1447 }
标签:des style blog io ar color os sp for
原文地址:http://www.cnblogs.com/crsky/p/4161881.html