AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [TF2] Pets (https://forums.alliedmods.net/showthread.php?t=232650)

arthurdead 01-02-2014 17:42

[TF2] Pets
 
3 Attachment(s)
original code made by noodleboy347 kinda fixed by me and fixes/improvements by abrandnewday

Public Commands:
sm_givepet <petindex> - Gives Yourself A Pet
sm_killpet - Slay Your Pet

Admin Commands Requires Cheats Flag
sm_spawnpet <client> <pet index> - Allows an admin to spawn a pet for a player.
sm_slaypet <client> - Allows an admin to slay a player's pet.

Public Commands If you Have An Pet
sm_petwait - makes your pet stop following you
sm_petfollow - makes your pet follow you

Instructions
1. Download playerpets.smx, put that into addons/sourcemod/plugins
2. Download playerpets.phrases.txt, put that into addons/sourcemod/translations
3. Load it up ingame via "rcon sm plugins load playerpets"

If you want to make your own custom pets:
1. Click "Get Source" below to download playerpets.sp
2. Download playerpets.inc as well, this is where you code in custom pets.
3. Put playerpets.inc into your "includes" folder, wherever you store your coding resources
4. Put playerpets.sp into the "scripting" folder.
5. Edit playerpets.inc and create your own custom pets.
6. Complie playerpets.sp.

Note: to not remove the first pet on the list (it counts as pet index 0)

Oshizu 01-02-2014 18:49

Re: [delete pls]
 
Here lies fixed 'Golden Machine Gun' pets plugin

Notice: if it's public for more than one hour publisher gonna have seizure out of reason RQWERQRQEDRESARAEREQRAR

arthurdead 01-03-2014 10:48

Re: [delete pls]
 
Quote:

Originally Posted by Oshizu (Post 2080269)
Here lies fixed 'Golden Machine Gun' pets plugin

Notice: if it's public for more than one hour publisher gonna have seizure out of reason RQWERQRQEDRESARAEREQRAR

actually i am gonna release later just gonna tweak more

Sreaper 01-03-2014 12:06

Re: [delete pls]
 
What is this pet mod and how does it work? I know gmg has a pet plugin up for download but I've never actually looked at the source code.

psychonic 01-03-2014 12:48

Re: [delete pls]
 
Quote:

Originally Posted by arthurdead (Post 2080244)
[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.

arthurdead 01-03-2014 13:05

Re: [delete pls]
 
Quote:

Originally Posted by psychonic (Post 2080587)

i was just going to make a new version

Mr. Man 01-03-2014 13:11

Re: [TF2] Pets
 
W-wha? I am confused about what this plugin does...

404UserNotFound 01-09-2014 02:03

Re: [TF2] Pets
 
So after looking at the code and trying to compile it, a few things:

1. You're probably going to want to change "<gmg/pets>" to just "<pets>" and pop the pets.inc contents into your "include" folder
2. You're gonna want to add this to the top of pets.sp:
PHP Code:

#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>
#include <sdkhooks> 

Otherwise you'll have huge error spam when you try to compile
3. Once you've done 1 and 2, the only error left will be the lack of a TraceEntityFilterPlayer function which you can find in many plugins.

I haven't fully compiled this or added in a command to spawn a pet and test it, but it looks promising.

arthurdead 01-09-2014 02:23

Re: [TF2] Pets
 
Quote:

Originally Posted by abrandnewday (Post 2083310)
So after looking at the code and trying to compile it, a few things:

1. You're probably going to want to change "<gmg/pets>" to just "<pets>" and pop the pets.inc contents into your "include" folder
2. You're gonna want to add this to the top of pets.sp:
PHP Code:

#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>
#include <sdkhooks> 

Otherwise you'll have huge error spam when you try to compile
3. Once you've done 1 and 2, the only error left will be the lack of a TraceEntityFilterPlayer function which you can find in many plugins.

I haven't fully compiled this or added in a command to spawn a pet and test it, but it looks promising.

fixed and added command to spawn/kill pet

404UserNotFound 01-09-2014 21:08

Re: [TF2] Pets
 
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()

Another bug is that no matter what playerfilter (i.e. if I choose myself) you use, it seems to always get "attached" to a specific player.


All times are GMT -4. The time now is 21:02.

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