Raised This Month: $ Target: $400
 0% 

Grenade Name return


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 01:23   Grenade Name return
Reply With Quote #1

How can I return the grenade's name when it touch a player?

I have a method but I want to know if have any other better than mine.
Thats the code that I'm using:

PHP Code:
new const szGrenades[] =
{
    
"smokegrenade",
    
"flashbang"
}

new 
g_gGrenadeType 
PHP Code:
register_touch("player","grenade","fwd_touch")
register_clcmd("say /grenadeUsed""showLastGrenade"
PHP Code:
public showLastGrenade(id)
{
     
console_print(id,"%s",GetGrenadeType(g_gGrenadeType)) 
PHP Code:
public fwd_touch(touchedtoucher
{
    new 
id pev(toucherpev_owner)
    if(
get_user_team(id) != get_user_team(touched))
    {
        new 
GrenadeType = (get_pdata_int(toucher114) & 3)
        
        if(
GrenadeType != CSW_HEGRENADE)
        {
            if(
fGetDistance(touchertouched) <= 5.0)
            {
                
g_gGrenadeType GrenadeType
            
}
        }
    }

PHP Code:
Float:fGetDistance(const touchedPlayer, const toucherPlayer)
{
    new 
Float:fOrigin[2][3]
    
pev(touchedPlayerpev_originfOrigin[0])
    
pev(toucherPlayerpev_originfOrigin[1])
    
    new 
Float:floatDistance fOrigin[1][2] - fOrigin[0][2]
    
    return 
floatDistance

PHP Code:
GetGrenadeType(GrenadeType)
{
    switch(
GrenadeType)
    {
        case 
CSW_SMOKEGRENADEg_gGrenadeType szGrenades[0]
        case 
CSW_FLASHBANGg_gGrenadeType szGrenades[1]
    }
    return 
g_gGrenadeType

__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 02-03-2017 at 01:24.
EFFx is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-03-2017 , 06:42   Re: Grenade Name return
Reply With Quote #2

This?
PHP Code:
stock fm_cs_get_grenade_type(index) {
    
// you can comment/remove this
    // if you are sure that the entity
    // with the given index are valid
    
if (!pev_valid(index))
        return 
0
    
    
// you can comment/remove this
    // if you are sure that the entity
    // with the given index are "grenade"
    
new classname[9]
    
pev(indexpev_classnameclassname8)
    if (!
equal(classname"grenade"))
        return 
0
    
    
if (get_pdata_int(index96) & (1<<8))
        return 
CSW_C4
    
    
new bits get_pdata_int(index114)
    if (
bits & (1<<0))
        return 
CSW_HEGRENADE
    
else if (bits & (1<<1))
        return 
CSW_SMOKEGRENADE
    
else if (!bits)
        return 
CSW_FLASHBANG
    
    
return 0

__________________
edon1337 is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 16:55   Re: Grenade Name return
Reply With Quote #3

No, as the fwd_touch says, the CSW_ prefix is already taken, i want return a string for show on console_print().
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2017 , 17:58   Re: Grenade Name return
Reply With Quote #4

Are you aware that your fGetDistance() function only gets the distance of the Z axis (up and down distance)?
__________________
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 18:02   Re: Grenade Name return
Reply With Quote #5

No, I just copied it from my runboost. But it works.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2017 , 18:03   Re: Grenade Name return
Reply With Quote #6

Well, that's what it does. Use get_distance_f() to get actual distance.

0=X
1=Y
2=Z
__________________
Bugsy is offline
Old 02-03-2017, 18:34
EFFx
This message has been deleted by EFFx. Reason: nvm
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 18:36   Re: Grenade Name return
Reply With Quote #7

Yea, thats what I have:

PHP Code:
if(fDistance(touchertouched) <= 20.0
PHP Code:
Float:fDistance(touchertouched)
{
    new 
Float:fOrigin[2][3]
    
pev(toucherpev_originfOrigin[0])
    
pev(touchedpev_originfOrigin[1])
    
    return 
get_distance_f(fOrigin[0], fOrigin[1])

What about the string return?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 02-03-2017 at 20:00.
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2017 , 21:30   Re: Grenade Name return
Reply With Quote #8

'Yes that's what I have'. No what you have is this, unless you are saying you have fixed it?
PHP Code:
Float:fGetDistance(const touchedPlayer, const toucherPlayer)
{
    new 
Float:fOrigin[2][3]
    
pev(touchedPlayerpev_originfOrigin[0])
    
pev(toucherPlayerpev_originfOrigin[1])
    
    new 
Float:floatDistance fOrigin[1][2] - fOrigin[0][2]
    
    return 
floatDistance

To explain better: This only measures the distance going up and down. So if you were standing on the same level ground as me but I was across the map, your distance function would return 0.

Aside from your method being wrong, you also do not take into consideration the orientation of one player to the other. So if I'm standing on your head and you subtract my Z from yours, the distance will be negative (hypothetically) and it would never satisfy your distance condition. This can be fixed by getting the absolute value, abs(), of the Z1-Z2 value.

I've never returned a string from a function because I remember reading somewhere that it does not work properly. This may only be in some scenarios like returning from a native or something. With that said, I always stick to not returning a string. You can easily avoid returning a string by just returning the index to the weapon name in the array.
__________________

Last edited by Bugsy; 02-03-2017 at 21:33.
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-03-2017 , 21:34   Re: Grenade Name return
Reply With Quote #9

I meant that I have fixed.

And I said "return a string" meaning "how can I return the smokegrenade/flashbang on the console_print()".
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2017 , 21:36   Re: Grenade Name return
Reply With Quote #10

It looks messy, I'll need to see more of your plugin to fix this
PHP Code:
enum
{
    
Smoke,
    
Flash
}

GetGrenadeType(GrenadeType)
{
    switch(
GrenadeType)
    {
        case 
CSW_SMOKEGRENADEg_gGrenadeType Smoke
        
case CSW_FLASHBANGg_gGrenadeType Flash
    
}
    return 
g_gGrenadeType
}  

public 
showLastGrenade(id)
{
     
console_print(id,"%s"szGrenadesg_gGrenadeType ] )  

__________________

Last edited by Bugsy; 02-03-2017 at 21:37.
Bugsy 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 21:02.


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