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

[ZR] I have questions. Weapon buy commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
farawayf
Senior Member
Join Date: Jan 2019
Old 01-27-2019 , 10:29   [ZR] I have questions. Weapon buy commands
Reply With Quote #1

Hi.
I make plugin for ZR mode with which players buy weapons through the chat commands. But I have a question. Due to the fact that I'm new to this, I want to know whether it is possible to load the server because of my plugin and maybe or somehow reduce the code itself without losing functionality.
PHP Code:
new Handle:smoke_limit INVALID_HANDLE;
new 
Handle:smoke_price INVALID_HANDLE;

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
MarkNativeAsOptional("ZR_IsClientZombie");
    return 
APLRes_Success;
}

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_smoke"Cmd_smoke"Buy weapon Smoke - VIP Only");
    
    
smoke_price CreateConVar("smoke_price""2000""Set price to Smoke"_true0.0true16000.0);
    
smoke_limit CreateConVar("smoke_limit""1""Set limit to Smoke"_true0.0true16000.0);
    
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("round_end"Event_RoundEnd);
    
HookEvent("player_spawn"Event_PlayerSpawn);
    
    for(new 
1<= MaxClientsi++)
    {
        if(
IsClientInGame(i)) OnClientPutInServer(i) && OnClientConnected(i);
    }
}

public 
void OnClientConnected(int client)
{
    
SmokeCounter[client] = 0;
}

public 
void OnClientPutInServer(int client)
{
    
SmokeCounter[client] = 0;
}

public 
Action Event_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    new 
client_id GetEventInt(event"userid");
    new 
client GetClientOfUserId(client_id);
    
    
SmokeCounter[client] = 0;
}

public 
Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    new 
client_id GetEventInt(event"userid");
    new 
client GetClientOfUserId(client_id);
    
    
SmokeCounter[client] = 0;
}

public 
Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    new 
client_id GetEventInt(event"userid");
    new 
client GetClientOfUserId(client_id);
    
    
SmokeCounter[client] = 0;
}

public 
Action:Cmd_smoke(clientarg)
{
    {
        if(
client == 0)
        {
            return 
Plugin_Handled;
        }
        
                new 
money GetEntProp(clientProp_Send"m_iAccount");
                new 
price GetConVarInt(smoke_price);
                    
                if(
money price)
                {
                    if (!
GetAdminFlag(GetUserAdmin(client), Admin_Reservation)) 
                    { 
                        
SendHudMessage(client3, -1.0, -0.60xFF0AFF000xFF0AFF0010.10.51.55.0,  "Only VIP's can buy smoke");
                        return 
Plugin_Handled;
                    }
                    if(
GetClientTeam(client) < 2)
                    {
                        
SendHudMessage(client3, -1.0, -0.60xFF00FF000xFF00FF00,10.10.51.55.0,  "You need to be in a team for buy weapons");
                        return 
Plugin_Handled;
                    }
                    if(!
IsPlayerAlive(client))
                    {
                        
SendHudMessage(client3, -1.0, -0.60xFF00FF000xFF00FF00,10.10.51.55.0,  "You need to be alive for buy weapons");
                        return 
Plugin_Handled;
                    }
                    if ((
GetFeatureStatus(FeatureType_Native"ZR_IsClientZombie") == FeatureStatus_Available) && ZR_IsClientZombie(client))
                    {
                           
SendHudMessage(client3, -1.0, -0.60xFF0000FF0xFF0000FF,10.10.51.55.0,  "You need to be human for buy weapons");
                        return 
Plugin_Handled;
                    }    
                    if(
GetConVarInt(smoke_limit) > && SmokeCounter[client] >= GetConVarInt(smoke_limit))
                    {
                        
SendHudMessage(client3, -1.0, -0.60xFF0000FF0xFF0000FF,10.10.51.55.0,  "You can't buy more smoke in this round");
                        
SendHudMessage(client4, -1.5, -0.60xFF00FF000xFF00FF00,10.10.51.54.0"Limit %i/%i",SmokeCounter[client],GetConVarInt(smoke_limit));
                        return 
Plugin_Handled;
                    }
                    
                       
SendHudMessage(client3, -1.0, -0.60xFF0080000xFF008000,10.10.51.54.0"You not have enough money Smoke price %i$"price);
                }
                if (
money price)
                {    
                    if (!
GetAdminFlag(GetUserAdmin(client), Admin_Reservation)) 
                    { 
                        
SendHudMessage(client3, -1.0, -0.60xFF0AFF000xFF0AFF00,10.10.51.55.0,  "Only VIP's can buy smoke");
                        return 
Plugin_Handled;
                    }
                    if(
GetClientTeam(client) < 2)
                    {
                        
SendHudMessage(client3, -1.0, -0.60xFF00FF000xFF00FF00,10.10.51.55.0,  "You need to be in a team for buy weapons");
                        return 
Plugin_Handled;
                    }
                    if(!
IsPlayerAlive(client))
                    {
                        
SendHudMessage(client3, -1.0, -0.60xFF00FF000xFF00FF00,10.10.51.55.0,  "You need to be alive for buy weapons");
                        return 
Plugin_Handled;
                    }
                    if ((
GetFeatureStatus(FeatureType_Native"ZR_IsClientZombie") == FeatureStatus_Available) && ZR_IsClientZombie(client))
                    {
                           
SendHudMessage(client3, -1.0, -0.60xFF0000FF0xFF0000FF,10.10.51.55.0"You need to be human for buy weapons");
                        return 
Plugin_Handled;
                    }    
                    
                    if(
GetConVarInt(smoke_limit) > && SmokeCounter[client] >= GetConVarInt(smoke_limit))
                    {
                        
SendHudMessage(client3, -1.0, -0.60xFF0000FF0xFF0000FF,10.10.51.55.0,  "You can't buy more Smoke in this round - Limit %i/%i",SmokeCounter[client],GetConVarInt(smoke_limit));
                        return 
Plugin_Handled;
                    }
                    
                    new 
mb money price;        
                
                    
SetEntProp(clientProp_Send"m_iAccount"mb);
                    
                    
GivePlayerItem(client"weapon_smokegrenade");
                    
SendHudMessage(client3, -1.0, -0.60x00FF00000x00FF0000,10.10.51.54.0"You have purchased SMOKE");
                    
CounterSmoke[client]++;
                    
SendHudMessage(client4, -0.5, -0.40xFF00FF000xFF00FF00,10.10.51.54.0"Limit %i/%i",SmokeCounter[client],GetConVarInt(smoke_limit));
                }
    }
    return 
Plugin_Handled;        


Last edited by farawayf; 01-27-2019 at 10:40.
farawayf is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 01-28-2019 , 05:37   Re: [ZR] I have questions. Weapon buy commands
Reply With Quote #2

do not know what you want help with...
__________________
8guawong is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 01-28-2019 , 06:44   Re: [ZR] I have questions. Weapon buy commands
Reply With Quote #3

Quote:
Originally Posted by 8guawong View Post
do not know what you want help with...
It seems to me that because of my plugin server using half RAM memory. Is it possible to reduce the load by shortening the code. If yes how ?

Last edited by farawayf; 01-28-2019 at 06:45.
farawayf is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 01-28-2019 , 07:09   Re: [ZR] I have questions. Weapon buy commands
Reply With Quote #4

Quote:
Originally Posted by farawayf View Post
It seems to me that because of my plugin server using half RAM memory. Is it possible to reduce the load by shortening the code. If yes how ?
Is it any different if you disable the plugin?
CliptonHeist is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 01-28-2019 , 07:19   Re: [ZR] I have questions. Weapon buy commands
Reply With Quote #5

Quote:
Originally Posted by CliptonHeist View Post
Is it any different if you disable the plugin?
yes. less memory using.
farawayf is offline
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 01-28-2019 , 07:41   Re: [ZR] I have questions. Weapon buy commands
Reply With Quote #6

My plugin already include the function that you want, but checking your code seems that you used part of my code.

How much RAM your server have? You checking sm_dump_handles to be sure what plugin use more memory? Also you didnt paste all the code.
__________________
Veteran Coder -> Activity channel
Coding on CS2 and taking paid and free jobs.

Contact: Steam, Telegram or discord ( franug ).

You like my work? +Rep in my steam profile comments or donate.

Franc1sco is offline
Send a message via MSN to Franc1sco
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 01-28-2019 , 07:49   Re: [ZR] I have questions. Weapon buy commands
Reply With Quote #7

Quote:
Originally Posted by farawayf View Post
yes. less memory using.
Alright by how much? Plugins really shouldn't use much memory at all unless they have a memory leak. In any case you can optimize your plugin a bit by removing the round_start and round_end events since they don't even contain a userid parameter. Remove the for loop in plugin start and both the OnClientConnected() and OnClientPutInServer() forwards since they're redundant if you're also setting the SmokeCounter to 0 on player spawn.

Last edited by CliptonHeist; 01-28-2019 at 07:50. Reason: English bad
CliptonHeist is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 01-28-2019 , 08:01   Re: [ZR] I have questions. Weapon buy commands
Reply With Quote #8

Quote:
Originally Posted by Franc1sco View Post
My plugin already include the function that you want, but checking your code seems that you used part of my code.

How much RAM your server have? You checking sm_dump_handles to be sure what plugin use more memory? Also you didnt paste all the code.
I did not think that you will answer.

Yes. I searched how to check if player is zombie and i find it in ur plugin.

Your plugin is great, but does not support chat commands via "/" like "/awp etc" and sm commands.
Because of the many events in our server, I needed to put cvars to change the price and limit without editing the cfg file.

i7, 4 Cores, 8 threads at 4.4/4.7 ghz.
That's all the information I could find on the host. There is no specified how much ram, only percent usage.
I’ll check sm_dump_handles and write as soon as I can

Last edited by farawayf; 01-28-2019 at 08:05.
farawayf is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 01-28-2019 , 08:32   Re: [ZR] I have questions. Weapon buy commands
Reply With Quote #9

I did not find the name of my plugin in list. But I found one plugin named NONE using 71406 memory with type Trie.
farawayf 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 18:28.


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