Raised This Month: $ Target: $400
 0% 

Get weapon entity index when dropped


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 04-17-2014 , 18:20   Get weapon entity index when dropped
Reply With Quote #1

So i'd like to get the index of a certain weapon, so that i can do stuff with this entity.
Example:

Let's say i gave this player who has the index in a function an m4, and he decides to drop it. When he drops it, set glow to that weapon if it's an m4, and the owner of the m4 is correct. Don't set glow on other players m4 when they drop theirs. Only if it's the player that i previously chose in my function.

No need to teach me how to set glow on entities, i know that part. I just need to know how to detect weapon dropping, and checking who it belongs to, and storing the entity index of the weapon inside a variable so that i can do a bunch of stuff to it.
__________________
PM me for private work.



Last edited by Buckshot; 04-17-2014 at 18:33.
Buckshot is offline
Send a message via Skype™ to Buckshot
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 04-17-2014 , 18:34   Re: Get weapon entity index when dropped
Reply With Quote #2

From my last request

Code:
register_forward( FM_SetModel, "SetModel", 1);

public SetModel( ent,const model[ ] )
{	
	if( !pev_valid( ent )) 
		return FMRES_IGNORED
	
	new id;
	id = pev( ent, pev_owner );
	
	if(is_user_alive(id))
	{
		if (id == g_iLastRequest[ LR_PRISONER ] || id == g_iLastRequest[ LR_GUARD ] ) 
		{
			static weapon
			weapon = get_user_weapon(id);
			if (weapon == CSW_DEAGLE)
			{	
				//Get Team color
				new r, b;
				switch(get_user_team(id)) {
					case 1: r = 255;
						default: b = 255;
				}
				
				//Glow teamcolor
				set_rendering(ent,kRenderFxGlowShell,r,0,b,kRenderNormal,16);
		}
	}
	
	return FMRES_SUPERCEDE
}
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 04-17-2014 , 18:38   Re: Get weapon entity index when dropped
Reply With Quote #3

Quote:
Originally Posted by ironskillz1 View Post
From my last request

Code:
register_forward( FM_SetModel, "SetModel", 1);

public SetModel( ent,const model[ ] )
{	
	if( !pev_valid( ent )) 
		return FMRES_IGNORED
	
	new id;
	id = pev( ent, pev_owner );
	
	if(is_user_alive(id))
	{
		if (id == g_iLastRequest[ LR_PRISONER ] || id == g_iLastRequest[ LR_GUARD ] ) 
		{
			static weapon
			weapon = get_user_weapon(id);
			if (weapon == CSW_DEAGLE)
			{	
				//Get Team color
				new r, b;
				switch(get_user_team(id)) {
					case 1: r = 255;
						default: b = 255;
				}
				
				//Glow teamcolor
				set_rendering(ent,kRenderFxGlowShell,r,0,b,kRenderNormal,16);
		}
	}
	
	return FMRES_SUPERCEDE
}
Thanks mate.
__________________
PM me for private work.


Buckshot is offline
Send a message via Skype™ to Buckshot
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 04-17-2014 , 22:24   Re: Get weapon entity index when dropped
Reply With Quote #4

Uhm.. This is making bugs that i've never seen before.. When i tried it, my screen like turned upside down.. or sideways :s.. I could walk around like that too.. Also i did not see my weapon. I'm suspecting there is something wrong with pev_health. When this happens, my health is set to 1, though i set health to 100 in the function. I noticed the value of "100" for pev_health that was wrong, and i changed it to a float value "100.0" from default "100", now i'm not even getting to the player menu.. This is really confusing. But.. the glow itself worked while my screen was twisted though


Here's a screenshot of it.
http://steamcommunity.com/sharedfile.../?id=250330790

Getting no error logs when debugging, or any errors compiling.


Plugin is not close to done.. i just started making it an hour ago, and all this happened when i ran it for the first time just to check that it was working as it should.. but here it is
PHP Code:
#include < amxmodx >
#include < fakemeta_util >
#include < cstrike >
#include < colorchat >

#define OFFSET_PRIMARYWEAPON    116 

#pragma semicolon 1

new const g_szPREFIX[ ] = "[AMXX]";

new 
pcvar_LastRequest;

new 
bool:Challenger32 ], bool:Challenged32 ];
new 
bool:g_bGame_S4Sbool:g_bGame_Guntossbool:g_bGame_Box;

public 
plugin_init() {
    
register_plugin"Last Request""1.0""BuckShot" );
    
    
pcvar_LastRequest register_cvar("jb_lastrequest""1");
    
    
register_clcmd"say /lr""Checks" );
    
    
register_forwardFM_SetModel"Fwd_SetModel");
}

public 
Checksid )
{
    if( 
get_pcvar_numpcvar_LastRequest ) != )
    {
        
set_pcvar_numpcvar_LastRequest);
        return 
PLUGIN_HANDLED;
    }
    
    if( 
cs_get_user_teamid ) != CS_TEAM_T )
    {
        
ColorChatidRED"%s^x01 You must be a prisoner in order to get a last request"g_szPREFIX );
        return 
PLUGIN_HANDLED;
    }
    
    new 
iPlayers32 ], iPlayeriPnum;
    new 
iCTcountiTcount;
    
    
get_playersiPlayersiPnum"a" );
    
    for( new 
0iPnumi++ )
    {
        
iPlayer iPlayers];
        switch( 
cs_get_user_teamiPlayer ) )
        {
            case 
CS_TEAM_CTiCTcount++;
            case 
CS_TEAM_TiTcount++;
        }
    }
    
    if( 
iTcount )
    {
        
ColorChatidRED"%s^x01 There are too many prisoners alive"g_szPREFIX );
        return 
PLUGIN_HANDLED;
    }
    
    if( 
iCTcount == )
    {
        
ColorChatidRED"%s^x01 There are no guards alive"g_szPREFIX );
        return 
PLUGIN_HANDLED;
    }
    
LastRequest_Menuid );
    return 
PLUGIN_HANDLED;
}

public 
LastRequest_Menuid )
{
    new 
iMenu menu_create"\yChoose your Last Request""LastRequest_Handler" );
    
    
menu_additemiMenu"\wShot for Shot""");
    
menu_additemiMenu"\wGun Toss""");
    
menu_additemiMenu"\wBoxing Match""");
    
    
menu_setpropiMenuMPROP_EXITMEXIT_ALL );
    
    
menu_displayidiMenu);
}

public 
LastRequest_HandleridiMenuiItem )
{
    if( 
iItem == MENU_EXIT )
    {
        
menu_destroyiMenu );
        return 
PLUGIN_HANDLED;
    }
    
    switch( 
iItem )
    {
        case 
0g_bGame_S4S true;
        case 
1g_bGame_Guntoss true;
        case 
2g_bGame_Box true;
    }
    
PlayerMenuid );
    return 
PLUGIN_HANDLED;
    
}

public 
PlayerMenuid )
{
    new 
iMenu menu_create"\yChoose your opponent:""Games_Handler" );
    
    new 
iPlayers32 ], iTempidiPnum;
    
    new 
szName32 ], szUserid32 ];
    
    
get_playersiPlayersiPnum"ae""CT" );
    
    for( new 
0iPnumi++ )
    {
        
iTempid iPlayers];
        
        
get_user_nameiTempidszNamecharsmaxszName ) );
        
        
formatexszUseridcharsmaxszUserid ), "%d"get_user_useridiTempid ) );
        
        
menu_additemiMenuszNameszUserid);
    }
    
    
menu_displayidiMenu);
}

public 
Games_HandleridiMenuiItem )
{
    if ( 
iItem == MENU_EXIT )
    {
        
menu_destroyiMenu );
        return 
PLUGIN_HANDLED;
    }
    
    new 
szData], szName64 ];
    new 
item_accessitem_callback;
    
    
menu_item_getinfoiMenuiItemitem_accessszDatacharsmaxszData ), szNamecharsmaxszName ), item_callback );
    
    new 
szUserid str_to_numszData );
    
    new 
iTempid find_player"k"szUserid );
    
    if( 
iTempid && is_user_aliveiTempid ) )
    {
        
Challengerid ] = true;
        
ChallengediTempid ] = true;
        
        new 
szName32 ], szName232 ];
        
get_user_nameidszNamecharsmaxszName ) );
        
get_user_nameiTempidszName2charsmaxszName2 ) );
        
        if( 
g_bGame_S4S )
        {
            
StripWeaponsid );
            
StripWeaponsiTempid );
            
            
set_pevidpev_health100.0 );
            
set_peviTempidpev_health100.0 );
            
            
fm_give_itemid"weapon_deagle" );
            
fm_give_itemiTempid"weapon_deagle" );
            
            
cs_set_user_bpammoidCSW_DEAGLE35 );
            
cs_set_user_bpammoiTempidCSW_DEAGLE35 );
            
            
ColorChatidRED"%s^x04 %s^x01 wants a Shot for Shot with^x04 %s"g_szPREFIXszNameszName2 );
        }
        
        else if( 
g_bGame_Guntoss )
        {
            
StripWeaponsid );
            
StripWeaponsiTempid );
            
            
set_pevidpev_health100.0 );
            
set_peviTempidpev_health100.0 );
            
            new 
Deagle_id fm_give_itemid"weapon_deagle" );
            new 
Deagle_tempid fm_give_itemiTempid"weapon_deagle" );
            
            
cs_set_weapon_ammoDeagle_id);
            
cs_set_weapon_ammoDeagle_tempid);
            
            
cs_set_user_bpammoidCSW_DEAGLE);
            
cs_set_user_bpammoiTempidCSW_DEAGLE);
            
            
ColorChatidRED"%s^x04 %s^x01 wants a Gun Toss with^x04 %s"g_szPREFIXszNameszName2 );
            
            
        }
        
        else if( 
g_bGame_Box )
        {
            
// Box code 
        
}
    }
    return 
PLUGIN_HANDLED;
}
/* All forwards, stocks and outside functions etc down here */

/* Deagle glow when in gun toss */
public Fwd_SetModeliEntity,const szModel[ ] )
{
    if( !
g_bGame_Guntoss )
        return 
FMRES_IGNORED;
    
    if( !
pev_validiEntity ) ) 
        return 
FMRES_IGNORED;
    
    new 
id;
    
id peviEntitypev_owner );
    
    if( 
Challengerid ] || Challengedid ] && is_user_aliveid ))
    {
        static 
iWeapon;
        
iWeapon get_user_weaponid );
        
        if( 
iWeapon == CSW_DEAGLE )
        {    
            new 
redblue;
            
            switch( 
cs_get_user_teamid ) )
            {
                
                case 
CS_TEAM_CTred 255;
                case 
CS_TEAM_Tblue 255;
            }
            
fm_set_renderingiEntitykRenderFxGlowShellred0bluekRenderNormal16 );
        }
    }
    
    return 
FMRES_SUPERCEDE;
}

/* Strip weps, give knife.. So i dont gotta repeat this process in every single lr menu option. */
stock StripWeaponsindex )
{
    
fm_strip_user_weaponsindex );
    
set_pdata_intindexOFFSET_PRIMARYWEAPON);
    
fm_give_itemindex"weapon_knife" );

Anyone knows what's creating this phenomenon that was twisting the whole game for me?
__________________
PM me for private work.



Last edited by Buckshot; 04-17-2014 at 23:30.
Buckshot is offline
Send a message via Skype™ to Buckshot
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 04-17-2014 , 23:46   Re: Get weapon entity index when dropped
Reply With Quote #5

There must be something that your not showing. It's usually related to a player's health being forcibly set to 0. Therefore if your inputting an integer where it's supposed to be a float, you'll end up with the wrong value.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 04-17-2014 , 23:51   Re: Get weapon entity index when dropped
Reply With Quote #6

Quote:
Originally Posted by hornet View Post
There must be something that your not showing. It's usually related to a player's health being forcibly set to 0. Therefore if your inputting an integer where it's supposed to be a float, you'll end up with the wrong value.
That is all the code i have actually. There is nothing i did not post in my code. I copy-pasted it all.. This is really strange. Because now i can't get it to work at all, and i didn't change anything other than pev_health's value to make it happen. :S I promise you, there is no more code. The health is correctly set, i'm currently not getting a twisted screen when i'm trying it, but the problem this time is that i can't even get to the player menu. I only see the Last_Request menu. When i select an option, nothing happens. Gawd. I'm horrible at solving problems.


Edit: It's fixed. I was running the server in console mode, and i switched to gui, and it worked :s But i have no idea what caused this and probably will never know.
__________________
PM me for private work.



Last edited by Buckshot; 04-18-2014 at 00:11.
Buckshot is offline
Send a message via Skype™ to Buckshot
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 04-18-2014 , 00:19   Re: Get weapon entity index when dropped
Reply With Quote #7

Last question. How would i remove the glow? I know how i could do it inside the function, but i'm going to remove it on round end. my entity cannot be reached from there. It's only reached inside the function itself. I never work with entities.. So i feel pretty horrible at this. It's like the first day of coding when working with entities. But i gotta learn it sometime
__________________
PM me for private work.



Last edited by Buckshot; 04-18-2014 at 00:26.
Buckshot is offline
Send a message via Skype™ to Buckshot
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 04-18-2014 , 06:31   Re: Get weapon entity index when dropped
Reply With Quote #8

Loop through all entites and do set_rendering(ent) on them
I can show code later when Im on my computer


Edit:
Code:
new Entity = -1; 
while ( ( Entity = find_ent_by_class( Entity, "armoury_entity" ) ) ) 
{ 
	set_rendering(Entity);
}
I dont think you need to remove glow becuse next round the weapon will disappear
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.

Last edited by ironskillz1; 04-18-2014 at 07:51.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 04-18-2014 , 09:39   Re: Get weapon entity index when dropped
Reply With Quote #9

Quote:
Originally Posted by ironskillz1 View Post
Loop through all entites and do set_rendering(ent) on them
I can show code later when Im on my computer


Edit:
Code:
new Entity = -1; 
while ( ( Entity = find_ent_by_class( Entity, "armoury_entity" ) ) ) 
{ 
	set_rendering(Entity);
}
I dont think you need to remove glow becuse next round the weapon will disappear
Yeah i could've done that. That feels abit unecessary though.. I feel there should be a better way than having to loop through all entities in the server, and remove glow on them all, even if they don't have glow.. just to be able to remove it on one. No i don't just need to remove it next rond. That was just an example. I'm gonna remove it when the game is over.
__________________
PM me for private work.



Last edited by Buckshot; 04-18-2014 at 10:05.
Buckshot is offline
Send a message via Skype™ to Buckshot
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 17:53.


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