Team036-CrosshairEntityCallback icon

CrosshairEntityCallback

Modding resource. Provide some useful callbacks on crosshair.

By Team036
Last updated 5 months ago
Total downloads 228
Total rating 0 
Categories Client-side
Dependency string Team036-CrosshairEntityCallback-2.0.0
Dependants 0 other packages depend on this package

README

Deprecated. Use ClPlayerCallback instead.

This mod provides some useful functions in client.

You should not install this until you are told.

Functions

cl_player.gnut


// This allows you to get the entity your crosshair look at.
void function AddCallback_CrosshairCurrentTargetChanged( void functionref( entity player, entity newTarget ) callbackFunc )

Examples

This is a helper to print entity info you look at.

untyped
global function MyHelperInit

struct {
    entity currentCrosshairEntity

    var rui


	vector position = Vector(0.51, 0.52, 0.0) //x axis: 0.0 is max left, 1.0 is max right; y axis: 0.0 is max top, 1.0 is max down; z doesn't do anything
    vector colour = Vector(1, 1, 1) // rgb, range: 0 - 0.0 to 255 - 1.0
    float alpha = 0.6 //maxiumum alpha of the text, range: 0.0 to 1.0
    float size = 28 //size of the text
} file

void function MyHelperInit(){
    thread Monitor()
}


void function Monitor(){
    WaitFrame()


    AddCallback_CrosshairCurrentTargetChanged(GetCrosshairEntity)
	RegisterButtonPressedCallback(KEY_O, PrintEnt)

    AddOnDeathCallback( "player", OnPlayerDeath_StopRui )

	// RUI
	file.rui = RuiCreate( $"ui/cockpit_console_text_top_left.rpak", clGlobal.topoCockpitHudPermanent, RUI_DRAW_COCKPIT, -1 )
	RuiSetInt(file.rui, "maxLines", 1)
	RuiSetInt(file.rui, "lineNum", 1)
	RuiSetFloat2(file.rui, "msgPos", file.position)
	RuiSetFloat3(file.rui, "msgColor", file.colour)
	RuiSetFloat(file.rui, "msgFontSize", file.size)
	RuiSetString(file.rui, "msgText", "")
	RuiSetFloat(file.rui, "msgAlpha", 0.0)
	RuiSetFloat(file.rui, "thicken", 0.0)
	thread DisplayRUI()
}



// You need to check the target manually. It refers to LocalClientPlayer(you) in default if there is nothing in your crosshair.
void function GetCrosshairEntity( entity player, entity target) {
    if (target != file.currentCrosshairEntity) {
        file.currentCrosshairEntity = target
    }
}



void function DisplayRUI() {
	while (true) {
        WaitFrame()


        if(IsLobby() || IsMenuLevel() || IsWatchingReplay())
		{
			RuiSetFloat(file.rui, "msgAlpha", 0.0)
            continue
		}
        entity player = GetLocalClientPlayer()
        if(player == null || IsSpectre(player))
		{
			RuiSetFloat(file.rui, "msgAlpha", 0.0)
            continue
		}

        string s = ""

		// Caution.
        if (file.currentCrosshairEntity != player) {
            if (!IsValid(file.currentCrosshairEntity)) {
                continue
            }
            s += file.currentCrosshairEntity + "\n"
            {
                try {
                    s += file.currentCrosshairEntity.GetSignifierName()+ "\n"
                } catch (exception){
                    print(exception)
                }
            }
            {
                try {
                    s += file.currentCrosshairEntity.GetClassName()+ "\n"
                } catch (exception){
                    print(exception)
                }
            }
        }

        RuiSetString(file.rui, "msgText", s)
        RuiSetFloat(file.rui, "msgAlpha", 1.0)

	}
}

void function OnPlayerDeath_StopRui( entity player )
{
	if ( player != GetLocalViewPlayer() )
		return

	RuiSetFloat(file.rui, "msgAlpha", 0.0)
}