Raised This Month: $ Target: $400
 0% 

Get total of active tripmines placed by player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Silencer123
Veteran Member
Join Date: Jul 2006
Old 10-31-2008 , 16:01   Get total of active tripmines placed by player
Reply With Quote #1

I want this code to set every players armor to the amount of by him placed tripmines currently in game.
Code:
public fakemeta_prethink(id) {     new mines=-1,cur_start=33;     while(cur_start!=0) {         mines++;         cur_start=find_ent_by_owner(cur_start,"monster_tripmine",id,0);     }     set_user_armor(id,mines); }
However, the used find_ent_by_owner function only returns something other than zero for a tripmine the moment I place it (like for 0.2 seconds after it) and the moment it explodes. So while placing them my armor jumps from 0 to 1 and back and forth, and when a bunch of mines explodes it may go up to higher values for a moment, then go down again. Why does that happen? How do I fix this?

Thanks in advance!
__________________
EAT YOUR VEGGIES
Silencer123 is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-31-2008 , 22:35   Re: Get total of active tripmines placed by player
Reply With Quote #2

You should look up the ent's classname after it has been placed. That way, you can use the code you've posted.

However, I'd suggest that you use a different method to count them. I'm not sure what your situation is like, but I'd recommend hooking when a mine is placed and when a mine explodes or is deleted, and doing the addition and subtraction there.
stupok is offline
Silencer123
Veteran Member
Join Date: Jul 2006
Old 11-01-2008 , 06:48   Re: Get total of active tripmines placed by player
Reply With Quote #3

Thanks for the reply. Yes, I should really not do it like that in a prethink, but this plugin was not meant to be for anything more than a 2 or 3 player WON2 LAN skirmish.

Yet, I looked up the tripmines info after it is placed and activated and what not using "impulse 106", and it clearly indicates that the classname still is "monster_tripmine". It appears that the owner information is temporarily moved elsewhere after placing and before detonation.

So... how'd I check when a mine is placed, blown up or unplaced because of bad spot (e.g. a mine is placed on a moving entity (func_train, player, monster_*, etc.)) and get its entity id and owner id?
__________________
EAT YOUR VEGGIES
Silencer123 is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 11-01-2008 , 12:29   Re: Get total of active tripmines placed by player
Reply With Quote #4

I don't know a whole lot about your situation. If it's a plugin that's spawning the mines, it should be no problem to hook the placement and booms.

I'm guessing that it's not a plugin, though. So, maybe try hooking SetModel to get when the mine is placed. I'm not sure about the best way to hook when the mine explodes.

You could hook ham_think on the mine and see when it goes boom.

Here's some code from Avalanche's frostnades plugin:

Code:
// grenade is ticking away
public ham_grenade_think(ent)
{
	// not a frostnade
	if(!pev(ent,pev_bInDuck)) return FMRES_IGNORED;
	
	new Float:dmgtime;
	pev(ent,pev_dmgtime,dmgtime);
	if(dmgtime > get_gametime()) return FMRES_IGNORED;
	
	// and boom goes the dynamite
	frostnade_explode(ent);

	return FMRES_SUPERCEDE;
}
I have another idea. Since the classname doesn't change, you can still use your method to find all the mines that belong to a client. The one thing that does change is the owner of the mine.

You can do a couple things to fix this problem. First, you can spill all of the ent's pev's and pdata into the server console or a log file and see if any of the numbers match your id. The other thing you can do is hook SetModel and set the ent's pev_iuser4 (or another unused pev) to your player's id.
stupok is offline
Silencer123
Veteran Member
Join Date: Jul 2006
Old 11-01-2008 , 14:01   Re: Get total of active tripmines placed by player
Reply With Quote #5

Quote:
Invalid event (name "SetModel")
Code:
register_event("SetModel","tmr_maybemine","");
So much about SetModel. With what function do I hook it up?
__________________
EAT YOUR VEGGIES
Silencer123 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-01-2008 , 14:03   Re: Get total of active tripmines placed by player
Reply With Quote #6

register_forward(FM_SetModel, ...);
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Silencer123
Veteran Member
Join Date: Jul 2006
Old 11-01-2008 , 17:58   Re: Get total of active tripmines placed by player
Reply With Quote #7

Damn it, sexy. Got it to work!
Code:
new g_mines[33]; new g_i_am_owned[MAXENTS]; public plugin_init() {     register_plugin("Tripmine Race",VERSION,"Silencer");     register_forward(FM_SetModel,"tmr_maybemine",0); } public tmr_maybemine(ent,const model[]) {     new class[32];     pev(ent,pev_classname,class,31);     new owner=pev(ent,pev_owner);     if(owner>0&&owner<33&&equal(class,"monster_tripmine")) {         if(!g_i_am_owned[ent]) {             g_mines[owner]++;         }         g_i_am_owned[ent]=owner;         set_pev(ent,pev_iuser4,owner); //To verify entity later on     } } public tmr_prethink(id) {     set_user_armor(id,g_mines[id]); } public server_frame() {     for(new i=0;i<MAXENTS;i++) {         if(g_i_am_owned[i]) {             if(!pev_valid(i)) {                 g_mines[g_i_am_owned[i]]--;                 g_i_am_owned[i]=0;             }             else {                 if(pev(i,pev_iuser4)!=g_i_am_owned[i]) {                     g_mines[g_i_am_owned[i]]--;                     g_i_am_owned[i]=0;                 }             }         }     } }
A little tricky is what I made with pev_iuser4. The problem is, that because I do not get the server_frame method called when a mine explodes, but 60 times per second or so, it is possible that between the explosion and the server_frame method the entity slot is being used by another entity already. Not rare, since the explosion creates sparks. So I set pev_iuser4 to the owners id and later on if the owned tripmine appears to still exist, I can figure out whether it still is its original owners tripmine or not, by checking if pev_iuser4 isn't equal to the owners id anymore.
__________________
EAT YOUR VEGGIES

Last edited by Silencer123; 11-01-2008 at 18:05.
Silencer123 is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 11-01-2008 , 19:19   Re: Get total of active tripmines placed by player
Reply With Quote #8

I'm glad it works, but that code makes me cry.

Try to find what noise the mine makes when it explodes, and then hook FM_EmitSound to catch when the thing explodes.
stupok is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 11-02-2008 , 04:24   Re: Get total of active tripmines placed by player
Reply With Quote #9

Or hook think for that ent, and when you set it make it think for a custom interval, like a task.
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Silencer123
Veteran Member
Join Date: Jul 2006
Old 11-02-2008 , 11:14   Re: Get total of active tripmines placed by player
Reply With Quote #10

Yeah the server_frame part is true CPU-Rape, but it works fine.
I pondered if I should use FM_Think, because I am not sure how
often it will be called. Only on placement and explosion/removal,
or from time to time, too? If you manage to damage it with less
than 1 damage, it will survive and think, too, won't it?

EDIT: Okay got it working the (much) better way. ^^
Code:
// This Plugin is designed for fast networks like 100 Mb/s LAN only #include <amxmodx> #include <amxmisc> #include <fun> #include <fakemeta> #include <engine> const MAXENTS=4096; new VERSION[]="0.4"; new bool:g_game_running; new g_mines[33]; new g_all_mines; new g_i_am_owned[MAXENTS]; public plugin_precache() {     register_forward(FM_SetModel,"tmr_maybemine",0);     register_forward(FM_Think,"tmr_minethink",0); } public plugin_init() {     register_plugin("Tripmine Race",VERSION,"Silencer");     register_forward(FM_PlayerPreThink,"tmr_prethink",0);     register_cvar("mp_minerace","0");     set_task(0.2,"tmr_checkstatus",1,"",0,"b"); } public tmr_minethink(ent) {     new class[32];     pev(ent,pev_classname,class,31);     //new owner=pev(ent,pev_owner); //The one who tripped     new Float:health=float(pev(ent,pev_health));     new iuser4=pev(ent,pev_iuser4);     if(equal(class,"monster_tripmine")&&health<=0.0&&iuser4<33) {         if(!iuser4) {             g_all_mines--;         }         else {             if(g_i_am_owned[ent]==iuser4) {                 g_mines[iuser4]--;                 g_all_mines--;             }         }         set_pev(ent,pev_iuser4,33);         g_i_am_owned[ent]=0;     } } public tmr_maybemine(ent,const model[]) {     new class[32];     pev(ent,pev_classname,class,31);     new owner=pev(ent,pev_owner);     if(equal(class,"monster_tripmine")) {         if(!owner) {             g_all_mines++;         }         else {             if(!g_i_am_owned[ent]) {                 g_mines[owner]++;                 g_all_mines++;             }         }         g_i_am_owned[ent]=owner;         set_pev(ent,pev_iuser4,owner);     } } public tmr_prethink(id) {     if(g_game_running&&is_user_connected(id)) {         if(is_user_alive(id)) {             new clip,ammo;             get_user_ammo(id,13,clip,ammo);             if(ammo<5) {                 give_item(id,"weapon_tripmine");             }         }         set_hudmessage(128,172,132,0.03,0.8,0,1.0,255.0,0.0,0.0,4);         show_hudmessage(id,"Your Mines: %i^nAll Mines: %i",g_mines[id],g_all_mines);     }     } public tmr_checkstatus() {     if(get_cvar_num("mp_minerace")) {         g_game_running=true;     }     else {         set_hudmessage(128,172,132,0.03,0.8,0,1.0,0.0,0.0,0.0,4);         show_hudmessage(0,"");         g_game_running=false;     } }
I also know why getting the owner failed. The problem is, that in order to display that the player killed/damaged himself with the tripmine, the tripmines owner is changed to 0 for a moment. A very gay workaround. If there are multiple players getting killed by the same mine, it will probably work through all the players, adjusting the mines pev_owner to either 0 or to the original owner, depending on who is going to be logged as dead and who triggered the tripmine. Weirdtastic!
__________________
EAT YOUR VEGGIES

Last edited by Silencer123; 11-02-2008 at 14:55.
Silencer123 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:27.


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