Raised This Month: $32 Target: $400
 8% 

Attaching a sprite to a player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NanoC
Veteran Member
Join Date: Jan 2016
Location: Argentina
Old 03-21-2019 , 00:09   Attaching a sprite to a player
Reply With Quote #1

I'm currently working in a simple plugin that serve to put a simple sprite in the head of the players like this:


=============================


The plugin works fine sometimes, but the problem is, when the round starts some sprites disappear, and when a person who have the sprite in the head dies, the sprite DON'T dissapear, it stays in the site of the death person (static). You can test the plugin youself and see how it works.
I think there's something wrong with the Sprite entity, or i've made a bad way to kill the sprite. Can someone help me? thanks

Code:

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
//#include <hl_gangs>

new g_unClientSprite[MAXPLAYERS+1]={INVALID_ENT_REFERENCE,...};

int g_iTimer;

public 
Plugin myinfo =
{
    
name "Icons for Gangs",
    
author "Nano",
    
description "",
    
version "2.1",
    
url "http://steamcommunity.com/id/marianzet1"
};

public 
void OnPluginStart()
{
    
HookEvent("round_start"round_start);
    
HookEvent("player_death"Event_PlayerDeath);
//    HookEvent("round_end", round_end);
}

public 
void OnMapStart()
{
    
AddFileToDownloadsTable("materials/decals/rage/pandilla.vtf");
    
AddFileToDownloadsTable("materials/decals/rage/pandilla.vmt");
    
PrecacheModel("materials/decals/rage/pandilla.vmt"true);
}

public 
void OnClientConnected(int client)
{
    
g_unClientSprite[client]=INVALID_ENT_REFERENCE;
}

public 
void OnClientDisconnect(int client)
{
    
ResetSprite(client);
}

public 
Action round_start(Event eventchar[] namebool dontBroadcast
{    
    
CreateTimer(1.0Timer_SetSprite_TIMER_REPEAT);
}

public 
Action Timer_SetSprite(Handle timer)
{
    if (
g_iTimer <= 60)
    {
        for (
int i 1<= MaxClientsi++) 
        {
            if(
IsValidClient(i) && GetClientTeam(i) == CS_TEAM_T)
            {
                
CreateSprite(i);
            }
        }
        
g_iTimer++;

        return 
Plugin_Continue;
    }

    
g_iTimer 0;
    
    return 
Plugin_Stop;
}

public 
Action Event_PlayerDeath(Event eventchar[] namebool dontBroadcast
{
    for (
int i 1<= MaxClientsi++) 
    {
        if(
IsValidClient(i) && GetClientTeam(i) == CS_TEAM_T)
        {
            
ResetSprite(i);
        }
    }
}



//I've tested this too:
/*
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) 
{
    int client = GetClientOfUserId(event.GetInt("userid"));
    if (client > 0 && IsValidClient(client)) 
    {
        ResetSprite(client);
    }

    return Plugin_Continue;
}
*/



public ResetSprite(client)
{
    if(
g_unClientSprite[client] == INVALID_ENT_REFERENCE)
        return;

    new 
m_unEnt EntRefToEntIndex(g_unClientSprite[client]);
    
g_unClientSprite[client] = INVALID_ENT_REFERENCE;
    if(
m_unEnt == INVALID_ENT_REFERENCE)
        return;

    
AcceptEntityInput(m_unEnt"Kill");
}

public 
CreateSprite(client)
{
    if(
g_unClientSprite[client] != INVALID_ENT_REFERENCE)
        return;

    new 
m_unEnt CreateEntityByName("env_sprite");
    if (
IsValidEntity(m_unEnt))
    {
        
char iTarget[16], sTargetname[64];
        
GetEntPropString(clientProp_Data"m_iName"sTargetnamesizeof(sTargetname));

        
Format(iTargetsizeof(iTarget), "Client%d"client);
        
DispatchKeyValue(client"targetname"iTarget);

        
float m_flPosition[3];
        
GetClientEyePosition(clientm_flPosition);
        
m_flPosition[2] += 20.0;
        
g_unClientSprite[client] = EntIndexToEntRef(m_unEnt);

        
DispatchKeyValue(m_unEnt"model""materials/decals/rage/pandilla.vmt");
        
DispatchKeyValue(m_unEnt"classname""env_sprite");
        
DispatchKeyValue(m_unEnt"spawnflags""1");
        
DispatchKeyValue(m_unEnt"scale""0.1");
        
DispatchKeyValue(m_unEnt"rendermode""1");
        
DispatchKeyValue(m_unEnt"rendercolor""255 255 255");
        
DispatchSpawn(m_unEnt);
        
TeleportEntity(m_unEntm_flPositionNULL_VECTORNULL_VECTOR);
        
SetVariantString(iTarget);
        
AcceptEntityInput(m_unEnt"SetParent"clientm_unEnt0);

        
DispatchKeyValue(client"targetname"sTargetname);
    }
}


bool IsValidClient(int client
{
    return (
client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client));

__________________

Last edited by NanoC; 03-21-2019 at 00:10.
NanoC is offline
Send a message via Skype™ to NanoC
BHaType
Great Tester of Whatever
Join Date: Jun 2018
Old 03-21-2019 , 02:39   Re: Attaching a sprite to a player
Reply With Quote #2

I don't play CSGO but I think it will work

https://pastebin.com/9dD9wXnz

Last edited by BHaType; 03-21-2019 at 02:40.
BHaType is offline
Send a message via AIM to BHaType
NanoC
Veteran Member
Join Date: Jan 2016
Location: Argentina
Old 03-21-2019 , 12:06   Re: Attaching a sprite to a player
Reply With Quote #3

Thanks for your reply! The plugin works fine but it's happening the same error; if a player dies, it won't have the sprite in the next round, same if the round is restarted via mp_restartgame 1

*Edit:
Fixed, thank you for the help anyway!
__________________

Last edited by NanoC; 03-21-2019 at 12:51.
NanoC is offline
Send a message via Skype™ to NanoC
Angeelor
Member
Join Date: Jan 2017
Old 03-23-2019 , 16:39   Re: Attaching a sprite to a player
Reply With Quote #4

I think that already exists

Angeelor is offline
NanoC
Veteran Member
Join Date: Jan 2016
Location: Argentina
Old 03-23-2019 , 16:50   Re: Attaching a sprite to a player
Reply With Quote #5

Quote:
Originally Posted by Angeelor View Post
I think that already exists
I was writing that code to use it with HL_Gangs plugin, so only players who are in a gang can have the sprite in the head, i don't know if i can do that with that plugin
__________________
NanoC is offline
Send a message via Skype™ to NanoC
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:44.


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