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

Solved Revive Chance plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
r14170
Veteran Member
Join Date: Dec 2009
Old 03-08-2023 , 00:05   Revive Chance plugin
Reply With Quote #1

Hi there.

I searched for some revive plugins but all of them are very different from what Im looking for.

Im looking for a plugin which gives everyone 5% chance to be revived after they type "!reviveme" or "/reviveme" or "reviveme"

It can be only used by dead players and only once per round.

I would be very grateful if someone can help.

Thank you!

Last edited by r14170; 03-08-2023 at 02:47.
r14170 is offline
AePT
Member
Join Date: Jan 2016
Old 03-08-2023 , 00:52   Re: Revive Chance plugin
Reply With Quote #2

Try it

PHP Code:
#include <cstrike>

#pragma newdecls required
#pragma semicolon 1

public Plugin myinfo =
{
    
name                "[Any] Lucky Respawn",
    
author            "AePT",
    
description "Gives players a chance to respawn.",
    
version            "1.0.0"
};

#define RESPAWN_CHANCE 5

bool g_already_used[MAXPLAYERS 1] = { false, ... };

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_reviveme"CMD_LuckyRespawn);
    
HookEvent("round_start"Hook_RoundStart);
}

public 
void Hook_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    for (
int i 1<= MaxClientsi++)
    {
        if (!
IsClientInGame(i))
        {
            continue;
        }

        
g_already_used[i] = false;
    }
}

public 
Action CMD_LuckyRespawn(int clientint args)
{
    if (
IsPlayerAlive(client))
    {
        
PrintToChat(client"Only dead players can use this command.");
        return 
Plugin_Handled;
    }

    if (
g_already_used[client])
    {
        
PrintToChat(client"You already tried lucky respawning this round.");
        return 
Plugin_Handled;
    }

    
g_already_used[client] = true;

    if (
GetRandomInt(0100) <= RESPAWN_CHANCE)
    {
        
CS_RespawnPlayer(client);
        
PrintToChat(client"You have revived with a %d%% chance!"RESPAWN_CHANCE);
    }
    else
    {
        
PrintToChat(client"No luck, try the next round. :(");
    }

    return 
Plugin_Handled;

AePT is offline
r14170
Veteran Member
Join Date: Dec 2009
Old 03-08-2023 , 02:15   Re: Revive Chance plugin
Reply With Quote #3

Hey! Thanks for the quick reply!

Works like a charm!

I really appreciate your help!

Is it possible to also check if the round has ended and if it has, the function would not be available? Like, lets say all people die and the round ends - when somebody types /reviveme - it wouldnt be possible to be respawned.

Last edited by r14170; 03-08-2023 at 02:16.
r14170 is offline
AePT
Member
Join Date: Jan 2016
Old 03-08-2023 , 02:28   Re: Revive Chance plugin
Reply With Quote #4

Quote:
Originally Posted by r14170 View Post
Hey! Thanks for the quick reply!

Works like a charm!

I really appreciate your help!

Is it possible to also check if the round has ended and if it has, the function would not be available? Like, lets say all people die and the round ends - when somebody types /reviveme - it wouldnt be possible to be respawned.


PHP Code:
#include <cstrike>

#pragma newdecls required
#pragma semicolon 1

public Plugin myinfo =
{
    
name                "[Any] Lucky Respawn",
    
author            "AePT",
    
description "Gives players a chance to respawn.",
    
version            "1.0.1"
};

#define RESPAWN_CHANCE 5

bool g_round_ended                                    false;
bool g_already_used[MAXPLAYERS 1] = { false, ... };

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_reviveme"CMD_LuckyRespawn);
    
HookEvent("round_start"Hook_RoundStart);
    
HookEvent("round_end"Hook_RoundEnd);
}

public 
void Hook_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    
g_round_ended false;

    for (
int i 1<= MaxClientsi++)
    {
        if (!
IsClientInGame(i))
        {
            continue;
        }

        
g_already_used[i] = false;
    }
}

public 
void Hook_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    
g_round_ended true;
}

public 
Action CMD_LuckyRespawn(int clientint args)
{
    if (
IsPlayerAlive(client))
    {
        
PrintToChat(client"Only dead players can use this command.");
        return 
Plugin_Handled;
    }

    if (
g_round_ended)
    {
        
PrintToChat(client"The round is over, you can't use this command.");
        return 
Plugin_Handled;
    }

    if (
g_already_used[client])
    {
        
PrintToChat(client"You already tried lucky respawning this round.");
        return 
Plugin_Handled;
    }

    
g_already_used[client] = true;

    if (
GetRandomInt(0100) <= RESPAWN_CHANCE)
    {
        
CS_RespawnPlayer(client);
        
PrintToChat(client"You have revived with a %d%% chance!"RESPAWN_CHANCE);
    }
    else
    {
        
PrintToChat(client"No luck, try the next round. :(");
    }

    return 
Plugin_Handled;

AePT is offline
r14170
Veteran Member
Join Date: Dec 2009
Old 03-08-2023 , 02:41   Re: Revive Chance plugin
Reply With Quote #5

You are awesome!

I really really appreciate your help!
r14170 is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 03-08-2023 , 06:41   Re: Revive Chance plugin
Reply With Quote #6

AePT, in this form it will be a little better:
PHP Code:
#pragma newdecls required
#pragma semicolon 1

#include <cstrike>

#define RESPAWN_CHANCE    5

public Plugin myinfo =
{
    
name        "[Any] Lucky Respawn",
    
author        "AePT",
    
description "Gives players a chance to respawn.",
    
version        "1.0.1_fix"
}

bool
    g_round_ended
,
    
g_already_used[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
HookEvent("round_freeze_end"Event_RoundEventHookMode_PostNoCopy);
    
HookEvent("round_end"Event_RoundEventHookMode_PostNoCopy);

    
RegConsoleCmd("sm_reviveme"CMD_LuckyRespawn);
}

public 
void Event_Round(Event event, const char[] namebool dontBroadcast)
{
    if((
g_round_ended name[6] == 'e')) for(int i 1<= MaxClientsi++) g_already_used[i] = false;
}

public 
Action CMD_LuckyRespawn(int clientint args)
{
    if(!
client || GetClientTeam(client) < CS_TEAM_T)    // neither server nor spectators are allowed
        
return Plugin_Handled;

    if(
IsPlayerAlive(client))
    {
        
PrintToChat(client"Only dead players can use this command.");
        return 
Plugin_Handled;
    }

    if(
g_round_ended)
    {
        
PrintToChat(client"The round is over, you can't use this command.");
        return 
Plugin_Handled;
    }

    if(
g_already_used[client])
    {
        
PrintToChat(client"You already tried lucky respawning this round.");
        return 
Plugin_Handled;
    }

    
g_already_used[client] = true;

    if(
GetRandomInt(1100) <= RESPAWN_CHANCE)
    {
        
CS_RespawnPlayer(client);
        
PrintToChat(client"You have revived with a %d%% chance!"RESPAWN_CHANCE);
    }
    else 
PrintToChat(client"No luck, try the next round. :(");

    return 
Plugin_Handled;

__________________

Last edited by Grey83; 03-08-2023 at 16:22.
Grey83 is offline
r14170
Veteran Member
Join Date: Dec 2009
Old 03-08-2023 , 11:27   Re: Revive Chance plugin
Reply With Quote #7

Hey! Thanks for the update.

I believe it fixes a potential problem where only 1 player was able to use the revive me and it disables it for everyone?

Havent tested it yet, will do in a bit!
r14170 is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 03-08-2023 , 12:09   Re: Revive Chance plugin
Reply With Quote #8

Quote:
Originally Posted by r14170 View Post
I believe it fixes a potential problem where only 1 player was able to use the revive me and it disables it for everyone?
I have no idea about this
__________________
Grey83 is offline
AePT
Member
Join Date: Jan 2016
Old 03-08-2023 , 12:28   Re: Revive Chance plugin
Reply With Quote #9

Quote:
Originally Posted by Grey83 View Post
AePT, in this form it will be a little better:
Thank you for the update, I appreciate it
AePT is offline
r14170
Veteran Member
Join Date: Dec 2009
Old 03-08-2023 , 14:25   Re: Revive Chance plugin
Reply With Quote #10

Im struggling to undestand how does this line work exactly:

Code:
    if(!client || GetClientTeam(client) < CS_TEAM_T)    // neither server nor spectators are allowed
        return Plugin_Handled;
Does this mean that CS_TEAM_NONE and CS_TEAM_SPECTATOR are ignored?

also I think there is a mistype here:

Code:
 HookEvent("round_freze_end", Event_Round, EventHookMode_PostNoCopy);
I changed it to round_freeze_end so it can work.

Either way, thank you very much for this, really appreciate it!

Last edited by r14170; 03-08-2023 at 14:26.
r14170 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 14:16.


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