Raised This Month: $51 Target: $400
 12% 

[Help] Spawning Rocket (TF2)


Post New Thread Reply   
 
Thread Tools Display Modes
Inhib
Member
Join Date: Oct 2014
Old 03-16-2015 , 03:42   Re: [Help] Spawning Rocket (TF2)
Reply With Quote #31

PHP Code:
SetEntDataFloat(rocket_entityFindSendPropOffs("CTFProjectile_Rocket""m_iDeflected") + 4100.0true); 
Still no damage
Inhib is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 03-16-2015 , 08:45   Re: [Help] Spawning Rocket (TF2)
Reply With Quote #32

How are you testing it?
__________________
Chdata is offline
Inhib
Member
Join Date: Oct 2014
Old 03-17-2015 , 02:52   Re: [Help] Spawning Rocket (TF2)
Reply With Quote #33

Quote:
Originally Posted by Chdata View Post
How are you testing it?
Full Code:
PHP Code:
#include <sourcemod>
#include <clients>
#include <console>
#include <events>
#include <tf2>
#include <tf2_stocks>
#include <string>
#include <entity_prop_stocks>
#include <sdkhooks>
#include <sdktools_trace>
#include <sdktools_engine>
#include <handles>

public Plugin:myinfo =
{
    
name "New Plugin",
    
author "Your Lord and Saviour",
    
description "Test",
    
version "1.0",
    
url "http://www.sourcemod.net/"
};

public 
OnPluginStart()
{
    for(new 
i<= MAXPLAYERSi++)
    {
        if(
IsValidEntity(i))
        {
            
SDKHook(iSDKHook_OnTakeDamageontakedamage);
            
PrecacheModel("models/props_farm/wooden_barrel.mdl");
            
PrecacheModel("models/weapons/w_models/w_rocket.mdl")
        }
    }
}

public 
Action:ontakedamage(client, &attacker, &inflictor, &Float:damage, &damagetype)
{
    
PrintToServer("DamageTaken");
    if(
damagetype DMG_FALL)
    {
        
PrintToServer("IsFallDamage");
        new 
TFClassType:playerclass TF2_GetPlayerClass(client);
        if(
playerclass==TFClass_Pyro)
        {
            
damage=damage*3;
            
PrintToServer("IsPyro");
            return 
Plugin_Changed;
        }
    }
    return 
Plugin_Continue;
}



public 
Action:TF2_CalcIsAttackCritical(clientweaponString:weaponname[], &bool:result)
{
    
PrintToServer("Tick");
    new 
Float:vectorfloat[3];
    new 
String:vecstring[10];
    new 
String:vecstring2[10];
    new 
TFClassType:playerclass TF2_GetPlayerClass(client);
    
GetClientEyeAngles(clientFloat:vectorfloat);
    
Format(vecstringsizeof(vecstring), "%.5f"vectorfloat[0]);
    
Format(vecstring2sizeof(vecstring2), "%.0f"vectorfloat[1]);
    
PrintToServer(vecstring);
    
PrintToServer(vecstring2);
    new 
Float:lateraljetpackvelocity=64.0;
    new 
Float:verticaljetpackvelocity=64.0;
    if(
playerclass==TFClass_Heavy)
    {
        if(
GetEntityFlags(client) & FL_ONGROUND)
        {
        
lateraljetpackvelocity=4000.0;
        
verticaljetpackvelocity=0.0;
        
PrintToServer("Heavy Knockback");
        }
        else
        {
        
lateraljetpackvelocity=0.0;
        
verticaljetpackvelocity=0.0;
        
PrintToServer("Heavy In Air")
        }
    }
    new 
Float:LateralEyeAngle=DegToRad(vectorfloat[1]);
    new 
Float:VerticalEyeAngle=DegToRad(vectorfloat[0]);
    new 
Float:velocityvector[3];
    new 
Float:zvelocity verticaljetpackvelocity*Sine(VerticalEyeAngle);
    new 
Float:xvelocity lateraljetpackvelocity*Cosine(VerticalEyeAngle)*Sine(LateralEyeAngle);
    new 
Float:yvelocity lateraljetpackvelocity*Cosine(VerticalEyeAngle)*Cosine(LateralEyeAngle);
    
GetEntPropVector(clientProp_Data"m_vecVelocity"velocityvector);
    
velocityvector[2] += zvelocity;
    
velocityvector[1] -= xvelocity;
    
velocityvector[0] -= yvelocity;
    
TeleportEntity(clientNULL_VECTORNULL_VECTORvelocityvector); 

    if(
playerclass==TFClass_DemoMan)
    {
        
PrintToServer("Demoman Shot");
        new 
String:demomanweapon[30];
        new 
String:grenadelauncher[30]="tf_weapon_grenadelauncher";
        
GetClientWeapon(clientdemomanweapon30);
        
PrintToServer(demomanweapon);
        
PrintToServer(grenadelauncher);
        if(
StrEqual(demomanweapongrenadelaunchertrue))
        {
            
PrintToServer("Pipe Shot");            
        }
    }

    if(
playerclass==TFClass_Engineer)
    {
        
PrintToServer("Engy Shot");
        new 
ActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
        new 
String:ActiveWeaponClassname[100];
        
GetEdictClassname(ActiveWeaponActiveWeaponClassnamesizeof(ActiveWeaponClassname));
        if(
StrEqual(ActiveWeaponClassname"tf_weapon_pistol"true))
        {
            
PrintToServer("Pistol Fired");
            if(
vectorfloat[0]<=-88)
            {
                
PrintToServer("DummyEngy");
                new 
barrel=CreateEntityByName("prop_physics_multiplayer");
                new 
Float:barrelpos[3];
                
GetClientAbsOrigin(clientbarrelpos);
                
barrelpos[2]+=128;
                
SetEntityModel(barrel"models/props_farm/wooden_barrel.mdl");
                
DispatchSpawn(barrel);
                
TeleportEntity(barrelbarrelposNULL_VECTORNULL_VECTOR);
            }
        }
    }

    if(
playerclass==TFClass_Soldier)
    {
        new 
rocketfired=FindEntityByClassname(-1"tf_projectile_rocket");
        new 
Deflected=GetEntProp(rocketfiredProp_Send"m_iDeflected"40);
        new 
Critical=GetEntProp(rocketfiredProp_Send"m_bCritical"10);
        new 
String:DeflectedString[4];
        new 
String:CriticalString[4];
        
Format(DeflectedStringsizeof(DeflectedString), "%i"Deflected);
        
Format(CriticalStringsizeof(CriticalString), "%i"Critical);
        
PrintToServer("Deflected:");
        
PrintToServer(DeflectedString);
        
PrintToServer("Crit:");
        
PrintToServer(CriticalString);
    }
    if(
playerclass==TFClass_Sniper)
    {
        
PrintToServer("Sniper Shot");
        new 
ActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
        new 
String:ActiveWeaponClassname[100];
        
GetEdictClassname(ActiveWeaponActiveWeaponClassnamesizeof(ActiveWeaponClassname));
        if(
StrEqual(ActiveWeaponClassname"tf_weapon_sniperrifle"true))
        {
            
PrintToServer("Rifle Fired");
            new 
Float:endpoint[3];
            
TraceRayEnd(clientendpoint);
            new 
Float:zrocketpos 64*Sine(VerticalEyeAngle);
            new 
Float:xrocketpos 64*Cosine(VerticalEyeAngle)*Sine(LateralEyeAngle);
            new 
Float:yrocketpos 64*Cosine(VerticalEyeAngle)*Cosine(LateralEyeAngle);
            new 
Float:rocketvel[3];
            
rocketvel[0]=yrocketpos;
            
rocketvel[1]=xrocketpos;
            
rocketvel[2]=-zrocketpos
            new 
String:rocketvel0[10];
            new 
String:rocketvel1[10];
            new 
String:rocketvel2[10];
            new 
Float:rocketpos[3];
            
rocketpos[0]=endpoint[0]-yrocketpos;
            
rocketpos[1]=endpoint[1]-xrocketpos;
            
rocketpos[2]=endpoint[2]+zrocketpos;
            
Format(rocketvel0sizeof(rocketvel0), "%.5f"rocketvel[0]);
            
Format(rocketvel1sizeof(rocketvel1), "%.5f"rocketvel[1]);
            
Format(rocketvel2sizeof(rocketvel2), "%.5f"rocketvel[2]);
            
PrintToServer(rocketvel0);
            
PrintToServer(rocketvel1);
            
PrintToServer(rocketvel2);
            new 
rocket_entity CreateEntityByName("tf_projectile_rocket");
            new 
team=GetClientTeam(client);
            
SetEntProp(rocket_entityProp_Send"m_hOwnerEntity"client210);
            
SetEntProp(rocket_entityProp_Send"m_iTeamNum"teamtrue); 
            
SetEntDataFloat(rocket_entityFindSendPropOffs("CTFProjectile_Rocket""m_iDeflected") + 4100.0true);
            
SetEntProp(rocket_entityProp_Send"m_bCritical"110);
            
DispatchSpawn(rocket_entity);
            
TeleportEntity(rocket_entityrocketposvectorfloatrocketvel);
        }
    }
    return 
Plugin_Continue;
}

public 
bool:rayhitplayer(entity,mask,any:data
{  
    if(
entity==data)
    {
        return 
false;  
    }  
    else
    {  
        return 
true;  
    }  
}

public 
TraceRayEnd(clientFloat:endpoint[3])
{
    new 
Float:origin[3];
    new 
Float:angles[3];
    
GetClientEyePosition(clientorigin);
    
GetClientEyeAngles(clientangles);
    
TR_TraceRayFilter(originanglesMASK_SHOTRayType_Infiniterayhitplayerclient);
    if(
TR_DidHit(INVALID_HANDLE))
    {
        
TR_GetEndPosition(endpointINVALID_HANDLE);
    }
    return;

I fire my rifle as sniper in the server, rocket spawns, doesnt hurt me or any bots i spawn in

Last edited by Inhib; 03-17-2015 at 02:52.
Inhib is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-17-2015 , 08:29   Re: [Help] Spawning Rocket (TF2)
Reply With Quote #34

Your problem is that you're corrupting the owner entity because you're using the wrong function and have sprinkled some random parameters on the SetEntProp calls.

Code:
SetEntPropEnt(rocket_entity, Prop_Send, "m_hOwnerEntity", client);
SetEntProp(rocket_entity, Prop_Send, "m_iTeamNum", team); 
SetEntDataFloat(rocket_entity, FindSendPropOffs("CTFProjectile_Rocket", "m_iDeflected") + 4, 100.0, true);
SetEntProp(rocket_entity, Prop_Send, "m_bCritical", true);
Also, I believe the owner of the rocket should be the weapon rather than the client, and I notice you're getting the active weapon rather than using the weapon parameter from the forward... why?
__________________

Last edited by asherkin; 03-17-2015 at 08:29.
asherkin is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 03-17-2015 , 09:36   Re: [Help] Spawning Rocket (TF2)
Reply With Quote #35

I think m_hOwnerEntity doesn't really matter. Rockets get their stats from the weapon via m_hLauncher / m_hOriginalLauncher.

Fakedit: Yep, I always set m_hOwnerEntity to the client, no problem.

Realedit: Yep, and that thing about the garble you put in those SetEntProps asherkin quoted.

PHP Code:
/*
    iWeapon is one of the player's weapons to read attributes from, such as 99 ; 1.5 for extra explosive radius
*/
stock FireTeamRocket(Float:vPos[3], Float:vAng[3], iOwner 0iTeam 0Float:flSpeed 1100.0Float:flDamage 90.0bool:bCrit falseiWeapon = -1)
{
    new 
iRocket CreateEntityByName("tf_projectile_rocket");
    if (
IsValidEntity(iRocket))
    {
        
decl Float:vVel[3]; // Determine velocity based on given speed/angle
        
GetAngleVectors(vAngvVelNULL_VECTORNULL_VECTOR);
        
ScaleVector(vVelflSpeed);
        
        
SetEntProp(iRocketProp_Send"m_bCritical"bCrit);

        
SetRocketDamage(iRocketflDamage);

        
SetEntProp(iRocketProp_Send"m_nSkin"max(0iTeam 2)); // 0 = RED 1 = BLU
        
SetEntProp(iRocketProp_Send"m_iTeamNum"iTeam1);
        
SetVariantInt(iTeam);
        
AcceptEntityInput(iRocket"TeamNum");
        
SetVariantInt(iTeam);
        
AcceptEntityInput(iRocket"SetTeam");

        if (
iOwner != -1)
        {
            
SetEntPropEnt(iRocketProp_Send"m_hOwnerEntity"iOwner);
        }
        
        
// I found this offset while trying to fix the sudden-explode issue with these rockets. it's another instance
        // of the owner entity, so why the hell not copy this over...probably useful for some things.
        // new iTestOffset = FindSendPropOffs("CTFProjectile_Rocket", "m_bCritical") - 4;
        // SetEntDataEnt2(iRocket, iTestOffset, iOwner, true); // GetEntDataEnt2(baseRocket, iTestOffset)

        
TeleportEntity(iRocketvPosvAngvVel);
        
DispatchSpawn(iRocket);
        
        
//SetEntProp(iRocket, Prop_Send, "m_nSolidType", );       // GetEntProp(baseRocket, Prop_Send, "m_nSolidType")
        //SetEntProp(iRocket, Prop_Send, "m_usSolidFlags", );     // GetEntProp(baseRocket, Prop_Send, "m_usSolidFlags")
        //SetEntProp(iRocket, Prop_Send, "m_CollisionGroup", );   // GetEntProp(baseRocket, Prop_Send, "m_CollisionGroup")
        // if (iOwner != -1)
        // {
        //     SetEntDataEnt2(iRocket, iTestOffset, iOwner, true);      // GetEntDataEnt2(baseRocket, testOffset)
        // }
        
        
if (iWeapon != -1)
        {
            
SetEntPropEnt(iRocketProp_Send"m_hOriginalLauncher"iWeapon); // GetEntPropEnt(baseRocket, Prop_Send, "m_hOriginalLauncher")
            
SetEntPropEnt(iRocketProp_Send"m_hLauncher"iWeapon); // GetEntPropEnt(baseRocket, Prop_Send, "m_hLauncher")
        
}
        

        
//if (false) SetEntProp(iRocket, Prop_Send, "m_nModelIndex", ); // GetEntProp(baseRocket, Prop_Send, "m_nModelIndex")
        
        // trail override
        //if (strlen(MS_TrailEffectOverride[bossClientIdx]) > 3)
        //{
        //  new particle = AttachParticle(iRocket, MS_TrailEffectOverride[bossClientIdx]);
        //  if (IsValidEntity(particle))
        //      CreateTimer(MS_ROCKET_LIFE, RemoveEntity, EntIndexToEntRef(particle));
        //}
        
        
return iRocket;
    }
    return -
1;
}

static 
s_iRocketDmgOffset = -1;

stock SetRocketDamage(iRocketFloat:flDamage)
{
    if (
s_iRocketDmgOffset == -1)
    {
        
s_iRocketDmgOffset FindSendPropOffs("CTFProjectile_Rocket""m_iDeflected") + 4// Credit to voogru
    
}
    
SetEntDataFloat(iRockets_iRocketDmgOffsetflDamagetrue);
}

stock Float:GetRocketDamage(iRocket)
{
    if (
s_iRocketDmgOffset == -1)
    {
        
s_iRocketDmgOffset FindSendPropOffs("CTFProjectile_Rocket""m_iDeflected") + 4// Credit to voogru
    
}
    return 
GetEntDataFloat(iRockets_iRocketDmgOffset);

__________________

Last edited by Chdata; 03-17-2015 at 09:38.
Chdata is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-17-2015 , 09:47   Re: [Help] Spawning Rocket (TF2)
Reply With Quote #36

Quote:
Originally Posted by Chdata View Post
I think m_hOwnerEntity doesn't really matter.
It does, a null / invalid owner causes issues with damage in TF2. It is possible they've fixed it since they broke it in 2010 to default to world rather than null when creating a new entity.

EDIT: And this is exactly what your code does, defaults to setting the owner to world (thanks to the mismatch between the default argument and the check in the function).

I mention it being the weapon rather than client as that is what the game does, and plugins with OnTakeDamage hooks expect.
__________________

Last edited by asherkin; 03-17-2015 at 19:35.
asherkin is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 03-17-2015 , 19:00   Re: [Help] Spawning Rocket (TF2)
Reply With Quote #37

Whatever that mercurial link is requires a username/pass.

Also the function was set up that way intentionally to default the rocket to 'something' and prevent people from trying to set it to something invalid. Since I don't know what m_hOwnerEntity would default to if it's not set at all, I figured that'd be the safest.
__________________
Chdata 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 16:06.


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