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

Color Players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yoloro0
Junior Member
Join Date: Apr 2020
Location: Universe
Old 05-01-2020 , 16:44   Color Players
Reply With Quote #1

I have a problem with this script

Code:
#include <cstrike>

#define TEAM_CT 3
#define TEAM_T 2

public Plugin myinfo =  {
    name = "FFA Colours", 
    author = "Loro", 
    description = "Colorize player model.", 
    version = "1.0", 
    url = "forums.alliedmods.net"
};

public OnPluginStart()
{
    HookEvent("player_spawn", Event_PlayerSpawn);
}

public Action Event_PlayerSpawn(Event event, char[] name, bool dontBroadcast)
{
    
    int client = GetClientOfUserId(event.GetInt("userid"));
    
    if (IsPlayerAlive(client))
    {
        switch (GetClientTeam(client))
        {
            case (TEAM_CT): SetEntityRenderColor(client, 255, 0, 0, 255);
            case (TEAM_T): SetEntityRenderColor(client, 255, 0, 0, 255);
        }
    }
}
I try to make all the players red but this script just not working.
yoloro0 is offline
Balimbanana
Member
Join Date: Jan 2017
Old 05-01-2020 , 21:33   Re: Color Players
Reply With Quote #2

It might be too early to color them. Should maybe debug each step, IsPlayerAlive might be false at the immediate point of player_spawn. You could try setting a timer or looping timer this is what I usually do for post spawn:
Code:
public Action Event_PlayerSpawn(Event event, char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(event.GetInt("userid"));
	CreateTimer(0.5,SpawnPost,client,TIMER_FLAG_NO_MAPCHANGE);
}

public Action SpawnPost(Handle timer, int client)
{
	if (IsValidEntity(client) && IsPlayerAlive(client))
	{
		//Code to run
	}
	else if (IsClientConnected(client))
	{
		CreateTimer(0.5,SpawnPost,client,TIMER_FLAG_NO_MAPCHANGE);
	}
}
Balimbanana is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 05-02-2020 , 09:27   Re: Color Players
Reply With Quote #3

Quote:
Originally Posted by Balimbanana View Post
It might be too early to color them. Should maybe debug each step, IsPlayerAlive might be false at the immediate point of player_spawn. You could try setting a timer or looping timer this is what I usually do for post spawn:
Code:
public Action Event_PlayerSpawn(Event event, char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(event.GetInt("userid"));
	CreateTimer(0.5,SpawnPost,client,TIMER_FLAG_NO_MAPCHANGE);
}

public Action SpawnPost(Handle timer, int client)
{
	if (IsValidEntity(client) && IsPlayerAlive(client))
	{
		//Code to run
	}
	else if (IsClientConnected(client))
	{
		CreateTimer(0.5,SpawnPost,client,TIMER_FLAG_NO_MAPCHANGE);
	}
}
I don't think so, if you're hooking an event with EventHookMode_Post (default) then player is actually alive at player_spawn event.

Also, since you're using EventHookMode_Post, you should replace your event callback from
Code:
public Action Event_PlayerSpawn(Event event, char[] name, bool dontBroadcast)
to
Code:
public void Event_PlayerSpawn(Event event, char[] name, bool dontBroadcast)
void is used with EventHookMode_Post and EventHookMode_PostNoCopy while Action is used with EventHookMode_Pre

Try to use SetEntityRenderMode with SetEntityRenderColor, for example:
Code:
SetEntityRenderMode(client, RENDER_TRANSCOLOR);
SetEntityRenderColor(client, 255, 0, 0, 255);
And at the end, if you want to color ALL players then you don't need to check their teams + you should not include cstrike library if your code doesn't have anything CS-related.
__________________

Last edited by MAGNAT2645; 05-02-2020 at 09:35.
MAGNAT2645 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 05-02-2020 , 09:38   Re: Color Players
Reply With Quote #4

Quote:
Originally Posted by Balimbanana View Post
It might be too early to color them.
RequestFrame would probably work for this instead of using a timer. Also you should be passing the userid instead of client index into timers and retrieving to verify it's the same client. More info here.

Might need this before you set the color if it still fails, probably not.
PHP Code:
SetEntityRenderMode(clientRENDER_TRANSCOLOR); 
__________________

Last edited by Silvers; 05-02-2020 at 09:39.
Silvers is offline
Reply


Thread Tools
Display Modes

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 12:42.


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