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

Storing a variable for each player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exanero
Junior Member
Join Date: Dec 2018
Old 01-07-2019 , 10:02   Storing a variable for each player
Reply With Quote #1

Hi!
I'm making a vip plugin for my community and in there i want to have so each VIP player can respawn/heal only 3 times per round. I have gotten it to work the way i wanted with resets each round and all. BUT it's global. So if player 1 uses heal then player 2 only has 2 left ect. I want it to be 3 heals for each player and not for every player together.

So my question is: How can i store a variable for each player?

Example bit of my code (Stitched together, not actual layout)
Code:
new uRes, uHeal;

public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast) 
{ 
	uRes = 0;
	uHeal = 0;
} 

else if (uHeal == 2) 
{
	PrintToChat(param1, "Fullt HP (3/3)");
	SetEntityHealth(param1, 100);
					
	uHeal++;
}
	else if (uHeal == 3) 
{
	PrintToChat(param1, "You've used all your heals!");
}

Last edited by Exanero; 01-07-2019 at 10:03.
Exanero is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 01-07-2019 , 10:40   Re: Storing a variable for each player
Reply With Quote #2

I don't have any knowlage in tf2 plugins but this should work:

PHP Code:
int g_iHeals[MAXPLAYERS 1];
int g_iRespawns[MAXPLAYERS 1];

public 
void OnClientPutInServerint Client
{
if(
bIsVip//here you have to make a check
{
g_iHeals[iClient] = 3;
g_iRespawns[iClient] =3;


else{
g_iHeals[iClient] = 0;
g_iRespawns[iClient]  =0;
{



public 
Action OnRoundStart(handle the event
{
if(
bIsVip//here you have to make a check
{
g_iHeals[iClient] = 3;
g_iRespawns[iClient] =3;



public 
Action Cmd_Heal(int iClientint iArgs
{
if(
g_iHeal 0
{
SetEntityHealth(iClient100);
g_iHeal[iClient]--;



I wrote this on phone and the code is very messy but I hope you will understand what you need
__________________

Last edited by kratoss1812; 01-07-2019 at 10:41.
kratoss1812 is offline
Exanero
Junior Member
Join Date: Dec 2018
Old 01-07-2019 , 11:11   Re: Storing a variable for each player
Reply With Quote #3

Well that seems to work only i get "undefined symbol "client"".

I can't seem to figure out why, if it's a spelling error or similar?
Exanero is offline
ofir753
Senior Member
Join Date: Aug 2012
Old 01-07-2019 , 12:48   Re: Storing a variable for each player
Reply With Quote #4

Learn about arrays and look for examples later.
ofir753 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-08-2019 , 10:45   Re: Storing a variable for each player
Reply With Quote #5

You create global array, loop array indexs on round start.

PHP Code:
    
    
// global array
int g_iPlayerRespawns[MAXPLAYERS+1];
    

public 
void OnPluginStart()
{
    
HookEvent("round_start"round_start);
    
RegConsoleCmd("sm_spawn"sm_spawn);
}

public 
void round_start(Handle event, const char[] namebool dontBroadcast)

    for(
int index 1index <= MaxClientsindex++)
    {
        
g_iPlayerRespawns[index] = 0;
    }




public 
Action sm_spawn(int clientint args)
{

    if(
client == || !IsClientInGame(client) || GetClientTeam(client) <= 1) return Plugin_Handled;



    if(
g_iPlayerRespawns[client] == 2)
    {
        
PrintToChat("[SM] You use all respawns");
        return 
Plugin_Handled;
    }


    
// Do respawns
    
    
g_iPlayerRespawns[client]++;
    

    return 
Plugin_Handled;

__________________
Do not Private Message @me
Bacardi 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 17:43.


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