Im not sure why this isn't working, but when pfn_touch occurs and I find my class name, remove_entity won't work. Im not sure whether or not pfn_touch is just not working, or from what I heard FakeMeta has problem with classnames and targetnames. Heres the code:
Code:
/* = AMXX Script ============================================== *
* AMXX Bullet Time
* Copyright (C), 2005 Knekter
*
* Purpose:
* The purpose of this plugin is to simulate the bullet
* time effect from the movie 'The Matrix'.
*
* Cvars:
* amxx_bullettime <1 = on|0 = off>
*
* Disclaimer:
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or
* (at your option) any later version.
* ============================================================ */
#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <fun>
/* ============================================================ */
new const PLUGIN[] = "Bullet Time"
new const VERSION[] = "0.1"
new const AUTHOR[] = "Knekter"
/* ============================================================ */
#define BULLETSPEED 500 // Bullet Time Speed
#define TASK_WAIT 755 // Task wait value
new bool:wait[33] // (bool) Is the user waiting?
new prevWeapon[33] // (int ) Previous weapon
new iMaxPlayers // (int ) Maxplayers
new spr_zbeam // (spr ) Zbeam sprite
/* = Plugin Initialized here ================================== */
public plugin_init() {
// Register the plugin and create the CVAR
register_plugin(PLUGIN, VERSION, AUTHOR)
register_cvar("amxx_bullettime", "1", FCVAR_PRINTABLEONLY)
// Register the Current Weapon event
register_event("CurWeapon", "event_CurWeapon", "1=1", "3>0")
// Set a task the loops every 0.1 seconds
set_task(0.1, "task_CheckAttack", 256, "", 0, "b")
// Get the maxplayers on the server
iMaxPlayers = get_maxplayers() + 1
}
public plugin_precache() {
precache_model("models/pshell.mdl")
spr_zbeam = precache_model("sprites/zbeam4.spr")
}
public plugin_modules() {
require_module("engine")
require_module("FakeMeta")
require_module("fun")
}
public client_connect(id) {
if(get_cvar_num("amxx_bullettime")) {
wait[id] = false
prevWeapon[id] = 0
}
}
/* = End of Plugin Initialization ============================== */
/* = Current Weapon Event ====================================== *
* This just checks to see if the user has changed his weapon
* or not so it can run the wait task.
* ============================================================= */
public event_CurWeapon(id) {
// Get users weapon ID
new iWeapon = read_data(2)
// Check if it has been set
if(prevWeapon[id] == 0)
prevWeapon[id] = iWeapon
if(get_cvar_num("amxx_bullettime") == 1 && wait[id] == false) {
// If previous weapon is not same as current weapon...
if(prevWeapon[id] != iWeapon) {
wait[id] = true
new param[1]
param[0] = id
set_task(0.6, "task_WaitOff", id + TASK_WAIT, param, 1)
}
}
prevWeapon[id] = iWeapon
}
/* = Check Attack Task ========================================= *
* This task checks every 0.1 seconds if the user is in attack
* ============================================================= */
public task_CheckAttack() {
if(!get_cvar_num("amxx_bullettime"))
return PLUGIN_CONTINUE
// Loop through all the players
for(new id = 1; id < iMaxPlayers; id++) {
// Check if they are alive
if(is_user_alive(id)) {
// Check if they are attacking
if(get_user_button(id) & IN_ATTACK) {
// Get weapon, clip, and ammo
new iClip, iAmmo
new iWeapon = get_user_weapon(id, iClip, iAmmo)
// Check if it is a valid bullet time weapon
if(wait[id] == false && iWeapon != 4 && iWeapon != 6 && iWeapon != 9 && iWeapon != 25 && iClip > 0) {
create_bullet(id, iWeapon)
}
}
}
}
return PLUGIN_CONTINUE
}
/* = Create Bullet Function ==================================== *
* This function creates the bullet time bullets
* ============================================================= */
public create_bullet(id, iWeapon) {
// Create the entity
new BulletEnt = create_entity("info_target")
// Check if it was created
if(BulletEnt > 0) {
new iOrigin[3]
new Float:Angle[3]
new Float:fOrigin[3]
new Float:AimVelocity[3]
// Create the min and max box's
new Float:MinBox[3] = {-1.0, -1.0, -1.0}
new Float:MaxBox[3] = {1.0, 1.0, 1.0}
// Get users origin
get_user_origin(id, iOrigin, 1)
IVecFVec(iOrigin, fOrigin)
// Set the classname and model
set_pev(BulletEnt, pev_classname, "BulletX")
entity_set_model(BulletEnt, "models/pshell.mdl")
// Set targetname depending on weapon
switch(iWeapon) {
case 3: set_pev(BulletEnt, pev_targetname, "Scout")
case 13, 24: set_pev(BulletEnt, pev_targetname, "Auto-Sniper")
case 18: set_pev(BulletEnt, pev_targetname, "Awp")
default: set_pev(BulletEnt, pev_targetname, "Normal")
}
// Get users angle
pev(id, pev_v_angle, Angle, sizeof(Angle))
// Set Mins and Maxs
set_pev(BulletEnt, pev_mins, MinBox)
set_pev(BulletEnt, pev_maxs, MaxBox)
// Set bullet origin and angle
set_pev(BulletEnt, pev_origin, fOrigin)
set_pev(BulletEnt, pev_angles, Angle)
set_pev(BulletEnt, pev_v_angle, Angle)
// Set bullet effects, solid, movetype, and owner
set_pev(BulletEnt, pev_effects, 2)
set_pev(BulletEnt, pev_solid, 1)
set_pev(BulletEnt, pev_movetype, 5)
set_pev(BulletEnt, pev_owner, id)
// Retrieve and set bullet velocity
VelocityByAim(id, BULLETSPEED, AimVelocity)
set_pev(BulletEnt, pev_velocity, AimVelocity)
// TE_BEAMFOLLOW
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(22)
write_short(BulletEnt) // Entity to follow
write_short(spr_zbeam) // Sprite index
write_byte(10) // Life
write_byte(3) // Line width
write_byte(193) // Red
write_byte(193) // Green
write_byte(191) // Blue
write_byte(120) // Brightness
message_end()
}
return PLUGIN_CONTINUE
}
/* = Entity Touch Function ===================================== *
* This function checks if two entitys touch each other
* ============================================================= */
public pfn_touch(ptr, ptd) {
if(!get_cvar_num("amxx_bullettime"))
return PLUGIN_CONTINUE
// Check if ptr is valid
if(ptr > 0) {
new pToucher[33]
new pTouched[33]
// Retrieve the classnames for the pToucher and pTouched
pev(ptr, pev_classname, pToucher, sizeof(pToucher))
pev(ptd, pev_classname, pTouched, sizeof(pTouched))
// If pToucher is a bullet time bullet and the pTouched is a player...
if(equali(pToucher, "BulletX")) {
if(equali(pTouched, "player")) {
// Get the targetname
new TargetName[33]
pev(ptr, pev_targetname, TargetName, sizeof(TargetName))
// Set damage based on weapon type
new iDamage
if(equali(TargetName, "Scout") || equali(TargetName, "Auto-Sniper"))
iDamage = random_num(45,75)
else if(equali(TargetName, "Awp"))
iDamage = random_num(85,100)
else if(equali(TargetName, "Normal"))
iDamage = random_num(15, 25)
new iHealth = (get_user_health(ptd) - iDamage)
// Check if player will die
if(iHealth <= 0) {
new Attacker = pev(ptr, pev_owner)
new Weapon[32]
get_weaponname(Attacker, Weapon, 32)
replace(Weapon, 32, "weapon_", "")
user_silentkill(ptd)
make_deathmsg(Attacker, ptd, 0, Weapon)
} else {
set_user_health(ptd, iHealth)
}
}
remove_entity(ptr)
}
}
return PLUGIN_CONTINUE
}
public task_WaitOff(param[1]) {
wait[param[0]] = false
}
Thanks for your help.