Raised This Month: $ Target: $400
 0% 

Solved HUD Message When Looking at Player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 05-19-2016 , 11:05   HUD Message When Looking at Player
Reply With Quote #1

I made a simple plugin where you can take the C4 from your bot teammate by being in a certain distance and pressing the USE key while aiming at it. I got this idea from CSGO and since I play with bots this is really handy.

It works perfectly but I was thinking of placing a HUD message when you aim at a bot teammate carrying a C4 to inform in other players. Like maybe it would say, "Press the USE key to take the C4 from your Bot teammate" or something like that. Thing is, I don't how to do this. How do hook this 'event ' of aiming at a player?

Here's the whole code. And before you say 'this looks familiar', you're right. Its from joaquimandrade and ConnorMcLeod's Easy Weapon Trade plugin.

PHP Code:
#include <amxmodx>
#include <fakemeta_util>
#include <hamsandwich>

new const Plugin[] = "C4 Bot Swap"
new const Author[] = "joaquimandrade and ConnorMcLeod"
new const Version[] = "1.0"
const MaxSlots 32
new Float:TradeMaxDistance 300.0

public plugin_init()
{
    
register_plugin(Plugin,Version,Author)
    
RegisterHam(Ham_ObjectCaps,"player","Use_Button")
}

getLookingAt(id)
{
    static 
Float:start[3],Float:viewOffset[3],Float:path[3],Float:dest[3]
    
    
pev(id,pev_origin,start);
    
pev(id,pev_view_ofs,viewOffset);
    
xs_vec_add(start,viewOffset,start);
    
    
pev(id,pev_v_angle,path);
    
engfunc(EngFunc_MakeVectors,path);
    
global_get(glb_v_forward,path);
    
    
xs_vec_mul_scalar(path,TradeMaxDistance,dest);
    
xs_vec_add(start,dest,dest);
    
    
engfunc(EngFunc_TraceLine,start,dest,0,id,0);
    
    new 
hit get_tr2(0,TR_pHit)
    
    return 
<= hit <= MaxSlots  hit 0
}

C4_Swap(id)
{
    new 
idLookingAt getLookingAt(id)
            
    if(
idLookingAt && (get_user_team(id) == get_user_team(idLookingAt)) && is_user_bot(idLookingAt))
    {
        
fm_transfer_user_gun(idLookingAtidCSW_C4);
    }
}

public 
Use_Button(id)
{
    if(
is_user_connected(id))
    {
        if(
pev(id,pev_button) & IN_USE)
        {
            
C4_Swap(id);
        }
    }


Last edited by hellmonja; 06-25-2017 at 04:21. Reason: Solved...
hellmonja is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 05-19-2016 , 11:09   Re: [HELP] HUD Message When Looking at Player
Reply With Quote #2

Quote:
Originally Posted by hellmonja View Post
How do hook this 'event ' of aiming at a player?
get_user_aming
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.

Last edited by wickedd; 05-19-2016 at 11:10.
wickedd is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 05-19-2016 , 11:15   Re: [HELP] HUD Message When Looking at Player
Reply With Quote #3

Quote:
Originally Posted by wickedd View Post
get_user_aiming(index, &id, &body, dist = 9999);

index is me and &id is the bot with the C4 I'm aiming at?...
hellmonja is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 05-19-2016 , 11:19   Re: [HELP] HUD Message When Looking at Player
Reply With Quote #4

Yes, it's the other players index.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 05-19-2016 , 11:22   Re: [HELP] HUD Message When Looking at Player
Reply With Quote #5

I see. But how do I trigger this? In the plugin, I had to press 'E' to trigger the swap. With the message I'm practically not doing anything but looking at my buddy...

UPDATE
======

This thread seems pretty relevant to my interests: https://forums.alliedmods.net/showthread.php?t=250165
But I have no idea how to use the 'task'. Are the referring to set_task()?...

Last edited by hellmonja; 05-19-2016 at 11:29. Reason: update
hellmonja is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 05-19-2016 , 11:26   Re: [HELP] HUD Message When Looking at Player
Reply With Quote #6

Ham_ObjectCaps or PreThink
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 05-19-2016 , 11:27   Re: [HELP] HUD Message When Looking at Player
Reply With Quote #7

PHP Code:
public plugin_init()
{
    
//looking at a player
    
register_event"StatusValue""EventStatusValue_PlayerID""b""1=2""2>0" );
    
    
//stoped looking
    
register_event("StatusValue""Event_StatusValueHide""be""1=1""2=0");
}

public 
EventStatusValue_PlayerID(id)
{
    new 
IdLookingAt=read_data(2);
}

public 
Event_StatusValueHide(id)
{


__________________

Last edited by JusTGo; 05-19-2016 at 11:30.
JusTGo is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 05-19-2016 , 11:31   Re: [HELP] HUD Message When Looking at Player
Reply With Quote #8

Quote:
Originally Posted by JusTGo View Post
PHP Code:
public plugin_init()
{
    
//looking at a player
    
register_event"StatusValue""EventStatusValue_PlayerID""b""1=2""2>0" );
    
    
//stoped looking
    
register_event("StatusValue""Event_StatusValueHide""be""1=1""2=0");
}

public 
EventStatusValue_PlayerID(id)
{

}

public 
Event_StatusValueHide(id)
{


Thank you good sir! Will try that one...
hellmonja is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 05-19-2016 , 11:32   Re: [HELP] HUD Message When Looking at Player
Reply With Quote #9

Quote:
Originally Posted by hellmonja View Post
Thank you good sir! Will try that one...
don't forget to add this to get the id for player looking at.
PHP Code:
new IdLookingAt=read_data(2); 
__________________
JusTGo is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 05-19-2016 , 12:03   Re: [HELP] HUD Message When Looking at Player
Reply With Quote #10

Works! Thanks both of you! Although I didn't use "public Event_StatusValueHide(id)" since I figured the HUD message had a timer of its own. Will there be any consequences not using that?...
hellmonja 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 18:37.


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