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

L4D2 How to add hint text


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SilentBr
Veteran Member
Join Date: Jan 2009
Old 09-11-2013 , 22:48   L4D2 How to add hint text
Reply With Quote #1

Silvers sent me this code to set the HP tank because l4d_multitanks has a lot of bugs. I did some changes and fixes but I'm having trouble how to show a hint message to infected team with tank HP.

Can someone help?

tank hp code:
Code:
#include <sourcemod>
#include <sdktools>

#define g_iCvarHealth 65000 

public OnPluginStart()
{
    HookEvent("tank_spawn", tank_spawn);
}

public tank_spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new userid = GetEventInt(event, "userid");
    CreateTimer(0.1, tmrHealth, userid);
}

public Action:tmrHealth(Handle:timer, any:userid)
{
    new client = GetClientOfUserId(userid)
    if( client && IsClientInGame(client))
    {
        SetEntityHealth(client, g_iCvarHealth);
    }
}
SilentBr is offline
super_leaf
Junior Member
Join Date: Oct 2012
Old 09-12-2013 , 06:47   Re: L4D2 How to add hint text
Reply With Quote #2

I don't know how to use hint message yet but I have a question of this: Why do you need to set up a timer to change the tank's health, instead of change it immediately after it spawn?
super_leaf is offline
super_leaf
Junior Member
Join Date: Oct 2012
Old 09-12-2013 , 06:54   Re: L4D2 How to add hint text
Reply With Quote #3

Well, dude, I have looked for certain functions for messaging, this is what I've got:

ShowVGUIPanel
PrintCenterText

Check the SourceMod api for usage. Click here

Or, try this out:
PHP Code:
new Handle:bf StartMessageOne("HintText"client);
BfWriteString(bf"This is a hint message!");
EndMessage(); 

Last edited by super_leaf; 09-12-2013 at 06:54.
super_leaf is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-12-2013 , 09:47   Re: L4D2 How to add hint text
Reply With Quote #4

Is there a particular reason you're not using PrintHintText?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
SilentBr
Veteran Member
Join Date: Jan 2009
Old 09-12-2013 , 13:21   Re: L4D2 How to add hint text
Reply With Quote #5

Quote:
Originally Posted by super_leaf View Post
I don't know how to use hint message yet but I have a question of this: Why do you need to set up a timer to change the tank's health, instead of change it immediately after it spawn?
You mean sm_cvar z_tank_health <value>? Doesn't work neither on windows nor linux, whatever value I put, the tank become with 1 HP.

Quote:
Originally Posted by Powerlord View Post
Is there a particular reason you're not using PrintHintText?
I was coding with "PrintHintText", it was working but with serious bugs:
1 - If a player lose the tank control, still showing his HP even with another zombie class and not the real tank itself. While the "first tank" doesn't spawn or die with the other zombie class, still showing his IP at same time with the player that is playing as tank.
2 - When the tank dies, appear a weird HP

look:

Code:
#include <sourcemod>
#include <sdktools>

#define g_iCvarHealth 22000
#define INFECTED 3

public OnPluginStart() { 
	HookEvent("tank_spawn", tank_spawn); 
} 

public tank_spawn(Handle:event, const String:name[], bool:dontBroadcast) { 
	new userid = GetEventInt(event, "userid");

	CreateTimer(0.1, tmrHealth, userid);
	CreateTimer(0.5, tmrHint, userid, TIMER_REPEAT);
} 

public Action:tmrHealth(Handle:timer, any:userid) {
	new client = GetClientOfUserId(userid);
	
	if (client && IsClientInGame(client)) 
		SetEntityHealth(client, g_iCvarHealth);
		
	return Plugin_Stop;
}

public Action:tmrHint(Handle:timer, any:userid) {
	new client = GetClientOfUserId(userid);
	
	if (IsValidClient(client) && IsPlayerAlive(client)) {
		new health = GetClientHealth(client);
		for (new i = 1; i <= MaxClients; i++)
			if (IsValidClient(i) && GetClientTeam(i) == INFECTED)
				PrintHintText(i, "TANK %N %d/%d", client, health, g_iCvarHealth);

		return Plugin_Continue;
	}
	
	return Plugin_Stop;
}

IsValidClient(client) {
	if(client <= 0 || client > MaxClients || !IsClientConnected(client))
		return false;

	return IsClientInGame(client);
}
SilentBr is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 09-13-2013 , 04:05   Re: L4D2 How to add hint text
Reply With Quote #6

The bugs with PrintHintText are entirely to do with your code, not the native. You're not checking to see if they're actually a tank, you're not checking alive state, you're not sending a blank hint on death to clear any existing data, etc.
__________________
thetwistedpanda is offline
SilentBr
Veteran Member
Join Date: Jan 2009
Old 09-13-2013 , 21:35   Re: L4D2 How to add hint text
Reply With Quote #7

Quote:
Originally Posted by thetwistedpanda View Post
The bugs with PrintHintText are entirely to do with your code, not the native. You're not checking to see if they're actually a tank, you're not checking alive state, you're not sending a blank hint on death to clear any existing data, etc.
I know the problem is my code. The problem is I don't know how to do those stuff.
SilentBr is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 09-13-2013 , 22:25   Re: L4D2 How to add hint text
Reply With Quote #8

i'm not aware about the best method to check if someone is a tank, but this will probably work:
Code:
#include <sourcemod>
#include <sdktools>

stock bool:IsPlayerTank(client){

	decl String:model[128];
	GetClientModel(client, model, 128);
	if(StrContains(model, "tank", false) != -1){

		return true;

	}
	return false;

}
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
SilentBr
Veteran Member
Join Date: Jan 2009
Old 09-14-2013 , 00:24   Re: L4D2 How to add hint text
Reply With Quote #9

Adding IsPlayerTank solved that bug, thank you bimbo.

But when another player is tank, the plugin stop showing the hint message. I need find a way to keep showing the hint when change the tank control (to another player or bot).

Last edited by SilentBr; 09-14-2013 at 00:25.
SilentBr is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 09-14-2013 , 01:34   Re: L4D2 How to add hint text
Reply With Quote #10

hey, bro, try this:
Code:
#include <sourcemod>
#include <sdktools>

#define g_iCvarHealth 22000
#define INFECTED 3

public OnPluginStart() { 
	HookEvent("tank_spawn", tank_spawn); 
	HookEvent("bot_player_replace", tank_spawn)
} 

public tank_spawn(Handle:event, const String:name[], bool:dontBroadcast) { 
	new userid = GetEventInt(event, "userid");
	new client = GetClientOfUserId(userid);
	if(IsPlayerTank(client)){

		CreateTimer(0.1, tmrHealth, userid);
		CreateTimer(0.5, tmrHint, userid, TIMER_REPEAT);

	}

} 

public Action:tmrHealth(Handle:timer, any:userid) {
	new client = GetClientOfUserId(userid);
	
	if (client && IsClientInGame(client)) 
		SetEntityHealth(client, g_iCvarHealth);
		
	return Plugin_Stop;
}

public Action:tmrHint(Handle:timer, any:userid) {
	new client = GetClientOfUserId(userid);
	
	if (IsValidClient(client) && IsPlayerAlive(client) && IsPlayerTank(client)) {
		new health = GetClientHealth(client);
		for (new i = 1; i <= MaxClients; i++)
			if (IsValidClient(i) && GetClientTeam(i) == INFECTED)
				PrintHintText(i, "TANK %N %d/%d", client, health, g_iCvarHealth);

		return Plugin_Continue;
	}
	
	return Plugin_Stop;
}

IsValidClient(client) {
	if(client <= 0 || client > MaxClients || !IsClientConnected(client))
		return false;

	return IsClientInGame(client);
}

stock bool:IsPlayerTank(client){

	decl String:model[128];
	GetClientModel(client, model, 128);
	if(StrContains(model, "tank", false) != -1){

		return true;

	}
	return false;

}
i'm not very used to the l4d2 dynamics, but this might(just might, not more than that) work.
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 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 23:34.


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