Raised This Month: $ Target: $400
 0% 

[TF2] +/- Command Listener conundrums (updated)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
404UserNotFound
BANNED
Join Date: Dec 2011
Old 11-05-2013 , 18:48   [TF2] +/- Command Listener conundrums (updated)
Reply With Quote #1

As some of you may or may not know, I am working on a plugin with a friend that revolves around bringing the scrapped grenades back to TF2. I know, there's already a plugin or two out there that do this already, but I've tried 'em and the one I'm working on is much better.

Within this plugin arises my conundrums. I've added in Command Listeners to detect when a player uses one of the existing grenade commands; "+grenade1", and "+grenade2". As with +attack, the grenade commands also have "-" versions; "-grenade1" and "-grenade2". These commands still exist in TF2 and are obvious leftovers from when TF2 was going to have grenades. Any bold text is stuff I need help with.

What I'm trying to do is as follows: The player has to bind +grenade1 and +grenade2 to be able to use the Frag Grenade (grenade1) and the class-specific specialty grenade (grenade2). When a player holds down the button they've binded +grenade1 or +grenade2 to, I want to make a function that acts just like the Huntsman's "charge-up". The longer you hold the button down will correspond to the distance you throw the grenade. I just don't know how to this.

Here's the first conundrum. I set up the Command Listener properly, using AddCommandListener(Command_Grenade1, "+grenade1");, and changing the Command's title to "public Action:Command_Grenade1(client, const String:command[], args) {". Ingame, upon using the command +grenade1, nothing happened. What did I do wrong?

The second conundrum is how to code in a charging effect on +grenade1. I know it's going to involve mathemetical functions to connect "length of time button was held down" to "throw distance", but I'm not good with mathematical functions.

The third conundrum is making each class play their "spell throwing" animation from the recent Scream Fortress 2013 event so it looks like they're throwing the grenade, instead of the grenade just popping out of their face. Here's my current "throw" code setup:

PHP Code:
public Action:Command_Grenade2(client, const String:command[], args) {
    
// Status effect checks, won't be able to throw a grenade.
    
if (TF2_IsPlayerInCondition(clientTFCond_Cloaked) ||
        
TF2_IsPlayerInCondition(clientTFCond_Dazed) ||
        
TF2_IsPlayerInCondition(clientTFCond_Taunting) ||
        
TF2_IsPlayerInCondition(clientTFCond_Bonked) ||
        
TF2_IsPlayerInCondition(clientTFCond_Disguised) ||
        
TF2_IsPlayerInCondition(clientTFCond_Disguising) ||
        
TF2_IsPlayerInCondition(clientTFCond_CloakFlicker))
    {
        
EmitSoundToClient(clientSOUND_NOTHROWclient___1.0);
        return 
Plugin_Handled;
    }
    
    
// Is client alive? If so, proceed!
    
if (IsClientAlive(client))
    {
        
// Get players class, execute class-specific grenade throwing.
        // This code could probably be shrunken down so much more by eliminating grenade-specific convars like the grenade's throw speed
        
new TFClassType:class = TF2_GetPlayerClass(client);
        switch(class)
        {
            
// No other classes get this Dynamite pack
            // Other classes will soon get their own grenades
            // But for this plugin, only the Demoman can use this.
            // Sorry every other class :(
            
case TFClass_Scout: return Plugin_Handled;
            case 
TFClass_Soldier: return Plugin_Handled;
            case 
TFClass_Pyro: return Plugin_Handled;
            case 
TFClass_Heavy: return Plugin_Handled;
            case 
TFClass_Engineer: return Plugin_Handled;
            case 
TFClass_Medic: return Plugin_Handled;
            case 
TFClass_Sniper: return Plugin_Handled;
            case 
TFClass_Spy: return Plugin_Handled;
            
            
// Demoman - Dynamite Pack
            
case TFClass_DemoMan:
            {
                
// Make sure we don't crash the map with entities
                
if (GetMaxEntities() - GetEntityCount() < 200) {
                    
PrintToChat(client"[SM] Too many entities! Can't throw!");
                    
EmitSoundToClient(clientSOUND_NOTHROWclient___1.0);
                    return 
Plugin_Handled;
                }
                
                
// Get player position and angles
                
decl Float:pos[3];
                
decl Float:ePos[3];
                
decl Float:angs[3];
                
decl Float:vecs[3];            
                
GetClientEyePosition(clientpos);
                
GetClientEyeAngles(clientangs);
                
GetAngleVectors(angsvecsNULL_VECTORNULL_VECTOR);
            
                
// Check to make sure the player isn't in front of a wall
                
new Handle:trace TR_TraceRayFilterEx(posangsMASK_SHOTRayType_InfiniteTraceEntityFilterPlayer);
                if (
TR_DidHit(trace)) {
                    
TR_GetEndPosition(ePostrace);
                    if (
GetVectorDistance(ePosposfalse) < 45.0) {
                        
// Player is too close to a wall
                        
EmitSoundToClient(clientSOUND_NOTHROWclient___1.0);
                        return 
Plugin_Handled;
                    }
                }
                
CloseHandle(trace);            
        
                
// Set throw position to directly in front of player
                
pos[0] += vecs[0] * 32.0;
                
pos[1] += vecs[1] * 32.0;
            
                
// Set up the throw speed
                
ScaleVector(vecsg_fMIRVThrowSpeed);

                new 
entity CreateEntityByName("prop_physics_override");

                if (
IsValidEntity(entity)) {                    
                    
DispatchKeyValue(entity"model"MODEL_MIRV);
                    
DispatchKeyValue(entity"solid""6");
                    
// Set skin for each team
                    
if (GetClientTeam(client) == _:TFTeam_RedDispatchKeyValue(entity"skin""0");
                    else if (
GetClientTeam(client) == _:TFTeam_BlueDispatchKeyValue(entity"skin""1");
                    
DispatchKeyValue(entity"renderfx""0");
                    
DispatchKeyValue(entity"rendercolor""255 255 255");
                    
DispatchKeyValue(entity"renderamt""255");                    
                    
SetEntPropEnt(entityProp_Data"m_hOwnerEntity"client);
                    
DispatchSpawn(entity);
                    
TeleportEntity(entityposNULL_VECTORvecs);
                    
                    
CreateTimer(g_fMIRVMainDetDelayFunction_MIRVExplodeentity);
                }
                else {
                    
EmitSoundToClient(clientSOUND_NOTHROWclient___1.0);
                }
                
                
// Spawn "trail" particle
                
if (GetClientTeam(client) == _:TFTeam_RedFunction_SpawnParticle(GRENADE_TRAIL_RED0.0_entity____);
                else 
Function_SpawnParticle(GRENADE_TRAIL_BLU0.0_entity____);

                
EmitSoundToAll(SOUND_THROWclient___1.0);
            }
        }
    }
    else if (
IsClientHere(client)) {
        
PrintToChat(client"[SM] You must be alive to do that...");
        
EmitSoundToClient(clientSOUND_NOTHROWclient___1.0);
    }
    return 
Plugin_Handled;

I'm obviously going to have to modify the code below the comment "Set throw position to directly in front of player", and try to move the throw position to the player's right side. That's the easy part.

From there, I can't have the grenade being thrown in a straight line because the player would have to look to the left to make up for the grenade flying out from their right side, so I need to also change the degree of the throw so it's at like, a 5 degree angle (again, not good with math) so that the grenade emanates from the right side, but lands where the player was aiming.


Any help with any bolded text stuff would be great. Math has never been my friend

Last edited by 404UserNotFound; 11-05-2013 at 22:52.
404UserNotFound is offline
-Absolute-
Member
Join Date: Mar 2010
Old 11-06-2013 , 18:26   Re: [TF2] +/- Command Listener conundrums (updated)
Reply With Quote #2

1. If they start pressing the key, save the current engine time via GetEngineTime() to a variable specific for each player and then if they stop pressing it get the current Engine Time again and subtract the saved value from it. This way you will know how long the player held down the button. Now you can just ScaleVector with the calculated time on the power you are throwing with.
2. I dont know exactly what you want with "Command Title" or what it is supposed to mean
3. Depends on the effect you want, and it's basically like in 1, save the time they charged for and then make the effect bigger for example
4. no idea about animation
5. http://docs.sourcemod.net/api/index....d=show&id=428& get the players angle and then add 5 degrees on the first of the first vector?
__________________
-Absolute- is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 11-06-2013 , 20:27   Re: [TF2] +/- Command Listener conundrums (updated)
Reply With Quote #3

Quote:
Originally Posted by -Absolute- View Post
1. If they start pressing the key, save the current engine time via GetEngineTime() to a variable specific for each player and then if they stop pressing it get the current Engine Time again and subtract the saved value from it. This way you will know how long the player held down the button. Now you can just ScaleVector with the calculated time on the power you are throwing with.
2. I dont know exactly what you want with "Command Title" or what it is supposed to mean
3. Depends on the effect you want, and it's basically like in 1, save the time they charged for and then make the effect bigger for example
4. no idea about animation
5. http://docs.sourcemod.net/api/index....d=show&id=428& get the players angle and then add 5 degrees on the first of the first vector?
Sounds good. I did edit the post because with my command listener, nothing would happen when I pressed a key binded to +grenade1. When I reverted it back to a RegConsoleCmd command, the command worked to throw the grenade.

Are there any plugins that use engine time and such so I can see how it's set up and get an idea of what I'm doing?
404UserNotFound is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 11-06-2013 , 22:05   Re: [TF2] +/- Command Listener conundrums (updated)
Reply With Quote #4

Every time you fail a throw you leak a handle, close it.
You can probably just use the global trace if you want.

Usually for cooldowns, just get engine time + the cooldown = clienttime, then compare in the future, if clienttime < getenginetime. This will always evaluate true if they are off cooldown.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 11-07-2013 , 01:10   Re: [TF2] +/- Command Listener conundrums (updated)
Reply With Quote #5

Quote:
Originally Posted by friagram View Post
Every time you fail a throw you leak a handle, close it.
You can probably just use the global trace if you want.

Usually for cooldowns, just get engine time + the cooldown = clienttime, then compare in the future, if clienttime < getenginetime. This will always evaluate true if they are off cooldown.
While I do release plugins here and there, I have to re-state that I have no clue what any of that stuff is.

I'm not at *that* particular skill level yet. I've no clue what a global trace is, I don't know how to properly implement client time/cooldowns/getenginetime/scalevector. Same with SQL related things, which is why I avoid trying to code up anything that would require an SQL database.

If I had an example snippet of something set up in reference to what I'm trying to code up, using getenginetime, scalevector, throwspeed from my throw command and proper scaling of throw speed based on time button has been held down, with a preset maximum "charge" time, that would be incredibly useful.

Last edited by 404UserNotFound; 11-07-2013 at 01:10.
404UserNotFound is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 11-07-2013 , 07:33   Re: [TF2] +/- Command Listener conundrums (updated)
Reply With Quote #6

The only way you will learn something new is if you are required to code something you do not understand. If you actively try to avoid everything you do not know or understand, you are never going to advance in skill level.

With the cool-downs, he is saying that when the player first starts throwing the grenades, use the native GetEngineTime(), however I would use GetTime(), and then save that value into a client specific variable, and you add on how long you want your cool-down to be. Then every time a player tries to throw a grenade, you do the check: if clienttime (the client specific variable) < GetEngineTime(). If that condition is false, you display the message, "you have used a grenade too recently" or what-have-you.
Marcus_Brown001 is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 11-07-2013 , 10:47   Re: [TF2] +/- Command Listener conundrums (updated)
Reply With Quote #7

Engine time is much more accurate. Sometimes, if you need to chech if something happened a few frames ago, or 1/10th a second a go say, to prevent loopback in ontakedamage or something, it is better to use the extra precision.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 11-07-2013 , 13:36   Re: [TF2] +/- Command Listener conundrums (updated)
Reply With Quote #8

Quote:
Originally Posted by Marcus_Brown001 View Post
The only way you will learn something new is if you are required to code something you do not understand. If you actively try to avoid everything you do not know or understand, you are never going to advance in skill level.

With the cool-downs, he is saying that when the player first starts throwing the grenades, use the native GetEngineTime(), however I would use GetTime(), and then save that value into a client specific variable, and you add on how long you want your cool-down to be. Then every time a player tries to throw a grenade, you do the check: if clienttime (the client specific variable) < GetEngineTime(). If that condition is false, you display the message, "you have used a grenade too recently" or what-have-you.
Good to know.
404UserNotFound is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 11-08-2013 , 20:02   Re: [TF2] +/- Command Listener conundrums (updated)
Reply With Quote #9

Quote:
Originally Posted by friagram View Post
Engine time is much more accurate. Sometimes, if you need to chech if something happened a few frames ago, or 1/10th a second a go say, to prevent loopback in ontakedamage or something, it is better to use the extra precision.

Hmm, learn something new every day Thanks for the information!
Marcus_Brown001 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:32.


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