Raised This Month: $ Target: $400
 0% 

[CSGO] Plugin Idea.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
FaTony
Veteran Member
Join Date: Aug 2008
Old 10-25-2012 , 07:16   Re: [CSGO] Plugin Idea.
Reply With Quote #11

Work in progress:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

#define PLUGIN_VERSION "dev"
#define DEFAULT_RESPAWNWAVE_TIME 10
#define RESPAWNWAVE_TIMER_INTERVAL 1.0
#define RESPAWNWAVE_TIMER_FLAGS TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE

public Plugin:myinfo =
{
    
name "CSS Respawn waves",
    
author "FaTony",
    
description "...",
    
version PLUGIN_VERSION,
    
url "http://fatony.com/"
};

static 
Handle:RespawnWaveTimer INVALID_HANDLE;
static 
Handle:RespawnWaveCvarT INVALID_HANDLE;
static 
Handle:RespawnWaveCvarCT INVALID_HANDLE;
static 
RespawnWaveTimeT DEFAULT_RESPAWNWAVE_TIME;
static 
RespawnWaveTimeCT DEFAULT_RESPAWNWAVE_TIME;
static 
RespawnWaveCurrentTimeT 1;
static 
RespawnWaveCurrentTimeCT 1;
static 
PlayerRespawnTime[MAXPLAYERS 1];

public 
OnPluginStart()
{
    
RespawnWave_Init();
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("round_end"Event_RoundEnd);
    
HookEvent("player_death"Event_PlayerDeath);
}

public 
OnMapEnd()
{
    
RespawnWave_EndTimer();
}

public 
Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    if ((
GetTeamClientCount(CS_TEAM_T) == 0) && (GetTeamClientCount(CS_TEAM_CT) == 0))
    {
        return 
Plugin_Continue;
    }
    
RespawnWave_StartTimer();
    return 
Plugin_Continue;
}

public 
Action:Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    
RespawnWave_EndTimer();
}

public 
Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
RespawnWave_SetupClient(client);
}

RespawnWave_Init()
{
    
RespawnWaveCvarT CreateConVar("ftz_respawnwavetime_t""10""The delay between terrorist respawn waves in seconds."0true0.0);
    
HookConVarChange(RespawnWaveCvarTRespawnWave_TimeChanged);
    
RespawnWaveCvarCT CreateConVar("ftz_respawnwavetime_ct""10""The delay between counter-terrorist respawn waves in seconds."0true0.0);
    
HookConVarChange(RespawnWaveCvarCTRespawnWave_TimeChanged);
}

public 
RespawnWave_TimeChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
    if (
convar == RespawnWaveCvarT)
    {
        
RespawnWaveTimeT GetConVarInt(convar);
    }
    else if (
convar == RespawnWaveCvarCT)
    {
        
RespawnWaveTimeCT GetConVarInt(convar);
    }
}

RespawnWave_StartTimer()
{
    if (
RespawnWaveTimer != INVALID_HANDLE)
    {
        
LogError("RespawnWave_StartTimer called when timer is still running.");
        
CloseHandle(RespawnWaveTimer);
    }
    
RespawnWaveTimer CreateTimer(RESPAWNWAVE_TIMER_INTERVALRespawnWave_TimerCallback_RESPAWNWAVE_TIMER_FLAGS);
}

RespawnWave_EndTimer()
{
    if (
RespawnWaveTimer == INVALID_HANDLE)
    {
        return;
    }
    
CloseHandle(RespawnWaveTimer);
    
RespawnWaveTimer INVALID_HANDLE;
}

RespawnWave_SetupClient(const client)
{
    switch (
GetClientTeam(client))
    {
        case 
CS_TEAM_T:
        {
            
PlayerRespawnTime[client] = RespawnWaveTimeT RespawnWaveCurrentTimeT;
        }
        case 
CS_TEAM_CT:
        {
            
PlayerRespawnTime[client] = RespawnWaveTimeCT RespawnWaveCurrentTimeCT;
        }
    }
}

public 
Action:RespawnWave_TimerCallback(Handle:timer)
{
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && (GetClientTeam(i) > CS_TEAM_SPECTATOR) && (!IsPlayerAlive(i)))
        {
            if (
PlayerRespawnTime[i] > 0)
            {
                
PlayerRespawnTime[i]--;
            }
            if (
PlayerRespawnTime[i] > 0)
            {
                
PrintCenterText(i"You will respawn in %d."PlayerRespawnTime[i]);
            }
            else
            {
                
CS_RespawnPlayer(i);
            }
        }
    }
    
RespawnWaveCurrentTimeT--;
    if (
RespawnWaveCurrentTimeT == 0)
    {
        
RespawnWaveCurrentTimeT RespawnWaveTimeT;
    }
    
RespawnWaveCurrentTimeCT--;
    if (
RespawnWaveCurrentTimeCT == 0)
    {
        
RespawnWaveCurrentTimeCT RespawnWaveTimeCT;
    }

PHP Code:
#include <sourcemod>
#include <smlib/clients>

#define PLUGIN_VERSION "dev"

#define MAX_CLIENT_WEAPONS 5

public Plugin:myinfo =
{
    
name "CSS Weapon saving",
    
author "FaTony",
    
description "...",
    
version PLUGIN_VERSION,
    
url "http://fatony.com/"
};

new 
bool:ShouldRestoreWeapons[MAXPLAYERS 1];
new 
String:ClientWeapons[MAXPLAYERS 1][MAX_CLIENT_WEAPONS][MAX_WEAPON_STRING];

public 
OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawn);
    
HookEvent("player_hurt"Event_PlayerHurt);
    
AddCommandListener(Command_Suicide"kill");
    
AddCommandListener(Command_Suicide"explode");
}

public 
OnClientDisconnect(client)
{
    
ClearClientWeapons(client)
}

public 
Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
RestoreClientWeapons(client);
}

public 
Action:Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
victim GetClientOfUserId(GetEventInt(event"userid"));
    new 
victimhealth GetClientHealth(victim);
    if (
victimhealth <= 0)
    {
        
SaveClientWeapons(victim);
    }
}

public 
Action:Command_Suicide(client, const String:command[], argc)
{
    if ((
client <= 0) || (client MaxClients))
    {
        return 
Plugin_Continue;
    }
    if (
IsPlayerAlive(client))
    {
        
SaveClientWeapons(client);
    }
    return 
Plugin_Continue;
}

SaveClientWeapons(const client)
{
    
ShouldRestoreWeapons[client] = true;
    new 
weapon;
    
decl String:weaponclassname[MAX_WEAPON_STRING];
    new 
0;
    for (new 
0offset Client_GetWeaponsOffset(client); MAX_WEAPONSi++, offset += 4)
    {
        
weapon GetEntDataEnt2(clientoffset);
        if (!
Weapon_IsValid(weapon))
        {
            break;
        }
        
GetEdictClassname(weaponweaponclassnameMAX_WEAPON_STRING);
        if ((!
StrEqual(weaponclassname"weapon_knife")) && (!StrEqual(weaponclassname"weapon_c4")))
        {
            
strcopy(ClientWeapons[client][j], MAX_WEAPON_STRINGweaponclassname);
            
j++;
            if (
== MAX_CLIENT_WEAPONS)
            {
                return;
            }
        }
    }
    
ClientWeapons[client][j][0] = '\0';
}

RestoreClientWeapons(const client)
{
    for (new 
0MAX_CLIENT_WEAPONSi++)
    {
        if (
ClientWeapons[client][i][0] == '\0')
        {
            return;
        }
        
Client_GiveWeapon(clientClientWeapons[client][i], false);
    }
    
ShouldRestoreWeapons[client] = false;
}

ClearClientWeapons(const client)
{
    for (new 
0MAX_CLIENT_WEAPONSi++)
    {
        
ShouldRestoreWeapons[client] = false;
        
ClientWeapons[client][i][0] = '\0';
    }

__________________
FaTony is offline
 



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 01:37.


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