Raised This Month: $32 Target: $400
 8% 

Solved [TF2] Getting Uber Value and Setting Uber Value


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 07-08-2020 , 20:00   [TF2] Getting Uber Value and Setting Uber Value
Reply With Quote #1

Sincerest apologies if I'm posting too much, I promise I've tried to troubleshoot on my own!
So, essentially what this code does is it finds a random dead player and respawns them at a player using the bonesaw taunt, but I only want this to trigger if that person has 100 ubercharge, then I want the uber to be set back to 0. I've tried a few different ways but I'm certainly doing something wrong or else I wouldn't be here! If anyone knows how to properly check and set uber I would very much appreciate it!

Code:
public Action OnSceneSpawned(int iEntity)
{
	int iClient = GetEntPropEnt(iEntity, Prop_Data, "m_hOwner");
	char strSceneFile[128];
	GetEntPropString(iEntity, Prop_Data, "m_iszSceneFile", strSceneFile, sizeof(strSceneFile));
	int playerVampire = GetRandomPlayer();
	float fTeleportOrigin[3];
	float fPlayerOrigin[3];
	if (StrEqual(strSceneFile, "scenes/player/medic/low/taunt03.vcd"))
	{
			if(TF2_GetClientTeam(playerVampire) == TFTeam_Blue)
			{
				TF2_ChangeClientTeam(playerVampire, TFTeam_Red);
			}
			TF2_SetPlayerClass(playerVampire, TFClass_Heavy);
			TF2_RespawnPlayer(playerVampire);
			GetClientAbsOrigin(iClient, fPlayerOrigin);

			fTeleportOrigin[0] = fPlayerOrigin[0];
			fTeleportOrigin[1] = fPlayerOrigin[1];
			fTeleportOrigin[2] = fPlayerOrigin[2];
			
			TeleportEntity(playerVampire, fTeleportOrigin, NULL_VECTOR, NULL_VECTOR);
			PrintToChatAll("%N was chosen!", playerVampire);
	}
}

Last edited by Ravrob; 07-09-2020 at 04:13.
Ravrob is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 07-08-2020 , 21:56   Re: [TF2] Getting Uber Value and Setting Uber Value
Reply With Quote #2

I found these stocks posted by naris in the snippets and tutorials section. They may be useful to you. I haven't tried them.

PHP Code:
stock TF_IsUberCharge(client)
{
    new 
index GetPlayerWeaponSlot(client1);
    if (
index 0)
        return 
GetEntProp(indexProp_Send"m_bChargeRelease"1);
    else
        return 
0;
}

stock TF_GetUberLevel(client)
{
    new 
index GetPlayerWeaponSlot(client1);
    if (
index 0)
        return 
RoundFloat(GetEntPropFloat(indexProp_Send"m_flChargeLevel")*100);
    else
        return 
0;
}

stock TF_SetUberLevel(clientuberlevel)
{
    new 
index GetPlayerWeaponSlot(client1);
    if (
index 0)
        
SetEntPropFloat(indexProp_Send"m_flChargeLevel"uberlevel*0.01);

On an unrelated note I see that your code changes a persons team, changes their class, respawns them, and teleports them. If you are interested in changing teams without respawn/telport consider viewing the excellent post by Benoist3012 entitled "[ANY] How to properly switch team" at this link: https://forums.alliedmods.net/showthread.php?t=314271

Here's an example of changing team without respawn:
PC Gamer is offline
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 07-09-2020 , 00:01   Re: [TF2] Getting Uber Value and Setting Uber Value
Reply With Quote #3

I had actually tried these stocks earlier to no avail, I was making mistakes converting them to new syntax but I figured it out this time. So it compiles now, only nothing is happening now, for some reason the float coming out of TF_GetUberLevel is always 0 regardless of actual uber. I've added a couple lines to my code, float uberAmount and if(uberAmount == 1.0).

PHP Code:
public Action OnSceneSpawned(int iEntity)
{
    
int iClient GetEntPropEnt(iEntityProp_Data"m_hOwner");
    
char strSceneFile[128];
    
GetEntPropString(iEntityProp_Data"m_iszSceneFile"strSceneFilesizeof(strSceneFile));
    
int playerVampire GetRandomPlayer();
    
float fTeleportOrigin[3];
    
float fPlayerOrigin[3];
    if (
StrEqual(strSceneFile"scenes/player/medic/low/taunt03.vcd"))
    {
        
float uberAmount TF_GetUberLevel(iClient);
        if (
uberAmount == 1.0)
        {
            if (
TF2_GetClientTeam(playerVampire) == TFTeam_Blue)
            {
                
TF2_ChangeClientTeam(playerVampireTFTeam_Red);
            }
            
TF2_SetPlayerClass(playerVampireTFClass_Heavy);
            
TF2_RespawnPlayer(playerVampire);
            
GetClientAbsOrigin(iClientfPlayerOrigin);

            
fTeleportOrigin[0] = fPlayerOrigin[0];
            
fTeleportOrigin[1] = fPlayerOrigin[1];
            
fTeleportOrigin[2] = fPlayerOrigin[2];
            
            
TeleportEntity(playerVampirefTeleportOriginNULL_VECTORNULL_VECTOR);
            
PrintToChatAll("%N was chosen!"playerVampire);
        }
    }

and I'm using this stock:
PHP Code:
stock float TF_GetUberLevel(int client)
{
    
int index GetPlayerWeaponSlot(client1);
    if (
index 0)
    {
        return 
RoundFloat(GetEntPropFloat(indexProp_Send"m_flChargeLevel")*100);
    }
    else
    {
        return 
0;
    }

Not really sure what I'm doing wrong if you could point me in the right direction.
Ravrob is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 07-09-2020 , 00:55   Re: [TF2] Getting Uber Value and Setting Uber Value
Reply With Quote #4

I haven't used these stocks but it appears that TF_GetUberLevel is multiplying the return by 100.

A fully charged medigun would have a "m_flChargeLevel" of 1.0. If we use the stock it would multiply that by 100.

The RoundFloat is changing the value to the nearest integer. Your variable should therefore be an integer.

Try changing from this:
PHP Code:
        float uberAmount TF_GetUberLevel(iClient);
        if (
uberAmount == 1.0
To this:
PHP Code:
        int uberAmount TF_GetUberLevel(iClient);
        if (
uberAmount == 100.0
Hopefully that will work.

Last edited by PC Gamer; 07-09-2020 at 01:44.
PC Gamer is offline
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 07-09-2020 , 01:51   Re: [TF2] Getting Uber Value and Setting Uber Value
Reply With Quote #5

Those numbers aren't necessarily the issue, I'm using this to check what the actual float is and for some reason it keeps coming out 0.
PHP Code:
PrintToChatAll("You have %f charge."uberAmount); 
I also checked to see if TF_GetUberLevel is using the else statement and it isn't so I'm really unsure why it's returning 0.

I've also got tag mismatches for both of the return statements and I don't understand what that means.

Last edited by Ravrob; 07-09-2020 at 01:53.
Ravrob is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 07-09-2020 , 02:51   Re: [TF2] Getting Uber Value and Setting Uber Value
Reply With Quote #6

Try this slightly edited version of the code. It compiles in Sourcemod 1.10 without errors or warnings. Not tested.

PHP Code:
#include <tf2_stocks>

public Action OnSceneSpawned(int iEntity)
{
    
int iClient GetEntPropEnt(iEntityProp_Data"m_hOwner");
    
char strSceneFile[128];
    
GetEntPropString(iEntityProp_Data"m_iszSceneFile"strSceneFilesizeof(strSceneFile));
    
int playerVampire GetRandomPlayer();
    
float fTeleportOrigin[3];
    
float fPlayerOrigin[3];
    if (
StrEqual(strSceneFile"scenes/player/medic/low/taunt03.vcd"))
    {
        
int uberAmount TF_GetUberLevel(iClient);
        if (
uberAmount == 100.0)
        {
            if (
TF2_GetClientTeam(playerVampire) == TFTeam_Blue)
            {
                
TF2_ChangeClientTeam(playerVampireTFTeam_Red);
            }
            
TF2_SetPlayerClass(playerVampireTFClass_Heavy);
            
TF2_RespawnPlayer(playerVampire);
            
GetClientAbsOrigin(iClientfPlayerOrigin);

            
fTeleportOrigin[0] = fPlayerOrigin[0];
            
fTeleportOrigin[1] = fPlayerOrigin[1];
            
fTeleportOrigin[2] = fPlayerOrigin[2];
            
            
TeleportEntity(playerVampirefTeleportOriginNULL_VECTORNULL_VECTOR);
            
PrintToChatAll("%N was chosen!"playerVampire);
        }
    }


stock int TF_GetUberLevel(int client)
{
    
int index GetPlayerWeaponSlot(client1);
    if (
index 0)
    {
        return 
RoundFloat(GetEntPropFloat(indexProp_Send"m_flChargeLevel")*100);
    }
    else
    {
        return 
0;
    }


stock int GetRandomPlayer()
{
    
decl iClients[MaxClients+1], iNumClients;
    for(
int i=1i<=MaxClientsi++)
    {
        if(
IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) > 0)
        {
            
iClients[iNumClients++] = i;
        }
    }
    return 
iClients[GetRandomInt(0iNumClients-1)];

PC Gamer is offline
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 07-09-2020 , 04:11   Re: [TF2] Getting Uber Value and Setting Uber Value
Reply With Quote #7

I hadn't seen your edit about changing float to int, and that was the exact problem! You must've made the edit while I was preparing my reply. The code works perfectly now thank you very much!
Ravrob 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 22:47.


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