BAFFLED
|
01-03-2014
, 12:48
Re: [delete pls]
|
#5
|
Quote:
Originally Posted by arthurdead
[TF2] Pets
this was made by noodleboy i just edited a bit requires smlib
to spawn a pet just
petType[client] = petnumber in the inc file;
SpawnPet(client);
example
petType[client] = 1;
SpawnPet(client);
this will spawn Mrs.Skelly
pets.sp
Code:
new pet[MAXPLAYERS+1];
new petType[MAXPLAYERS+1];
new petState[MAXPLAYERS+1];
new Handle:soundTimer[MAXPLAYERS+1] = INVALID_HANDLE;
public SpawnPet(client)
{
decl Float:pos[3];
GetClientAbsOrigin(client, pos);
OffsetLocation(pos);
if(!(pet[client] = CreateEntityByName("prop_dynamic_override")))
{
return;
}
PrecacheModel(petInfo[petType[client]][iModel]);
SetEntityModel(pet[client], petInfo[petType[client]][iModel]);
DispatchSpawn(pet[client]);
TeleportEntity(pet[client], pos, NULL_VECTOR, NULL_VECTOR);
SetEntPropFloat(pet[client], Prop_Send, "m_flModelScale", petInfo[petType[client]][iModelSize]);
SetPetState(client, STATE_SPAWNING);
CreateParticle(petInfo[petType[client]][iSpawnParticle], pos);
EmitAmbientSound(petInfo[petType[client]][iSoundGeneric], pos, pet[client]);
EmitAmbientSound(petInfo[petType[client]][iSoundSpawn], pos);
SetEntProp(client, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_NPC);
SetEntityRenderMode(pet[client], RENDER_TRANSADD);
SafeKillTimer(soundTimer[client]);
soundTimer[client] = CreateTimer(10.0, Timer_GenericSound, client);
SDKHook(client, SDKHook_PreThink, PetThink);
}
public PetThink(client)
{
if(!IsValidEntity(pet[client]))
{
SDKUnhook(client, SDKHook_PreThink, PetThink);
return;
}
decl Float:pos[3], Float:ang[3], Float:clientPos[3];
GetEntPropVector(pet[client], Prop_Data, "m_vecOrigin", pos);
GetEntPropVector(pet[client], Prop_Data, "m_angRotation", ang);
GetClientAbsOrigin(client, clientPos);
new Float:dist = GetVectorDistance(clientPos, pos);
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.0, 4.0);
if(FloatAbs(speed) < 0.3)
speed *= 0.1;
if(dist > 1024.0)
{
decl Float:posTmp[3];
GetClientAbsOrigin(client, posTmp);
OffsetLocation(posTmp);
TeleportEntity(pet[client], posTmp, NULL_VECTOR, NULL_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_GROUND: pos[2] = clientPos[2];
case HEIGHT_HOVER: pos[2] = clientPos[2] + 32.0;
case HEIGHT_FLY: pos[2] = clientPos[2] + 96.0;
}
if(!(GetEntityFlags(client) & FL_ONGROUND))
SetPetState(client, STATE_JUMPING);
else if(FloatAbs(speed) > 0.2)
SetPetState(client, STATE_WALKING);
else if(TF2_IsPlayerInCondition(client, TFCond_Taunting))
SetPetState(client, STATE_TAUNTING);
else if(GetClientButtons(client) & IN_DUCK)
SetPetState(client, STATE_DUCKING);
else
SetPetState(client, STATE_IDLE);
ang[1] = (ArcTangent2(distY, distX) * 180) / 3.14;
TeleportEntity(pet[client], pos, ang, NULL_VECTOR);
}
public Action:Timer_GenericSound(Handle:timer, any:client)
{
if(pet[client] == 0 || !IsValidEntity(pet[client]))
{
KillTimer(timer);
}
decl Float:pos[3];
GetEntPropVector(pet[client], Prop_Data, "m_vecOrigin", pos);
EmitAmbientSound(petInfo[petType[client]][iSoundGeneric], pos, pet[client], _, _, _, petInfo[petType[client]][iPitch]);
soundTimer[client] = CreateTimer(GetRandomFloat(20.0, 60.0), Timer_GenericSound, client);
}
public SetPetState(client, status)
{
decl Float:pos[3];
GetEntPropVector(pet[client], Prop_Data, "m_vecOrigin", pos);
if(petState[client] == status)
{
return;
}
switch(status)
{
case STATE_IDLE: SetPetAnim(client, petInfo[petType[client]][iAnimIdle]);
case STATE_WALKING: SetPetAnim(client, petInfo[petType[client]][iAnimWalk]);
case STATE_JUMPING:
{
SetPetAnim(client, petInfo[petType[client]][iAnimJump]);
EmitAmbientSound(petInfo[petType[client]][iSoundJump], pos, pet[client], _, _, _, petInfo[petType[client]][iPitch]);
}
case STATE_TAUNTING:
{
SetPetAnim(client, petInfo[petType[client]][iAnimTaunt]);
EmitAmbientSound(petInfo[petType[client]][iSoundTaunt], pos, pet[client], _, _, _, petInfo[petType[client]][iPitch]);
}
case STATE_SPAWNING:
{
SetPetAnim(client, petInfo[petType[client]][iAnimSpawn]);
EmitAmbientSound(petInfo[petType[client]][iSoundSpawn], pos, pet[client], _, _, _, petInfo[petType[client]][iPitch]);
}
case STATE_DUCKING:
{
SetPetAnim(client, petInfo[petType[client]][iAnimDuck]);
EmitAmbientSound(petInfo[petType[client]][iSoundDuck], pos, pet[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.0, 128.0);
pos[1] += GetRandomFloat(-128.0, 128.0);
}
public KillPet(client)
{
if(pet[client] == 0)
{
return;
}
decl Float:pos[3];
Entity_GetAbsOrigin(pet[client], pos);
SDKUnhook(client, SDKHook_PreThink, PetThink);
AcceptEntityInput(pet[client], "Kill");
CreateParticle(petInfo[petType[client]][iDeathParticle], pos);
pet[client] = 0;
}
pets.inc
Code:
#define STATE_IDLE 1
#define STATE_WALKING 2
#define STATE_JUMPING 3
#define STATE_SPAWNING 4
#define STATE_TAUNTING 5
#define STATE_DUCKING 6
#define HEIGHT_GROUND 1
#define HEIGHT_HOVER 2
#define HEIGHT_FLY 3
enum petContent
{
String:iModel[PLATFORM_MAX_PATH],
String:iSoundGeneric[PLATFORM_MAX_PATH],
String:iSoundJump[PLATFORM_MAX_PATH],
String:iSoundTaunt[PLATFORM_MAX_PATH],
String:iSoundSpawn[PLATFORM_MAX_PATH],
String:iSoundDuck[PLATFORM_MAX_PATH],
String:iAnimIdle[PLATFORM_MAX_PATH],
String:iAnimWalk[PLATFORM_MAX_PATH],
String:iAnimJump[PLATFORM_MAX_PATH],
String:iAnimTaunt[PLATFORM_MAX_PATH],
String:iAnimSpawn[PLATFORM_MAX_PATH],
String:iAnimDuck[PLATFORM_MAX_PATH],
String:iDeathParticle[PLATFORM_MAX_PATH],
String:iSpawnParticle[PLATFORM_MAX_PATH],
Float:iModelSize,
iPitch,
iHeight,
};
stock petInfo[][petContent] =
{
{
"models/empty.mdl",
"misc/null.wav",
"misc/null.wav",
"misc/null.wav",
"misc/null.wav",
"misc/null.wav",
"idle", "idle", "idle", "idle", "idle", "idle",
"unknown",
"unknown",
0.0,
0,
0,
},
{
"models/bots/skeleton_sniper/skeleton_sniper.mdl",
"misc/halloween/skeletons/skelly_small_21.wav",
"misc/halloween/skeletons/skelly_small_06.wav",
"misc/halloween/skeletons/skelly_small_20.wav",
"misc/halloween/spell_skeleton_horde_rise.wav",
"misc/halloween/skeletons/skelly_small_11.wav",
"stand_LOSER", "s_swimAlign_LOSER", "a_jumpstart_LOSER", "taunt06", "spawn06", "crouch_LOSER",
"ghost_appearation",
"ghost_appearation",
0.5,
100,
HEIGHT_GROUND,
}
};
Code:
stock SafeKillTimer(&Handle:timer)
{
if(timer != INVALID_HANDLE)
{
KillTimer(timer);
timer = INVALID_HANDLE;
}
}
Code:
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=0; i<count; i++)
{
ReadStringTable(tblidx, i, tmp, sizeof(tmp));
if(StrEqual(tmp, particle, false))
{
stridx = i;
break;
}
}
for(new i=1; i<=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(i, 0.0);
}
}
|
https://forums.alliedmods.net/misc.php?do=showrules
Quote:
Do not blank out posts - if you solve your problem post the solution for others to find.
|
|
|