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

[TF2] Pets


Post New Thread Reply   
 
Thread Tools Display Modes
arthurdead
Senior Member
Join Date: Jul 2013
Old 01-09-2014 , 21:11   Re: [TF2] Pets
Reply With Quote #11

Quote:
Originally Posted by abrandnewday View Post
Code:
L 01/09/2014 - 21:06:40: [SM] Native "GetClientAbsOrigin" reported: Client 1 is not in game
L 01/09/2014 - 21:06:40: [SM] Displaying call stack trace for plugin "pets.smx":
L 01/09/2014 - 21:06:40: [SM]   [0]  Line 146, C:\Users\User\Desktop\Work\Coding\addons\sourcemod\scripting\pets.sp::SpawnPet()
L 01/09/2014 - 21:06:40: [SM]   [1]  Line 139, C:\Users\User\Desktop\Work\Coding\addons\sourcemod\scripting\pets.sp::Command_EasyPet()
just add IsClientInGame
arthurdead is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-09-2014 , 21:20   Re: [TF2] Pets
Reply With Quote #12

Quote:
Originally Posted by arthurdead View Post
just add IsClientInGame
I did, but the pet keeps getting spawned to the same player no matter what "playerfilter" I use in the command.

I'm looking at the code right now and I'm unsure how to fix it.

Maybe you should get rid of Easy Commands and just code up normal commands?

EDIT: Server crashing bug: If you have multiple players with the same string in their name, and you try to give one of them a pet, it doesn't print a "multiple clients with same name" message, and crashes the server.

I'd definitely switch from Easy Commands.

Last edited by 404UserNotFound; 01-09-2014 at 21:22.
404UserNotFound is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 01-09-2014 , 21:33   Re: [TF2] Pets
Reply With Quote #13

Quote:
Originally Posted by abrandnewday View Post
I did, but the pet keeps getting spawned to the same player no matter what "playerfilter" I use in the command.

I'm looking at the code right now and I'm unsure how to fix it.

Maybe you should get rid of Easy Commands and just code up normal commands?

EDIT: Server crashing bug: If you have multiple players with the same string in their name, and you try to give one of them a pet, it doesn't print a "multiple clients with same name" message, and crashes the server.

I'd definitely switch from Easy Commands.
Code:
public Action:Command_KillPet(client, args)
{
	new String:target[PLATFORM_MAX_PATH];
	GetCmdArg(1, target, PLATFORM_MAX_PATH);
	decl String:target_name[MAX_TARGET_LENGTH];
	decl target_list[MAXPLAYERS], target_count;
	new bool:tn_is_ml;
	if ((target_count = ProcessTargetString(
	target,
	client,
	target_list,
	MAXPLAYERS,
	COMMAND_FILTER_ALIVE,
	target_name,
	sizeof(target_name),
	tn_is_ml)) <= 0)
	{
		ReplyToTargetError(client, target_count);
		return Plugin_Handled;
	}
	for (new i = 0; i < target_count; i++)
	{
		KillPet(target_list[i]);
	}
	return Plugin_Handled;
}

public Action:Command_SpawnPet(client, args)
{
	new String:target[PLATFORM_MAX_PATH];
	new String:petindex[PLATFORM_MAX_PATH];
	GetCmdArg(1, target, PLATFORM_MAX_PATH);
	GetCmdArg(2, petindex, PLATFORM_MAX_PATH);
	decl String:target_name[MAX_TARGET_LENGTH];
	decl target_list[MAXPLAYERS], target_count;
	new bool:tn_is_ml;
	if ((target_count = ProcessTargetString(
	target,
	client,
	target_list,
	MAXPLAYERS,
	COMMAND_FILTER_ALIVE,
	target_name,
	sizeof(target_name),
	tn_is_ml)) <= 0)
	{
		ReplyToTargetError(client, target_count);
		return Plugin_Handled;
	}
	for (new i = 0; i < target_count; i++)
	{
		KillPet(target_list[i]);
		petType[target_list[i]] = StringToInt(petindex, 10);
		SpawnPet(target_list[i]);
	}
	return Plugin_Handled;
}
i didn't tested yet
arthurdead is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-09-2014 , 23:43   Re: [TF2] Pets
Reply With Quote #14

Quote:
Originally Posted by arthurdead View Post
Code:
public Action:Command_KillPet(client, args)
{
    new String:target[PLATFORM_MAX_PATH];
    GetCmdArg(1, target, PLATFORM_MAX_PATH);
    decl String:target_name[MAX_TARGET_LENGTH];
    decl target_list[MAXPLAYERS], target_count;
    new bool:tn_is_ml;
    if ((target_count = ProcessTargetString(
    target,
    client,
    target_list,
    MAXPLAYERS,
    COMMAND_FILTER_ALIVE,
    target_name,
    sizeof(target_name),
    tn_is_ml)) <= 0)
    {
        ReplyToTargetError(client, target_count);
        return Plugin_Handled;
    }
    for (new i = 0; i < target_count; i++)
    {
        KillPet(target_list[i]);
    }
    return Plugin_Handled;
}

public Action:Command_SpawnPet(client, args)
{
    new String:target[PLATFORM_MAX_PATH];
    new String:petindex[PLATFORM_MAX_PATH];
    GetCmdArg(1, target, PLATFORM_MAX_PATH);
    GetCmdArg(2, petindex, PLATFORM_MAX_PATH);
    decl String:target_name[MAX_TARGET_LENGTH];
    decl target_list[MAXPLAYERS], target_count;
    new bool:tn_is_ml;
    if ((target_count = ProcessTargetString(
    target,
    client,
    target_list,
    MAXPLAYERS,
    COMMAND_FILTER_ALIVE,
    target_name,
    sizeof(target_name),
    tn_is_ml)) <= 0)
    {
        ReplyToTargetError(client, target_count);
        return Plugin_Handled;
    }
    for (new i = 0; i < target_count; i++)
    {
        KillPet(target_list[i]);
        petType[target_list[i]] = StringToInt(petindex, 10);
        SpawnPet(target_list[i]);
    }
    return Plugin_Handled;
}
i didn't tested yet
Tested it.

1. Pet spawns in a location not near the player when only one player is on the server
2. Pet doesn't follow the player
3. Both commands stop working completely after you spawn a pet
4. Pet model stays in place until you run mp_restartgame 1.

Last edited by 404UserNotFound; 01-09-2014 at 23:43.
404UserNotFound is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 01-10-2014 , 09:58   Re: [TF2] Pets
Reply With Quote #15

Quote:
Originally Posted by abrandnewday View Post
Tested it.

1. Pet spawns in a location not near the player when only one player is on the server
2. Pet doesn't follow the player
3. Both commands stop working completely after you spawn a pet
4. Pet model stays in place until you run mp_restartgame 1.
i am gonna try to fix
arthurdead is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 01-10-2014 , 13:54   Re: [TF2] Pets
Reply With Quote #16

Quote:
Originally Posted by abrandnewday View Post
Tested it.

1. Pet spawns in a location not near the player when only one player is on the server
2. Pet doesn't follow the player
3. Both commands stop working completely after you spawn a pet
4. Pet model stays in place until you run mp_restartgame 1.
1. Works Fine Here
2. Works Fine Here Try Not Giving Pet On Wait For Players
3. Fixed (just remove CreateParticle on KillPet no ideia why that happened)
4. Works Fine Here

Any errors on console ?
arthurdead is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-12-2014 , 21:46   Re: [TF2] Pets
Reply With Quote #17

Quote:
Originally Posted by arthurdead View Post
1. Works Fine Here
2. Works Fine Here Try Not Giving Pet On Wait For Players
3. Fixed (just remove CreateParticle on KillPet no ideia why that happened)
4. Works Fine Here

Any errors on console ?
So I unloaded and reloaded it, now both commands don't do anything whatsoever.

No errors in console, no errors in logs.
404UserNotFound is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 01-13-2014 , 12:15   Re: [TF2] Pets
Reply With Quote #18

Quote:
Originally Posted by abrandnewday View Post
So I unloaded and reloaded it, now both commands don't do anything whatsoever.

No errors in console, no errors in logs.
But It Works Fine Here

Are you sure you got your code right ?

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2>
#include <tf2_stocks>
#include <pets>
#include <smlib>
#pragma semicolon 1

stock AttachParticle(entString:particleType[], String:attachBone[], Float:addPos[3]=NULL_VECTORFloat:addAngle[3]=NULL_VECTOR)
{
    new 
particle CreateEntityByName("info_particle_system"); 
    if (
IsValidEdict(particle)) 
    { 
        new 
String:tName[32]; 
        
GetEntPropString(entProp_Data"m_iName"tNamesizeof(tName)); 
        
DispatchKeyValue(particle"targetname""tf2particle"); 
        
DispatchKeyValue(particle"parentname"tName); 
        
DispatchKeyValue(particle"effect_name"particleType); 
        
DispatchSpawn(particle); 
        
SetVariantString("!activator"); 
        
AcceptEntityInput(particle"SetParent"entent0); 
        
SetVariantString(attachBone);
        
AcceptEntityInput(particle"SetParentAttachment"particleparticle0); 
        
ActivateEntity(particle); 

        
TeleportEntity(particleaddPosaddAngleNULL_VECTOR); 
        
AcceptEntityInput(particle"start"); 
    } 
    return 
particle
}

stock AttachModel(entString:Modelname[], String:attachBone[], Float:addPos[3]=NULL_VECTORFloat:addAngle[3]=NULL_VECTOR)
{
    new 
model CreateEntityByName("prop_dynamic_override"); 
    if (
IsValidEdict(model)) 
    {
        new 
String:tName[32]; 
        
GetEntPropString(entProp_Data"m_iName"tNamesizeof(tName)); 
        
DispatchKeyValue(model"targetname""tf2modelattach"); 
        
DispatchKeyValue(model"model"Modelname); 
        
DispatchKeyValue(model"parentname"tName); 
        
SetVariantString("!activator"); 
        
AcceptEntityInput(model"SetParent"entent0); 
        
SetVariantString(attachBone);
        
AcceptEntityInput(model"SetParentAttachment"modelmodel0); 
        
DispatchSpawn(model); 
        
SetEntityModel(modelModelname);
        
TeleportEntity(modeladdPosaddAngleNULL_VECTOR); 
    } 
    return 
model
}

stock SafeKillTimer(&Handle:timer)
{
    if(
timer != INVALID_HANDLE)
    {
        
KillTimer(timer);
        
timer INVALID_HANDLE;
    }
}

stock CreateParticle(String:particle[], Float:pos[3])
{
    new 
tblidx FindStringTable("ParticleEffectNames");
    new 
String:tmp[256];
    new 
count GetStringTableNumStrings(tblidx);
    new 
stridx INVALID_STRING_INDEX;
    for(new 
i=0i<counti++)
    {
        
ReadStringTable(tblidxitmpsizeof(tmp));
        if(
StrEqual(tmpparticlefalse))
        {
            
stridx i;
            break;
        }
    }
    for(new 
i=1i<=GetMaxClients(); i++)
    {
        if(!
IsValidEntity(i)) continue;
        if(!
IsClientInGame(i)) continue;
        
TE_Start("TFParticleEffect");
        
TE_WriteFloat("m_vecOrigin[0]"pos[0]);
        
TE_WriteFloat("m_vecOrigin[1]"pos[1]);
        
TE_WriteFloat("m_vecOrigin[2]"pos[2]);
        
TE_WriteNum("m_iParticleSystemIndex"stridx);
        
TE_SendToClient(i0.0);
    }
}

new 
pet[MAXPLAYERS+1];
new 
petType[MAXPLAYERS+1];
new 
petState[MAXPLAYERS+1];
new 
Handle:soundTimer[MAXPLAYERS+1] = INVALID_HANDLE;
new 
Float:g_pos[3];
new 
bool:inColldown[MAXPLAYERS+1];

public 
OnPluginStart()
{
    
RegConsoleCmd("givepet"Command_SpawnPet);
    
RegConsoleCmd("killpet"Command_KillPet);
    
HookEvent("player_death"Event_DeathEventHookMode_Post);
    
HookEvent("player_spawn"Event_SpawnEventHookMode_Post);
}

public 
OnMapStart()
{
    for(new 
i=1i<sizeof(petInfo); i++)
    {
        
PrecacheModel(petInfo[i][iModel]);
        
PrecacheModel(petInfo[i][iHat]);
        
PrecacheModel(petInfo[i][iWep]);
        
PrecacheSound(petInfo[i][iSoundGeneric]);
        
PrecacheSound(petInfo[i][iSoundJump]);
        
PrecacheSound(petInfo[i][iSoundTaunt]);
        
PrecacheSound(petInfo[i][iSoundSpawn]);
        
PrecacheSound(petInfo[i][iSoundDuck]);
        
PrecacheSound(petInfo[i][iSoundAttack]);
        
PrecacheSound(petInfo[i][iSoundStun]);
        
PrecacheSound(petInfo[i][iSoundFoot0]);
        
PrecacheSound(petInfo[i][iSoundFoot1]);
        
PrecacheSound(petInfo[i][iSoundFoot2]);
    }
}

public 
Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if(
petType[client] != 0)
    {
        
SpawnPet(client);
    }
}

public 
Action:Event_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
victim GetClientOfUserId(GetEventInt(event"userid"));
    
KillPet(victim);
}

public 
OnPluginEnd()
{
    for (new 
1<=MaxClientsi++)
    {
        
KillPet(i);
    }
}

public 
Action:Command_KillPet(clientargs)
{
    new 
String:target[PLATFORM_MAX_PATH];
    
GetCmdArg(1targetPLATFORM_MAX_PATH);
    
decl String:target_name[MAX_TARGET_LENGTH];
    
decl target_list[MAXPLAYERS], target_count;
    new 
bool:tn_is_ml;
    if ((
target_count ProcessTargetString(
    
target,
    
client,
    
target_list,
    
MAXPLAYERS,
    
COMMAND_FILTER_ALIVE,
    
target_name,
    
sizeof(target_name),
    
tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }
    for (new 
0target_counti++)
    {
        
KillPet(target_list[i]);
    }
    return 
Plugin_Handled;
}

public 
Action:Command_SpawnPet(clientargs)
{
    new 
String:target[PLATFORM_MAX_PATH];
    new 
String:petindex[PLATFORM_MAX_PATH];
    
GetCmdArg(1targetPLATFORM_MAX_PATH);
    
GetCmdArg(2petindexPLATFORM_MAX_PATH);
    
decl String:target_name[MAX_TARGET_LENGTH];
    
decl target_list[MAXPLAYERS], target_count;
    new 
bool:tn_is_ml;
    if ((
target_count ProcessTargetString(
    
target,
    
client,
    
target_list,
    
MAXPLAYERS,
    
COMMAND_FILTER_ALIVE,
    
target_name,
    
sizeof(target_name),
    
tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }
    for (new 
0target_counti++)
    {
        new 
strint StringToInt(petindex10);
        if(
strint == 0)
        {
            
ReplyToCommand(client"[SM] Invalid Pet Index");
        }
        else
        {
            
KillPet(target_list[i]);
            
petType[target_list[i]] = strint;
            
SpawnPet(target_list[i]);
        }
    }
    return 
Plugin_Handled;
}

public 
SpawnPet(client)
{
    
decl Float:pos[3];
    
GetClientAbsOrigin(clientpos);
    
OffsetLocation(pos);
    if(!(
pet[client] = CreateEntityByName("prop_dynamic_override")))
    {
        return;
    }
    
SetEntPropEnt(pet[client], Prop_Send"m_hOwnerEntity"client);
    new 
String:clientname[PLATFORM_MAX_PATH];
    
GetClientName(clientclientnamePLATFORM_MAX_PATH);
    new 
String:PetName[PLATFORM_MAX_PATH];
    
Format(PetNamePLATFORM_MAX_PATH"%s Pet"clientname);
    
DispatchKeyValue(pet[client], "targetname"PetName);
    
DispatchKeyValue(pet[client], "model"petInfo[petType[client]][iModel]);
    
DispatchKeyValue(pet[client], "DefaultAnim"petInfo[petType[client]][iAnimIdle]);
    
SetVariantString(petInfo[petType[client]][iAnimIdle]);
    
AcceptEntityInput(pet[client], "SetDefaultAnimation");
    
SetVariantInt(petInfo[petType[client]][iSkin]);
    
AcceptEntityInput(pet[client], "skin");
    
SetVariantInt(petInfo[petType[client]][iBodyGroup]);
    
AcceptEntityInput(pet[client], "SetBodyGroup");
    
SetVariantInt(2);
    
AcceptEntityInput(pet[client], "solid");
    
DispatchKeyValueFloat(pet[client], "modelscale"petInfo[petType[client]][iModelSize]);
    
AttachModel(pet[client], petInfo[petType[client]][iHat], petInfo[petType[client]][iHatBone]);
    
AttachModel(pet[client], petInfo[petType[client]][iWep], petInfo[petType[client]][iWepBone]);
    
AttachParticle(pet[client], petInfo[petType[client]][iParticle], petInfo[petType[client]][iParBone]);
    
DispatchSpawn(pet[client]);
    
TeleportEntity(pet[client], posNULL_VECTORNULL_VECTOR);
    
SetPetState(clientSTATE_SPAWNING);
    
CreateParticle(petInfo[petType[client]][iSpawnParticle], pos);
    
EmitAmbientSound(petInfo[petType[client]][iSoundGeneric], pospet[client]);
    
EmitAmbientSound(petInfo[petType[client]][iSoundSpawn], pos);
    
SafeKillTimer(soundTimer[client]);
    
soundTimer[client] = CreateTimer(10.0Timer_GenericSoundclient);
    
SDKHook(clientSDKHook_PreThinkPetThink);
}

public 
PetThink(client)
{
    if(!
IsValidEntity(pet[client]))
    {
        
SDKUnhook(clientSDKHook_PreThinkPetThink);
        return;
    }
    
decl Float:pos[3], Float:ang[3], Float:clientPos[3], Float:clientAng[3];
    
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"pos);
    
GetEntPropVector(pet[client], Prop_Data"m_angRotation"ang);
    
GetClientAbsOrigin(clientclientPos);
    
GetClientAbsAngles(clientclientAng);
    new 
Float:dist GetVectorDistance(clientPospos);
    new 
Float:distX clientPos[0] - pos[0];
    new 
Float:distY clientPos[1] - pos[1];
    new 
Float:speed = (dist 64.0) / 54;
    
Math_Clamp(speed, -4.04.0);
    if(
FloatAbs(speed) < 0.3)
        
speed *= 0.1;
    if(
dist 1024.0)
    {
        
decl Float:posTmp[3];
        
GetClientAbsOrigin(clientposTmp);
        
OffsetLocation(posTmp);
        
TeleportEntity(pet[client], posTmpNULL_VECTORNULL_VECTOR);
        
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"pos);
    }
    if(
pos[0] < clientPos[0])    pos[0] += speed;
    if(
pos[0] > clientPos[0])    pos[0] -= speed;
    if(
pos[1] < clientPos[1])    pos[1] += speed;
    if(
pos[1] > clientPos[1])    pos[1] -= speed;
    switch(
petInfo[petType[client]][iHeight])
    {
        case 
HEIGHT_GROUNDpos[2] = clientPos[2];
        case 
HEIGHT_HOVERpos[2] = clientPos[2] + 32.0;
        case 
HEIGHT_FLYpos[2] = clientPos[2] + 96.0;
    }
    if(!(
GetEntityFlags(client) & FL_ONGROUND))
        
SetPetState(clientSTATE_JUMPING);
    else if(
FloatAbs(speed) > 0.2)
        
SetPetState(clientSTATE_WALKING);
    else if(
TF2_IsPlayerInCondition(clientTFCond_Taunting))
        
SetPetState(clientSTATE_TAUNTING);
    else if(
GetClientButtons(client) & IN_DUCK)
        
SetPetState(clientSTATE_DUCKING);
    else if(
GetClientButtons(client) & IN_ATTACK)
        
SetPetState(clientSTATE_ATTACKING);
    else if(
TF2_IsPlayerInCondition(clientTFCond_Dazed))
        
SetPetState(clientSTATE_STUN);
    else
        
SetPetState(clientSTATE_IDLE);
    
ang[1] = (ArcTangent2(distYdistX) * 180) / 3.14;
    
TeleportEntity(pet[client], posangNULL_VECTOR);
    if(
petState[client] == STATE_ATTACKING)
    {
        
TeleportEntity(pet[client], NULL_VECTORclientAngNULL_VECTOR);
    }
    if(
petState[client] == STATE_ATTACKING && inColldown[client] == false)
    {
        
CreateProjectile(client);
        
inColldown[client] = true;
        
CreateTimer(3.0PetColldownclient);
    }
    if(
petState[client] == STATE_WALKING && inColldown[client] == false)
    {
        new 
footstep GetRandomInt(02);
        switch(
footstep)
        {
            case 
0EmitAmbientSound(petInfo[petType[client]][iSoundFoot0], pospet[client], ___petInfo[petType[client]][iPitch]);
            case 
1EmitAmbientSound(petInfo[petType[client]][iSoundFoot1], pospet[client], ___petInfo[petType[client]][iPitch]);
            case 
2EmitAmbientSound(petInfo[petType[client]][iSoundFoot2], pospet[client], ___petInfo[petType[client]][iPitch]);
        }
        
inColldown[client] = true;
        
CreateTimer(0.5PetColldownclient);
    }
}

public 
Action:PetColldown(Handle:timerany:client)
{
    
inColldown[client] = false;
}

public 
CreateProjectile(client)
{
    if(!
SetTeleportEndPoint(client))
    {
        
PrintToChat(client"[SM] Could not find spawn point.");
    }
    new 
Float:vAngles[3];
    new 
Float:vPosition[3];
    new 
Float:ang[3];
    
GetClientEyeAngles(clientang);
    
GetEntPropVector(pet[client], Prop_Data"m_angRotation"vAngles);
    
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"vPosition);
    new 
iTeam GetClientTeam(client);
    new 
iProject CreateEntityByName(petInfo[petType[client]][iProjectile]);
    
decl Float:vVelocity[3];
    
decl Float:vBuffer[3];
    
GetAngleVectors(vAnglesvBufferNULL_VECTORNULL_VECTOR);
    
vVelocity[0] = vBuffer[0]*1100.0;
    
vVelocity[1] = vBuffer[1]*1100.0;
    
vVelocity[2] = vBuffer[2]*1100.0;
    
SetEntPropEnt(iProjectProp_Send"m_hOwnerEntity"client);
    
SetEntProp(iProjectProp_Send"m_bCritical"100);
    
SetEntProp(iProjectProp_Send"m_iTeamNum"iTeam1);
    
SetEntProp(iProjectProp_Send"m_nSkin", (iTeam-2));
    
vPosition[2] += 50.0;
    
TeleportEntity(iProjectvPositionvAnglesNULL_VECTOR);
    
SetVariantInt(iTeam);
    
AcceptEntityInput(iProject"TeamNum", -1, -10);
    
SetVariantInt(iTeam);
    
AcceptEntityInput(iProject"SetTeam", -1, -10); 
    
DispatchSpawn(iProject);
    
TeleportEntity(iProjectNULL_VECTORangvVelocity);
}

public 
SetTeleportEndPoint(client)
{
    
decl Float:vAngles[3];
    
decl Float:vOrigin[3];
    
decl Float:vBuffer[3];
    
decl Float:vStart[3];
    
decl Float:Distance;
    
GetClientEyePosition(client,vOrigin);
    
GetClientEyeAngles(clientvAngles);
    new 
Handle:trace TR_TraceRayFilterEx(vOriginvAnglesMASK_SHOTRayType_InfiniteTraceEntityFilterPlayer);
    if(
TR_DidHit(trace))
    {        
            
TR_GetEndPosition(vStarttrace);
        
GetVectorDistance(vOriginvStartfalse);
        
Distance = -35.0;
            
GetAngleVectors(vAnglesvBufferNULL_VECTORNULL_VECTOR);
        
g_pos[0] = vStart[0] + (vBuffer[0]*Distance);
        
g_pos[1] = vStart[1] + (vBuffer[1]*Distance);
        
g_pos[2] = vStart[2] + (vBuffer[2]*Distance);
    }
    else
    {
        
CloseHandle(trace);
        return 
false;
    }
    
CloseHandle(trace);
    return 
true;
}

public 
bool:TraceEntityFilterPlayer(entitycontentsMask)
{
    return 
entity MaxClients;
}

public 
Action:Timer_GenericSound(Handle:timerany:client)
{
    if(
pet[client] == || IsValidEntity(pet[client]) == false)
    {
        
SafeKillTimer(timer);
    }
    
decl Float:pos[3];
    
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"pos);
    
EmitAmbientSound(petInfo[petType[client]][iSoundGeneric], pospet[client], ___petInfo[petType[client]][iPitch]);
    
soundTimer[client] = CreateTimer(GetRandomFloat(20.060.0), Timer_GenericSoundclient);
}

public 
SetPetState(clientstatus)
{
    
decl Float:pos[3];
    
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"pos);
    if(
petState[client] == status)
    {
        return;
    }
    switch(
status)
    {
        case 
STATE_IDLESetPetAnim(clientpetInfo[petType[client]][iAnimIdle]);
        case 
STATE_WALKINGSetPetAnim(clientpetInfo[petType[client]][iAnimWalk]);
        case 
STATE_JUMPING:
        {
            
SetPetAnim(clientpetInfo[petType[client]][iAnimJump]);
            
EmitAmbientSound(petInfo[petType[client]][iSoundJump], pospet[client], ___petInfo[petType[client]][iPitch]);
        }
        case 
STATE_TAUNTING:
        {
            
SetPetAnim(clientpetInfo[petType[client]][iAnimTaunt]);
            
EmitAmbientSound(petInfo[petType[client]][iSoundTaunt], pospet[client], ___petInfo[petType[client]][iPitch]);
        }
        case 
STATE_SPAWNING:
        {
            
SetPetAnim(clientpetInfo[petType[client]][iAnimSpawn]);
            
EmitAmbientSound(petInfo[petType[client]][iSoundSpawn], pospet[client], ___petInfo[petType[client]][iPitch]);
        }
        case 
STATE_DUCKING:
        {
            
SetPetAnim(clientpetInfo[petType[client]][iAnimDuck]);
            
EmitAmbientSound(petInfo[petType[client]][iSoundDuck], pospet[client], ___petInfo[petType[client]][iPitch]);
        }
        case 
STATE_ATTACKING:
        {
            
SetPetAnim(clientpetInfo[petType[client]][iAnimAttack]);
            
EmitAmbientSound(petInfo[petType[client]][iSoundAttack], pospet[client], ___petInfo[petType[client]][iPitch]);
        }
        case 
STATE_STUN:
        {
            
SetPetAnim(clientpetInfo[petType[client]][iAnimStun]);
            
EmitAmbientSound(petInfo[petType[client]][iSoundStun], pospet[client], ___petInfo[petType[client]][iPitch]);
        }
    }
    
petState[client] = status;
}

public 
SetPetAnim(client, const String:anim[])
{
    
SetVariantString(anim);
    
AcceptEntityInput(pet[client], "SetAnimation");
}

public 
OffsetLocation(Float:pos[3])
{
    
pos[0] += GetRandomFloat(-128.0128.0);
    
pos[1] += GetRandomFloat(-128.0128.0);
}


public 
KillPet(client)
{
    if(
pet[client] == 0)
    {
        return;
    }
    
decl Float:pos[3];
    
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"pos);
    
SDKUnhook(clientSDKHook_PreThinkPetThink);
    
AcceptEntityInput(pet[client], "Kill");
    
CreateParticle(petInfo[petType[client]][iDeathParticle], pos);
    
pet[client] = 0;

arthurdead is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-13-2014 , 12:23   Re: [TF2] Pets
Reply With Quote #19

Quote:
Originally Posted by arthurdead View Post
But It Works Fine Here

Are you sure you got your code right ?
It's weird, I'm using the same code, yet whenever I do the commands, it tells me the commands don't exist. The plugin is loaded, it doesn't error out on load, but the commands just fail to do anything.

EDIT: Weird, now it works all of a sudden. That was....odd....

EDIT 2: Error upon unloading the plugin after I've already killed off any pets:

Code:
L 01/13/2014 - 12:39:55: [SM] Native "GetEntPropVector" reported: Entity 1128 (1128) is invalid
L 01/13/2014 - 12:39:55: [SM] Displaying call stack trace for plugin "pets.smx":
L 01/13/2014 - 12:39:55: [SM]   [0]  Line 483, C:\Coding\addons\sourcemod\scripting\pets.sp::KillPet()
L 01/13/2014 - 12:39:55: [SM]   [1]  Line 207, C:\Coding\addons\sourcemod\scripting\pets.sp::Command_SpawnPet()

Last edited by 404UserNotFound; 01-13-2014 at 12:44.
404UserNotFound is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 01-13-2014 , 12:56   Re: [TF2] Pets
Reply With Quote #20

Quote:
Originally Posted by abrandnewday View Post
It's weird, I'm using the same code, yet whenever I do the commands, it tells me the commands don't exist. The plugin is loaded, it doesn't error out on load, but the commands just fail to do anything.

EDIT: Weird, now it works all of a sudden. That was....odd....

EDIT 2: Error upon unloading the plugin after I've already killed off any pets:

Code:
L 01/13/2014 - 12:39:55: [SM] Native "GetEntPropVector" reported: Entity 1128 (1128) is invalid
L 01/13/2014 - 12:39:55: [SM] Displaying call stack trace for plugin "pets.smx":
L 01/13/2014 - 12:39:55: [SM]   [0]  Line 483, C:\Coding\addons\sourcemod\scripting\pets.sp::KillPet()
L 01/13/2014 - 12:39:55: [SM]   [1]  Line 207, C:\Coding\addons\sourcemod\scripting\pets.sp::Command_SpawnPet()
IsValidEntity on killpet ?
arthurdead 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 10:18.


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