AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Storing a variable for each player (https://forums.alliedmods.net/showthread.php?t=313381)

Exanero 01-07-2019 10:02

Storing a variable for each player
 
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!");
}


kratoss1812 01-07-2019 10:40

Re: Storing a variable for each player
 
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

Exanero 01-07-2019 11:11

Re: Storing a variable for each player
 
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?

ofir753 01-07-2019 12:48

Re: Storing a variable for each player
 
Learn about arrays and look for examples later.

Bacardi 01-08-2019 10:45

Re: Storing a variable for each player
 
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;




All times are GMT -4. The time now is 12:59.

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