View Single Post
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 05-15-2018 , 07:53   Re: deathmatch (5 minutes =ak, 10 minutes = awp, 15 minutes = usp)
Reply With Quote #4

Quote:
Originally Posted by LenHard View Post
PHP Code:
#include <sourcemod>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls required

int gI_Weapon 0;

public 
void OnMapStart()
{
    
gI_Weapon 0;
    
CreateTimer(300.0Timer_RepeatINVALID_HANDLETIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);    
}

public 
void OnClientPutInServer(int client)
{
    if (!
IsFakeClient(client)) {
        
SDKHook(clientSDKHook_WeaponCanUseOnWeaponDecideUse);
    }
}

public 
Action Timer_Repeat(Handle hTimer)
{
    ++
gI_Weapon;
}

public 
Action OnWeaponDecideUse(int clientint iWeapon)
{
    if (
IsValidEdict(iWeapon) && IsClientInGame(client))
    {
        
char[] sWeapon = new char[32];
        
GetEdictClassname(iWeaponsWeapon32);
        
        switch (
gI_Weapon)
        {
            case 
1// Ak only
            
{
                if (
sWeapon[7] != 'a' && sWeapon[8] != 'k')
                    return 
Plugin_Handled;
            }
            case 
2// Next weapon
            
{
                
// etc...    
            
}
        }
    }
    return 
Plugin_Continue;

This is what you requested?
You have the right idea but I see a lot of things wrong with your code.

Here are some notes about your code that you should take in:

1. If you're not passing any data on a timer handle, you don't need to put "INVALID_HANDLE" in there. Just simply use an underscore like this: CreateTimer(1.0, Timer_Callback, _, TIMER_REPEAT);
2. ++i is equivalent to i + 2. You should be using i++ instead.
3. Change the following:

PHP Code:
char[] sWeapon = new char[32];
GetEdictClassname(iWeaponsWeapon32); 
To the following:

PHP Code:
char sWeapon[32];
GetEdictClassname(iWeaponsWeaponsizeof(sWeapon)); 
4. You already assigned "g_iWeapon" to 0 in your global declaration. No need to do it again on OnMapStart(). Also, simply declaring it as "int g_iWeapon;" is basically saying that it's already 0.
5. You can make the following a lot easier by changing it from:

PHP Code:
if (sWeapon[7] != 'a' && sWeapon[8] != 'k'
To the following:

PHP Code:
if (StrContains(sWeapon"ak47"false) != -1
Here's my revision:

PHP Code:
#include <sourcemod>
#include <sdkhooks>
#pragma semicolon 1
#pragma newdecls required

int g_iWeapon;

public 
void OnMapStart()
{
    
g_iWeapon 0;
    
CreateTimer(300.0TimerChangeWeapon_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);    
}

public 
void OnClientPutInServer(int client)
{
    if (
IsValidClient(client))
    {
        
SDKHook(clientSDKHook_WeaponCanUseOnWeaponUse);
    }
}

public 
Action TimerChangeWeapon(Handle timer)
{
    
g_iWeapon++;
}

public 
Action OnWeaponUse(int clientint weapon)
{
    if (
IsValidClient(client))
    {
        
char sWeapon[32];
        
GetEdictClassname(weaponsWeaponsizeof(sWeapon));
        switch (
g_iWeapon)
        {
            case 
1// Ak only
            
{
                if (
StrContains(sWeapon"ak47"false) != -1)
                {
                    return 
Plugin_Handled;
                }
            }
            case 
2// Next weapon
            
{
                
// etc...    
            
}
        }
    }
    return 
Plugin_Continue;
}

stock bool IsValidClient(int client)
{
    return (
client && client <= MaxClients && IsClientInGame(client) && !IsClientInKickQueue(client) && IsPlayerAlive(client) && !IsFakeClient(client));

__________________
Psyk0tik is offline