AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with pfn_touch (https://forums.alliedmods.net/showthread.php?t=11617)

knekter 03-24-2005 17:23

Problem with pfn_touch
 
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.

Twilight Suzuka 03-24-2005 17:48

pev and set_pev fuck up on strings. Use the engine equivilents.

knekter 03-24-2005 17:52

alright
 
Thanks, I remember seeing something about that before.

XxAvalanchexX 03-24-2005 23:18

For every thing I've used pfn_touch for, ptr and ptd are reversed. ptr would be world and ptd would be player, for example.

knekter 03-25-2005 09:16

really?
 
Really? For every plugin I have made and seen ptr (what is touching) is what hit the ptd (what is touched). Maybee you can do it both ways??? Maybe Ill test it out.

Twilight Suzuka 03-25-2005 10:49

Players always are touched, they never do the touching.

Other objects work as normal.

Use register_think if you only want to get when a player and a bullet touch.

knekter 03-25-2005 17:27

more problems
 
for some reason when I use entity_get_string(ptd, EV_SZ_classname, pTouched, sizeof(pTouched)) it gives me an invalid entity error. So it can't find the classname of ptd. Heres my new code:

Code:
// Includes #include <amxmodx> #include <engine> #include <fun> // Plugin information new const PLUGIN[] = "Bullet Time"; new const VERSION[] = "0.1"; new const AUTHOR[] = "Knekter"; // Bullet velocity #define BULLETSPEED 500 new iMaxPlayers; new spr_zbeam; public event_Damage(id) {     if(!get_cvar_num("amxx_bullettime"))         return 0;     new iWeapon;     new Attacker = get_user_attacker(id, iWeapon);     if(iWeapon != 4 && iWeapon != 29 && Attacker != id) {         new iDamageSave = read_data(1);         new iDamageTake = read_data(2);         set_user_health(id, get_user_health(id) + iDamageTake);         set_user_armor(id, get_user_armor(id) + iDamageSave);     }     return 0; } public task_CheckAttack() {     if(!get_cvar_num("amxx_bullettime"))         return 0;     for(new id = 1; id < iMaxPlayers; id++) {         if(is_user_alive(id)) {             if(get_user_button(id) & IN_ATTACK) {                 new iClip, iAmmo;                 new iWeapon = get_user_weapon(id, iClip, iAmmo);                 if(iWeapon != 4 && iWeapon != 6 && iWeapon != 9 && iWeapon != 25 && iClip > 0) {                     create_bullet(id, iWeapon);                 }             }         }     }     return 0; } public create_bullet(id, iWeapon) {     new BulletEnt = create_entity("info_target");     if(BulletEnt > 0) {         new Float:Angle[3];         new Float:Origin[3];         new Float:AimVelocity[3];         new Float:MinBox[3] = {-1.0, -1.0, -1.0};         new Float:MaxBox[3] = {1.0, 1.0, 1.0};         entity_get_vector(id, EV_VEC_origin, Origin);         Origin[2] += 12.0;         entity_set_string(BulletEnt, EV_SZ_classname, "BulletX");         entity_set_model(BulletEnt, "models/shell.mdl");         switch(iWeapon) {             case 3: entity_set_string(BulletEnt, EV_SZ_targetname, "Scout");             case 13, 24: entity_set_string(BulletEnt, EV_SZ_targetname, "Auto-Sniper");             case 18: entity_set_string(BulletEnt, EV_SZ_targetname, "Awp");             default: entity_set_string(BulletEnt, EV_SZ_targetname, "Normal");         }         entity_get_vector(id, EV_VEC_v_angle, Angle);         entity_set_vector(BulletEnt, EV_VEC_mins, MinBox);         entity_set_vector(BulletEnt, EV_VEC_maxs, MaxBox);         entity_set_origin(BulletEnt, Origin);         entity_set_vector(BulletEnt, EV_VEC_angles, Angle);         entity_set_vector(BulletEnt, EV_VEC_v_angle, Angle);         entity_set_int(BulletEnt, EV_INT_effects, 2);         entity_set_int(BulletEnt, EV_INT_solid, 2);         entity_set_int(BulletEnt, EV_INT_movetype, 5);         entity_set_edict(BulletEnt, EV_ENT_owner, id);         VelocityByAim(id, BULLETSPEED, AimVelocity);         entity_set_vector(BulletEnt, EV_VEC_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(2);           // Line width         write_byte(193);         // Red         write_byte(193);         // Green         write_byte(191);         // Blue         write_byte(120);         // Brightness         message_end();     }     return 0; } public pfn_touch(ptr, ptd) {     if(!get_cvar_num("amxx_bullettime"))         return 0;     if(ptr > 0 && ptd >= 0) {         new pToucher[33];         entity_get_string(ptr, EV_SZ_classname, pToucher, sizeof(pToucher));         new pTouched[33];         if(ptd > 0) {             entity_get_string(ptd, EV_SZ_classname, pTouched, sizeof(pTouched));         }         new Attacker = entity_get_edict(ptr, EV_ENT_owner);         if(equali(pToucher, "BulletX") && (ptd > 0 || equali(pTouched, "player")) && Attacker != ptd) {             if(is_user_connected(ptd)) {                 new TargetName[33];                 entity_get_string(ptr, EV_SZ_targetname, TargetName, sizeof(TargetName));                 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);                 if(iHealth <= 0) {                     new Weapon[32];                     get_weaponname(Attacker, Weapon, 32);                     replace(Weapon, 32, "weapon_", "");                     user_silentkill(ptd);                     make_deathmsg(Attacker, ptd, 0, Weapon);                     set_user_frags(Attacker, get_user_frags(Attacker) + 1);                 } else {                     set_user_health(ptd, iHealth);                 }             }             remove_entity(ptr);         }     }     return 0; } // Core public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     register_cvar("amxx_bullettime", "1", FCVAR_PRINTABLEONLY);     register_event("Damage", "event_Damage", "a");     set_task(0.1, "task_CheckAttack", 256, "", 0, "b");     iMaxPlayers = get_maxplayers() + 1; } public plugin_precache() {     precache_model("models/shell.mdl");     spr_zbeam = precache_model("sprites/zbeam4.spr"); } public plugin_modules() {     require_module("engine");     require_module("fun"); }

Johnny got his gun 03-25-2005 17:30

Check entities. Don't send 0 to the entvar natives.

Twilight Suzuka 03-25-2005 17:35

0 = world. Sending 0 is very bad.

knekter 03-25-2005 17:43

hmm
 
I changed it a bit and I made sure ptd and ptr > 0. I get these messages:

Code:

[AMXX] Native error in "entity_get_string"
[ENGINE] Invalid entity 105



All times are GMT -4. The time now is 09:55.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.