Veteran Member
|
09-01-2012
, 08:04
Re: Tf2: Credit plugin
|
#4
|
This is something I was having fun with on my server. Currently crashes, not sure why... Ah, offsets changed, whatever. You can start from here and code whatever you want. It runs on top of [ANY] Money system.
Bits of sp file:
PHP Code:
public OnPluginStart() { Money_Init(); ItemMarket_Init(); }
public OnConfigsExecuted() { if (IsBuyMenuReady()) { OnBuyMenuReady(); } }
public OnBuyMenuReady() { ItemMarket_Load(); }
Money.inc
PHP Code:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Money system ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// player_death new Handle:ftz_reward_kill = INVALID_HANDLE; new Handle:ftz_reward_domination = INVALID_HANDLE; new Handle:ftz_reward_revenge = INVALID_HANDLE; new Handle:ftz_reward_assist = INVALID_HANDLE; new Handle:ftz_reward_assist_domination = INVALID_HANDLE; new Handle:ftz_reward_assist_revenge = INVALID_HANDLE;
// object_destroyed new Handle:ftz_reward_destroy_sentry = INVALID_HANDLE; new Handle:ftz_reward_destroy_dispenser = INVALID_HANDLE; new Handle:ftz_reward_destroy_teleport = INVALID_HANDLE; new Handle:ftz_reward_destroy_sapper = INVALID_HANDLE; new Handle:ftz_reward_destroy2_sentry = INVALID_HANDLE; new Handle:ftz_reward_destroy2_dispenser = INVALID_HANDLE; new Handle:ftz_reward_destroy2_teleport = INVALID_HANDLE; new Handle:ftz_reward_destroy2_sapper = INVALID_HANDLE; new Handle:ftz_reward_destroy_building = INVALID_HANDLE;
// ctf_flag_captured new Handle:ftz_reward_flag_cap = INVALID_HANDLE; new Handle:ftz_reward_flag_cap_mult = INVALID_HANDLE;
// player_builtobject new Handle:ftz_reward_build_sentry = INVALID_HANDLE; new Handle:ftz_reward_build_dispenser = INVALID_HANDLE; new Handle:ftz_reward_build_teleport = INVALID_HANDLE; new Handle:ftz_reward_build_sapper = INVALID_HANDLE;
Money_Init() { ftz_reward_kill = CreateConVar("ftz_reward_kill", "200", "The reward for killing an enemy.", _, true, 0.0, false, 0.0); ftz_reward_domination = CreateConVar("ftz_reward_domination", "3", "The reward multiplier for dominated kill.", _, true, 0.0, false, 0.0); ftz_reward_revenge = CreateConVar("ftz_reward_revenge", "2", "The reward multiplier for revenge kill.", _, true, 0.0, false, 0.0); ftz_reward_assist = CreateConVar("ftz_reward_assist", "1", "The reward multiplier for assisted kill.", _, true, 0.0, false, 0.0); ftz_reward_assist_domination = CreateConVar("ftz_reward_assist_domination", "3", "The reward multiplier for assisted dominated kill.", _, true, 0.0, false, 0.0); ftz_reward_assist_revenge = CreateConVar("ftz_reward_assist_revenge", "2", "The reward multiplier for assisted revenge kill.", _, true, 0.0, false, 0.0); ftz_reward_destroy_sentry = CreateConVar("ftz_reward_destroy_sentry", "1.5", "The reward multiplier for sentry destruction.", _, true, 0.0, false, 0.0); ftz_reward_destroy_dispenser = CreateConVar("ftz_reward_destroy_dispenser", "0.7", "The reward multiplier for dispenser destruction.", _, true, 0.0, false, 0.0); ftz_reward_destroy_teleport = CreateConVar("ftz_reward_destroy_teleport", "0.5", "The reward multiplier for teleporter destruction.", _, true, 0.0, false, 0.0); ftz_reward_destroy_sapper = CreateConVar("ftz_reward_destroy_sapper", "1.25", "The reward multiplier for sapper destruction.", _, true, 0.0, false, 0.0); ftz_reward_destroy2_sentry = CreateConVar("ftz_reward_destroy2_sentry", "1.5", "The reward multiplier for assisted sentry destruction.", _, true, 0.0, false, 0.0); ftz_reward_destroy2_dispenser = CreateConVar("ftz_reward_destroy2_dispenser", "0.7", "The reward multiplier for assisted dispenser destruction.", _, true, 0.0, false, 0.0); ftz_reward_destroy2_teleport = CreateConVar("ftz_reward_destroy2_teleport", "0.5", "The reward multiplier for assisted teleporter destruction.", _, true, 0.0, false, 0.0); ftz_reward_destroy2_sapper = CreateConVar("ftz_reward_destroy2_sapper", "1.25", "The reward multiplier for assisted sapper destruction.", _, true, 0.0, false, 0.0); ftz_reward_destroy_building = CreateConVar("ftz_reward_destroy_building", "2", "The reward multiplier for building object destruction.", _, true, 0.0, false, 0.0); ftz_reward_flag_cap = CreateConVar("ftz_reward_flag_cap", "300", "The reward for 1st flag capture.", _, true, 0.0, false, 0.0); ftz_reward_flag_cap_mult = CreateConVar("ftz_reward_flag_cap_mult", "1", "The reward multiplier for consequent flag captures.", _, true, 0.0, false, 0.0); ftz_reward_build_sentry = CreateConVar("ftz_reward_build_sentry", "65", "The reward for building a sentry.", _, true, 0.0, false, 0.0); ftz_reward_build_dispenser = CreateConVar("ftz_reward_build_dispenser", "50", "The reward for building dispenser.", _, true, 0.0, false, 0.0); ftz_reward_build_teleport = CreateConVar("ftz_reward_build_teleport", "62", "The reward for building teleporter entrance.", _, true, 0.0, false, 0.0); ftz_reward_build_sapper = CreateConVar("ftz_reward_build_sapper", "100", "The reward for building a sapper.", _, true, 0.0, false, 0.0); }
Money_EventPlayerDeath(const client, const attacker, const assister, const death_flags) { new basereward = GetConVarInt(ftz_reward_kill); new finalreward; decl String:specialkillprint[32]; specialkillprint[0] = '\0'; if ((attacker == client) || (attacker == 0) || (!IsClientInGame(attacker))) { return; } finalreward = basereward; if (death_flags & TF_DEATHFLAG_KILLERDOMINATION) { finalreward = RoundToNearest(float(basereward) * GetConVarFloat(ftz_reward_domination)); specialkillprint = "dominated " } if (death_flags & TF_DEATHFLAG_KILLERREVENGE) { finalreward = RoundToNearest(float(basereward) * GetConVarFloat(ftz_reward_revenge)); specialkillprint = "revenge " } Logging_PrintToAdmin(2, "Base reward: %d, final reward: %d", basereward, finalreward); if (!AddClientMoney(attacker , finalreward)) { Logging_PrintToAdmin(0, "Unable to add money"); } else { PrintToChat(attacker, "[fTz] You have earned $%d by %skilling an enemy.", finalreward, specialkillprint); } if (assister == 0) { return; } finalreward = RoundToNearest(float(basereward) * GetConVarFloat(ftz_reward_assist)); if (death_flags & TF_DEATHFLAG_ASSISTERDOMINATION) { finalreward = RoundToNearest(float(basereward) * GetConVarFloat(ftz_reward_assist_domination)); specialkillprint = "dominated " } if (death_flags & TF_DEATHFLAG_ASSISTERREVENGE) { finalreward = RoundToNearest(float(basereward) * GetConVarFloat(ftz_reward_assist_revenge)); specialkillprint = "revenge " } Logging_PrintToAdmin(2, "Assister base reward: %d, final reward: %d", basereward, finalreward); if (!AddClientMoney(assister, finalreward)) { Logging_PrintToAdmin(0, "Unable to add money"); return; } PrintToChat(assister, "[fTz] You have earned $%d by assisted %skilling an enemy.", finalreward, specialkillprint); }
Money_EventObjectDestroyed(const client, const attacker, const assister, const String:userweapon[64], const Object:objecttype, const bool:was_building) { if (attacker == client) { return; } new Handle:rewardconvar; new basereward; new finalreward; decl String:weaponprintname[64]; decl String:objectprint[64]; if (was_building) { finalreward = RoundToNearest(float(basereward) * GetConVarFloat(ftz_reward_destroy_building)); objectprint = "building" } else { finalreward = basereward; } if (!GetTrieString(ItemPrintNameTrie, userweapon, weaponprintname, 64)) { weaponprintname = userweapon; } switch (objecttype) { case OBJECT_DISPENSER: { finalreward = RoundToNearest(float(finalreward) * GetConVarFloat(ftz_reward_destroy_dispenser)); Format(objectprint, 64, "%s dispenser", objectprint); } case OBJECT_TELEPORTER: { finalreward = RoundToNearest(float(finalreward) * GetConVarFloat(ftz_reward_destroy_teleport)); Format(objectprint, 64, "%s teleporter", objectprint); } case OBJECT_SENTRYGUN: { finalreward = RoundToNearest(float(finalreward) * GetConVarFloat(ftz_reward_destroy_sentry)); Format(objectprint, 64, "%s sentry", objectprint); } case OBJECT_ATTACHMENT_SAPPER: { finalreward = RoundToNearest(float(finalreward) * GetConVarFloat(ftz_reward_destroy_sapper)); Format(objectprint, 64, "%s sapper", objectprint); } } Logging_PrintToAdmin(2, "Base reward: %d, final reward: %d", basereward, finalreward); if (AddClientMoney(attacker, finalreward)) { PrintToChat(attacker, "[fTz] You have earned $%d by destroying an enemy %s with %s.", finalreward, objectprint, weaponprintname); } if (assister == 0) { return; } switch (objecttype) { case OBJECT_DISPENSER:{finalreward = RoundToNearest(float(finalreward) * GetConVarFloat(ftz_reward_destroy2_dispenser));} case OBJECT_TELEPORTER:{finalreward = RoundToNearest(float(finalreward) * GetConVarFloat(ftz_reward_destroy2_teleport));} case OBJECT_SENTRYGUN:{finalreward = RoundToNearest(float(finalreward) * GetConVarFloat(ftz_reward_destroy2_sentry));} case OBJECT_ATTACHMENT_SAPPER:{finalreward = RoundToNearest(float(finalreward) * GetConVarFloat(ftz_reward_destroy2_sapper));} } Logging_PrintToAdmin(2, "Assister base reward: %d, final reward: %d", basereward, finalreward); if (!AddClientMoney(assister, finalreward)) { return; } PrintToChat(assister, "[fTz] You have earned $%d by assister destroying an enemy's %s with %s.", finalreward, objectprint, weaponprintname); }
Money_EventCTFFlagCaptured(const Team:team, const score) { new reward; new scoremod100; new scoremod10; decl String:teamname[4]; decl String:capprint[8]; switch (team) { case TEAM_RED:{teamname = "RED";} case TEAM_BLU:{teamname = "BLU";} } reward = RoundToNearest(float(GetConVarInt(ftz_reward_flag_cap)) * float(score) * GetConVarFloat(ftz_reward_flag_cap_mult)); scoremod100 = score % 100; scoremod10 = score % 10; switch (scoremod10) { case 1: { if (scoremod100 != 11) { Format(capprint, 8, "%dst", score); } else { Format(capprint, 8, "%dth", score); } } case 2: { if (scoremod100 != 12) { Format(capprint, 8, "%dnd", score); } else { Format(capprint, 8, "%dth", score); } } case 3: { if (scoremod100 != 13) { Format(capprint, 8, "%drd", score); } else { Format(capprint, 8, "%dth", score); } } default: { Format(capprint, 8, "%dth", score); } } PrintToChatAll("[fTz] %s have earned $%d by capturing an enemy intelligence for the %s time.", teamname, reward, capprint); for (new i=1; i<=MaxClients; i++) { if ((IsClientInGame(i)) && (PlayerTeam[i]==team)) { if (AddClientMoney(i, reward)) { PrintToChat(i, "[fTz] You have earned $%d.", reward); } } } }
Money_EventPlayerBuiltobject(const client, const Object:object) { new reward; decl String:objectprint[32]; switch (object) { case OBJECT_DISPENSER: { reward = GetConVarInt(ftz_reward_build_dispenser); objectprint = "dispenser"; } case OBJECT_TELEPORTER: { reward = GetConVarInt(ftz_reward_build_teleport); objectprint = "teleporter"; } case OBJECT_SENTRYGUN: { reward = GetConVarInt(ftz_reward_build_sentry); objectprint = "a sentry"; } case OBJECT_ATTACHMENT_SAPPER: { reward = GetConVarInt(ftz_reward_build_sapper); objectprint = "a sapper"; } } if (!AddClientMoney(client, reward)) { return; } PrintToChat(client, "[fTz] You have earned $%d by building %s.", reward, objectprint); }
Money_EventPlayerSpawn(const client, const Team:team) { if (team == TEAM_NONE) { return; } new money = GetClientMoney(client); PrintToChat(client, "[fTz] Your money: $%d.", money); }
itemmarket.inc
PHP Code:
//////////////////////////////////////////////////////////////////////////////// // Item market ////////////////////////////////////////////////////////////////////////////////
#define ITEM_NAME_SIZE 32 #define ITEM_ALIAS_SIZE 32 #define ITEM_PRICE_CVAR_NAME_SIZE 32 #define NUM_ITEMS 38
enum Item { String:itemname[ITEM_NAME_SIZE], String:itemalias[ITEM_ALIAS_SIZE], String:itemparentalias[ITEM_ALIAS_SIZE], String:pricecvarname[ITEM_PRICE_CVAR_NAME_SIZE], Handle:pricecvar };
static ItemBuffer[NUM_ITEMS][Item]; static ItemBufferSize = 0;
ItemMarket_Init() { ItemMarket_CreateItem("Scattergun", "tf_weapon_scattergun", "scout", "ftz_price_scattergun", "500", "The price of a scattergun"); ItemMarket_CreateItem("Pistol", "tf_weapon_pistol_scout", "scout", "ftz_price_pistol_scout", "150", "The price of a Scout's pistol"); ItemMarket_CreateItem("Bat", "tf_weapon_bat", "scout", "ftz_price_bat", "120", "The price of a bat"); ItemMarket_CreateItem("Rocket launcher", "tf_weapon_rocketlauncher", "soldier", "ftz_price_rocketlauncher", "1500", "The price of a rocket launcher"); ItemMarket_CreateItem("Shotgun", "tf_weapon_shotgun_soldier", "soldier", "ftz_price_shotgun_soldier", "500", "The price of a Soldier's shotgun"); ItemMarket_CreateItem("Shovel", "tf_weapon_shovel", "soldier", "ftz_price_shovel", "100", "The price of a shovel"); ItemMarket_CreateItem("Flamethrower", "tf_weapon_flamethrower", "pyro", "ftz_price_flamethrower", "800", "The price of a flamethrower"); ItemMarket_CreateItem("Shotgun", "tf_weapon_shotgun_pyro", "pyro", "ftz_price_shotgun_pyro", "500", "The price of a Pyro's shotgun"); ItemMarket_CreateItem("Fire axe", "tf_weapon_fireaxe", "pyro", "ftz_price_fireaxe", "100", "The price of a fire axe"); ItemMarket_CreateItem("Grenade launcher", "tf_weapon_grenadelauncher", "demoman", "ftz_price_grenadelauncher", "1100", "The price of a grenade launcher"); ItemMarket_CreateItem("Sticky bomb launcher", "tf_weapon_pipebomblauncher", "demoman", "ftz_price_pipebomblauncher", "1300", "The price of a sticky bomb launcher"); ItemMarket_CreateItem("Bottle", "tf_weapon_bottle", "demoman", "ftz_price_bottle", "100", "The price of a bottle"); ItemMarket_CreateItem("Minigun", "tf_weapon_minigun", "heavy", "ftz_price_minigun", "1000", "The price of a minigun"); ItemMarket_CreateItem("Shotgun", "tf_weapon_shotgun_hwg", "heavy", "ftz_price_shotgun_hwg", "500", "The price of a Heavy's shotgun"); ItemMarket_CreateItem("Fists", "tf_weapon_fists", "heavy", "ftz_price_fists", "100", "The price of fists"); ItemMarket_CreateItem("Shotgun", "tf_weapon_shotgun_primary", "engineer", "ftz_price_shotgun_primary", "500", "The price of an Engineer's shotgun"); ItemMarket_CreateItem("Pistol", "tf_weapon_pistol", "engineer", "ftz_price_pistol", "150", "The price of an Engineer's pistol"); ItemMarket_CreateItem("Wrench", "tf_weapon_wrench", "engineer", "ftz_price_wrench", "100", "The price of a wrench"); ItemMarket_CreateItem("Build PDA", "tf_weapon_pda_engineer_build", "engineer", "ftz_price_pda_engineer_build", "100", "The price of a Build PDA"); ItemMarket_CreateItem("Destroy PDA", "tf_weapon_pda_engineer_destroy", "engineer", "ftz_price_pda_engineer_destroy", "100", "The price of a Destroy PDA"); ItemMarket_CreateItem("Builder", "tf_weapon_builder", "engineer", "ftz_price_builder", "100", "The price of a builder"); ItemMarket_CreateItem("Syringe gun", "tf_weapon_syringegun_medic", "medic", "ftz_price_syringegun_medic", "400", "The price of a syringe gun"); ItemMarket_CreateItem("Medigun", "tf_weapon_medigun", "medic", "ftz_price_medigun", "800", "The price of a medigun"); ItemMarket_CreateItem("Bonesaw", "tf_weapon_bonesaw", "medic", "ftz_price_bonesaw", "100", "The price of a bonesaw"); ItemMarket_CreateItem("Sniper rifle", "tf_weapon_sniperrifle", "sniper", "ftz_price_sniperrifle", "1200", "The price of a sniper rifle"); ItemMarket_CreateItem("SMG", "tf_weapon_smg", "sniper", "ftz_price_smg", "300", "The price of a SMG"); ItemMarket_CreateItem("Kukri", "tf_weapon_club", "sniper", "ftz_price_club", "100", "The price of a kukri"); ItemMarket_CreateItem("Revolver", "tf_weapon_revolver", "spy", "ftz_price_revolver", "150", "The price of a revolver"); ItemMarket_CreateItem("Knife", "tf_weapon_knife", "spy", "ftz_price_knife", "300", "The price of a knife"); ItemMarket_CreateItem("PDA", "tf_weapon_pda_spy", "spy", "ftz_price_pda_spy", "100", "The price of a Spy PDA"); ItemMarket_CreateItem("Invisibility", "tf_weapon_invis", "spy", "ftz_price_invis", "100", "The price of a invisibility"); ItemMarket_CreateItem("Small healthkit", "item_healthkit_small", "other", "ftz_price_healthkit_small", "100", "The price of a small healthkit"); ItemMarket_CreateItem("Medium healthkit", "item_healthkit_medium", "other", "ftz_price_healthkit_medium", "200", "The price of a medium healthkit"); ItemMarket_CreateItem("Full healthkit", "item_healthkit_full", "other", "ftz_price_healthkit_full", "400", "The price of a full healthkit"); ItemMarket_CreateItem("Small ammopack", "item_ammopack_small", "other", "ftz_price_ammopack_small", "100", "The price of a small ammopack"); ItemMarket_CreateItem("Medium ammopack", "item_ammopack_medium", "other", "ftz_price_ammopack_medium", "200", "The price of a medium ammopack"); ItemMarket_CreateItem("Full ammopack", "item_ammopack_full", "other", "ftz_price_ammopack_full", "400", "The price of a full ammopack"); ItemMarket_CreateItem("Intelligence", "item_teamflag", "other", "ftz_price_teamflag", "10000", "The price of an intelligence"); }
ItemMarket_Load() { CreateBuyMenuSubMenu("Scout", "scout"); CreateBuyMenuSubMenu("Soldier", "soldier"); CreateBuyMenuSubMenu("Pyro", "pyro"); CreateBuyMenuSubMenu("Demoman", "demoman"); CreateBuyMenuSubMenu("Heavy", "heavy"); CreateBuyMenuSubMenu("Engineer", "engineer"); CreateBuyMenuSubMenu("Medic", "medic"); CreateBuyMenuSubMenu("Sniper", "sniper"); CreateBuyMenuSubMenu("Spy", "spy"); CreateBuyMenuSubMenu("Other", "other"); for (new i = 0; i < 31; i++) { AddBuyMenuItem(ItemBuffer[i][itemname], ItemBuffer[i][itemalias], GetConVarInt(ItemBuffer[i][pricecvar]), OnClientBuyWeapon, ItemBuffer[i][itemparentalias]); } for (new i = 31; i < NUM_ITEMS; i++) { AddBuyMenuItem(ItemBuffer[i][itemname], ItemBuffer[i][itemalias], GetConVarInt(ItemBuffer[i][pricecvar]), OnClientBuyItem, ItemBuffer[i][itemparentalias]); } }
static ItemMarket_CreateItem(const String:name[], const String:alias[], const String:parentalias[], const String:cvarname[], const String:price[], const String:description[]) { strcopy(ItemBuffer[ItemBufferSize][itemname], ITEM_NAME_SIZE, name); strcopy(ItemBuffer[ItemBufferSize][itemalias], ITEM_ALIAS_SIZE, alias); strcopy(ItemBuffer[ItemBufferSize][itemparentalias], ITEM_ALIAS_SIZE, parentalias); strcopy(ItemBuffer[ItemBufferSize][pricecvarname], ITEM_PRICE_CVAR_NAME_SIZE, cvarname); ItemBuffer[ItemBufferSize][pricecvar] = CreateConVar(cvarname, price, description, FCVAR_PRINTABLEONLY, true); HookConVarChange(ItemBuffer[ItemBufferSize][pricecvar], PriceChange); ItemBufferSize++; }
public PriceChange(Handle:cvar, const String:oldVal[], const String:newVal[]) { decl String:cvarname[ITEM_PRICE_CVAR_NAME_SIZE]; GetConVarName(cvar, cvarname, ITEM_PRICE_CVAR_NAME_SIZE); for (new i = 0; i < NUM_ITEMS; i++) { if (strcmp(ItemBuffer[i][pricecvarname], cvarname) == 0) { ChangeBuyMenuItemPrice(ItemBuffer[i][itemalias], GetConVarInt(ItemBuffer[i][pricecvar])); } } }
public bool:OnClientBuyWeapon(const client, const String:classname[]) { new entity = SDKCall(GiveWeaponSDKCall, client, classname, 0); //new entity = SDKCall(GiveWeaponSDKCall, client, classname, 0, 0); SDKCall(EquipWeaponSDKCall, client, entity); return true; }
public bool:OnClientBuyItem(const client, const String:classname[]) { new entity = CreateEntityByName(classname, -1); if (entity == -1) { return false; } decl Float:entcoords[3]; GetClientAbsOrigin(client, entcoords); DispatchSpawn(entity) TeleportEntity(entity, entcoords, NULL_VECTOR, NULL_VECTOR); return true; }
__________________
Last edited by FaTony; 09-01-2012 at 08:04.
|
|