Raised This Month: $32 Target: $400
 8% 

Help with zr plugin!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
comp
Junior Member
Join Date: Apr 2021
Old 04-24-2021 , 23:57   Help with zr plugin!
Reply With Quote #1

/* SM Buy weapons by commands
*
*
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/.
*/

#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#undef REQUIRE_PLUGIN
#include <zombiereloaded>

#pragma newdecls required

#define DATA "2.2"

char sConfig[PLATFORM_MAX_PATH];
Handle kv, trie_weapons[MAXPLAYERS + 1];

public Plugin myinfo =
{
name = "SM Buy weapons by commands",
description = "",
author = "comp",
version = DATA,
url = ""
};

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
MarkNativeAsOptional("ZR_IsClientZombie");
return APLRes_Success;
}

public void OnPluginStart()
{
CreateConVar("sm_buybycommands_version", DATA, "", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
AddCommandListener(SayC, "say");
AddCommandListener(SayC, "say_team");

HookEvent("player_spawn", PlayerSpawn);

for(int client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client))
{
OnClientConnected(client);
}
}
}

public Action PlayerSpawn(Handle event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));

ClearTrie(trie_weapons[client]);
}

public void OnClientConnected(int client)
{
trie_weapons[client] = CreateTrie();
}

public void OnClientDisconnect(int client)
{
if(trie_weapons[client] != INVALID_HANDLE) CloseHandle(trie_weapons[client]);
}

public void OnMapStart()
{
RefreshKV();
}

public void RefreshKV()
{
BuildPath(Path_SM, sConfig, PLATFORM_MAX_PATH, "configs/franug_buybycommands.txt");

if(kv != INVALID_HANDLE) CloseHandle(kv);

kv = CreateKeyValues("BuyCommands");
FileToKeyValues(kv, sConfig);
}

public Action SayC(int client, const char[] command, int args)
{
if (!IsValidClient(client))return;

char buffer[255];
GetCmdArgString(buffer,sizeof(buffer));
StripQuotes(buffer);

if (strlen(buffer) < 1)return;

if (kv == INVALID_HANDLE)RefreshKV();

KvRewind(kv);
if (!KvJumpToKey(kv, buffer))return;

char flags[24];
KvGetString(kv, "flags", flags, sizeof(flags), "public");

if(!StrEqual(flags, "public", false) && !CheckAdminFlagsByString(client, flags))
{
PrintToChat(client, " \x04You dont have access to buy this weapon");
return;
}

int money = GetEntProp(client, Prop_Send, "m_iAccount");
int cost = KvGetNum(kv, "price");

if(money >= cost)
{
if(GetClientTeam(client) < 2)
{
PrintToChat(client, " \x04You need to be in a team for buy weapons");
return;
}
if(!IsPlayerAlive(client))
{
PrintToChat(client, " \x04You need to be alive for buy weapons");
return;
}
if ((GetFeatureStatus(FeatureType_Native, "ZR_IsClientZombie") == FeatureStatus_Available) && ZR_IsClientZombie(client))
{
PrintToChat(client, " \x04You need to be human for buy weapons");
return;
}

char weapons[64];
KvGetString(kv, "weapon", weapons, 64);
int times = KvGetNum(kv, "times");
int current;

if(times == 0)
{
int drop = KvGetNum(kv, "slot", -1);
if(drop != -1)
{
int weapon = GetPlayerWeaponSlot(client, drop);
if(weapon != -1) SDKHooks_DropWeapon(client, weapon);
}

GivePlayerItem(client, weapons);
SetEntProp(client, Prop_Send, "m_iAccount", money-cost);
ReplaceString(weapons, sizeof(weapons), "weapon_", "");
PrintToChat(client, " \x04You have bought a %s", weapons);
return;
}

if (!GetTrieValue(trie_weapons[client], weapons, current))current = 0;

if(times <= current)
{
PrintToChat(client, " \x04You cant buy more %s this round", weapons);
return;

}
SetTrieValue(trie_weapons[client], weapons, ++current);

int drop = KvGetNum(kv, "slot", -1);
if(drop != -1)
{
int weapon = GetPlayerWeaponSlot(client, drop);
if(weapon != -1) SDKHooks_DropWeapon(client, weapon);
}

GivePlayerItem(client, weapons);
SetEntProp(client, Prop_Send, "m_iAccount", money-cost);
ReplaceString(weapons, sizeof(weapons), "weapon_", "");

PrintToChat(client, " \x04You have bought a %s %i/%i", weapons, current, times);
}
else PrintToChat(client, " \x04You dont have enought money. You need %i", cost);

}

stock bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
{
if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
{
return false;
}
return true;
}

stock bool CheckAdminFlagsByString(int client, const char[] flagString)
{
AdminId admin = view_as<AdminId>(GetUserAdmin(client));
if (admin != INVALID_ADMIN_ID){
int count, found, flags = ReadFlagString(flagString);
for (int i = 0; i <= 20; i++){
if (flags & (1<<i))
{
count++;

if(GetAdminFlag(admin, view_as<AdminFlag>(i))){
found++;
}
}
}

if (count == found || GetUserFlagBits(client) & ADMFLAG_ROOT){
return true;
}
}

return false;
}







Can someone make this code so you can buy weapons and items like kevlar & vest and kevlar?
My regards
comp is offline
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 04-25-2021 , 07:11   Re: Help with zr plugin!
Reply With Quote #2

Quote:
Originally Posted by comp View Post
/* SM Buy weapons by commands
*
*
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/.
*/

#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#undef REQUIRE_PLUGIN
#include <zombiereloaded>

#pragma newdecls required

#define DATA "2.2"

char sConfig[PLATFORM_MAX_PATH];
Handle kv, trie_weapons[MAXPLAYERS + 1];

public Plugin myinfo =
{
name = "SM Buy weapons by commands",
description = "",
author = "comp",
version = DATA,
url = ""
};

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
MarkNativeAsOptional("ZR_IsClientZombie");
return APLRes_Success;
}

public void OnPluginStart()
{
CreateConVar("sm_buybycommands_version", DATA, "", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
AddCommandListener(SayC, "say");
AddCommandListener(SayC, "say_team");

HookEvent("player_spawn", PlayerSpawn);

for(int client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client))
{
OnClientConnected(client);
}
}
}

public Action PlayerSpawn(Handle event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));

ClearTrie(trie_weapons[client]);
}

public void OnClientConnected(int client)
{
trie_weapons[client] = CreateTrie();
}

public void OnClientDisconnect(int client)
{
if(trie_weapons[client] != INVALID_HANDLE) CloseHandle(trie_weapons[client]);
}

public void OnMapStart()
{
RefreshKV();
}

public void RefreshKV()
{
BuildPath(Path_SM, sConfig, PLATFORM_MAX_PATH, "configs/franug_buybycommands.txt");

if(kv != INVALID_HANDLE) CloseHandle(kv);

kv = CreateKeyValues("BuyCommands");
FileToKeyValues(kv, sConfig);
}

public Action SayC(int client, const char[] command, int args)
{
if (!IsValidClient(client))return;

char buffer[255];
GetCmdArgString(buffer,sizeof(buffer));
StripQuotes(buffer);

if (strlen(buffer) < 1)return;

if (kv == INVALID_HANDLE)RefreshKV();

KvRewind(kv);
if (!KvJumpToKey(kv, buffer))return;

char flags[24];
KvGetString(kv, "flags", flags, sizeof(flags), "public");

if(!StrEqual(flags, "public", false) && !CheckAdminFlagsByString(client, flags))
{
PrintToChat(client, " \x04You dont have access to buy this weapon");
return;
}

int money = GetEntProp(client, Prop_Send, "m_iAccount");
int cost = KvGetNum(kv, "price");

if(money >= cost)
{
if(GetClientTeam(client) < 2)
{
PrintToChat(client, " \x04You need to be in a team for buy weapons");
return;
}
if(!IsPlayerAlive(client))
{
PrintToChat(client, " \x04You need to be alive for buy weapons");
return;
}
if ((GetFeatureStatus(FeatureType_Native, "ZR_IsClientZombie") == FeatureStatus_Available) && ZR_IsClientZombie(client))
{
PrintToChat(client, " \x04You need to be human for buy weapons");
return;
}

char weapons[64];
KvGetString(kv, "weapon", weapons, 64);
int times = KvGetNum(kv, "times");
int current;

if(times == 0)
{
int drop = KvGetNum(kv, "slot", -1);
if(drop != -1)
{
int weapon = GetPlayerWeaponSlot(client, drop);
if(weapon != -1) SDKHooks_DropWeapon(client, weapon);
}

GivePlayerItem(client, weapons);
SetEntProp(client, Prop_Send, "m_iAccount", money-cost);
ReplaceString(weapons, sizeof(weapons), "weapon_", "");
PrintToChat(client, " \x04You have bought a %s", weapons);
return;
}

if (!GetTrieValue(trie_weapons[client], weapons, current))current = 0;

if(times <= current)
{
PrintToChat(client, " \x04You cant buy more %s this round", weapons);
return;

}
SetTrieValue(trie_weapons[client], weapons, ++current);

int drop = KvGetNum(kv, "slot", -1);
if(drop != -1)
{
int weapon = GetPlayerWeaponSlot(client, drop);
if(weapon != -1) SDKHooks_DropWeapon(client, weapon);
}

GivePlayerItem(client, weapons);
SetEntProp(client, Prop_Send, "m_iAccount", money-cost);
ReplaceString(weapons, sizeof(weapons), "weapon_", "");

PrintToChat(client, " \x04You have bought a %s %i/%i", weapons, current, times);
}
else PrintToChat(client, " \x04You dont have enought money. You need %i", cost);

}

stock bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
{
if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
{
return false;
}
return true;
}

stock bool CheckAdminFlagsByString(int client, const char[] flagString)
{
AdminId admin = view_as<AdminId>(GetUserAdmin(client));
if (admin != INVALID_ADMIN_ID){
int count, found, flags = ReadFlagString(flagString);
for (int i = 0; i <= 20; i++){
if (flags & (1<<i))
{
count++;

if(GetAdminFlag(admin, view_as<AdminFlag>(i))){
found++;
}
}
}

if (count == found || GetUserFlagBits(client) & ADMFLAG_ROOT){
return true;
}
}

return false;
}







Can someone make this code so you can buy weapons and items like kevlar & vest and kevlar?
My regards


Remove the credits from a sourcemod plugin is against the law.

Original source: https://github.com/Franc1sco/Franug-...uy_commands.sp
__________________
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.


Last edited by Franc1sco; 04-25-2021 at 07:12.
Franc1sco is offline
Send a message via MSN to Franc1sco
Reply


Thread Tools
Display Modes

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 17:00.


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