AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved HUD Message When Looking at Player (https://forums.alliedmods.net/showthread.php?t=282854)

hellmonja 05-19-2016 11:05

HUD Message When Looking at Player
 
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);
        }
    }



wickedd 05-19-2016 11:09

Re: [HELP] HUD Message When Looking at Player
 
Quote:

Originally Posted by hellmonja (Post 2420160)
How do hook this 'event ' of aiming at a player?

get_user_aming

hellmonja 05-19-2016 11:15

Re: [HELP] HUD Message When Looking at Player
 
Quote:

Originally Posted by wickedd (Post 2420162)

get_user_aiming(index, &id, &body, dist = 9999);

index is me and &id is the bot with the C4 I'm aiming at?...

wickedd 05-19-2016 11:19

Re: [HELP] HUD Message When Looking at Player
 
Yes, it's the other players index.

hellmonja 05-19-2016 11:22

Re: [HELP] HUD Message When Looking at Player
 
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()?...

wickedd 05-19-2016 11:26

Re: [HELP] HUD Message When Looking at Player
 
Ham_ObjectCaps or PreThink

JusTGo 05-19-2016 11:27

Re: [HELP] HUD Message When Looking at Player
 
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)
{




hellmonja 05-19-2016 11:31

Re: [HELP] HUD Message When Looking at Player
 
Quote:

Originally Posted by JusTGo (Post 2420170)
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...

JusTGo 05-19-2016 11:32

Re: [HELP] HUD Message When Looking at Player
 
Quote:

Originally Posted by hellmonja (Post 2420171)
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); 


hellmonja 05-19-2016 12:03

Re: [HELP] HUD Message When Looking at Player
 
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?...


All times are GMT -4. The time now is 18:37.

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