02-28-2011, 12:38 PM
(This post was last modified: 02-28-2011, 12:38 PM by codename_B.)
Here's the store plugin I've been working on, I finally got the ini file writing to work.
The basics - credits are earned by mining, one credit per block mined, doesn't matter the type. When a method to detect playerkills is added, I will be adding in 100 credits for killing a player and losing 100 credits for being killed. When mobs and monsters are implemented, I will be adding a credit value system to that too
You can buy:
64 torches - 64 credits
wood shovel, axe, pickaxe, sword - 0 credits (new players joining the server automatically get access to basic tools)
stone shovel, axe, pickaxe, sword - 100 credits
iron shovel, axe, pickaxe, sword - 500 credits
gold shovel, axe, pickaxe, sword - 800 credits
diamond shovel, axe, pickaxe, sword - 1000 credits
This is easily expandable to include other items as I've added a fairly easy to expand store api with a function to check and see if I player can afford an item
Filename:Kit.lua
Before I forget, you can access the prices list by typing "/store" into the chat window.
That should be all else you need
The basics - credits are earned by mining, one credit per block mined, doesn't matter the type. When a method to detect playerkills is added, I will be adding in 100 credits for killing a player and losing 100 credits for being killed. When mobs and monsters are implemented, I will be adding a credit value system to that too
You can buy:
64 torches - 64 credits
wood shovel, axe, pickaxe, sword - 0 credits (new players joining the server automatically get access to basic tools)
stone shovel, axe, pickaxe, sword - 100 credits
iron shovel, axe, pickaxe, sword - 500 credits
gold shovel, axe, pickaxe, sword - 800 credits
diamond shovel, axe, pickaxe, sword - 1000 credits
This is easily expandable to include other items as I've added a fairly easy to expand store api with a function to check and see if I player can afford an item
Filename:Kit.lua
PHP Code:
local KitPlugin = {}
KitPlugin.__index = KitPlugin
function KitPlugin:new()
local t = {}
setmetatable(t, KitPlugin)
local w = Lua__cPlugin:new()
tolua.setpeer(w, t)
w:tolua__set_instance(w)
return w
end
function KitPlugin:Initialize()
self:AddCommand("/store", " - tells you what's currently for sale and how many credits you have.", "Kit.lua")
self:BindCommand("/store", PricesCommand)
self:BindCommand("/buywoodkit", BuyWoodKit)
self:BindCommand("/buystonekit", BuyStoneKit)
self:BindCommand("/buyironkit", BuyIronKit)
self:BindCommand("/buygoldkit", BuyGoldKit)
self:BindCommand("/buydiamondkit", BuyDiamondKit)
self:BindCommand("/buytorches", Buy64Torches)
PluginManager = cRoot:Get():GetPluginManager()
PluginManager:AddHook( self, cPluginManager.E_PLUGIN_BLOCK_DIG )
return true
end
function KitPlugin:OnBlockDig( PacketData, Player )
local PlayerName = Player:GetName()
local World = cRoot:Get():GetWorld()
local X = PacketData.m_PosX
local Y = PacketData.m_PosY
local Z = PacketData.m_PosZ
-- status 0 = started digging; 2 = block broken
if(PacketData.m_Status == 2) then
local IniFile = cIniFile("score.ini")
if ( IniFile:ReadFile() == true ) then
PlayerScore = IniFile:GetValueI(PlayerName, "score" )
NewScore = PlayerScore+1
IniFile:DeleteKey(PlayerName)
IniFile:WriteFile()
IniFile:AddKeyName(PlayerName)
IniFile:SetValueI(PlayerName, "score", NewScore)
IniFile:WriteFile()
Log(NewScore);
end
end
return false
end
function CanAfford(money, Player)
local PlayerName = Player:GetName()
local IniFile = cIniFile("score.ini")
if ( IniFile:ReadFile() == true ) then
PlayerScore = IniFile:GetValueI(PlayerName, "score" )
Log(PlayerScore);
if(PlayerScore>=money) then
if(money>0) then
NewScore = PlayerScore-money
Log("Sold item");
else
NewScore = PlayerScore
Log("Gave away freebie");
end
IniFile:DeleteKey(PlayerName)
IniFile:WriteFile()
IniFile:SetValueI(PlayerName, "score", NewScore)
IniFile:WriteFile()
Log(NewScore);
end
return true
else
return false
end
end
-- store values --
function BuyWoodKit(Split, Player)
Server = cRoot:Get():GetServer()
if(CanAfford(0, Player)) then
Server:SendMessage(cChatColor.Red .. "The wood kit has been added to your inventory")
Player:GetInventory():AddItem( cItem( 268, 1 ) )
Player:GetInventory():AddItem( cItem( 269, 1 ) )
Player:GetInventory():AddItem( cItem( 270, 1 ) )
Player:GetInventory():AddItem( cItem( 271, 1 ) )
else
Server:SendMessage(cChatColor.Red .. "You cannot afford the wood kit!")
end
return true
end
function BuyStoneKit(Split, Player)
Server = cRoot:Get():GetServer()
if(CanAfford(100, Player)) then
Server:SendMessage(cChatColor.Red .. "The stone kit has been added to your inventory")
Player:GetInventory():AddItem( cItem( 272, 1 ) )
Player:GetInventory():AddItem( cItem( 273, 1 ) )
Player:GetInventory():AddItem( cItem( 274, 1 ) )
Player:GetInventory():AddItem( cItem( 275, 1 ) )
else
Server:SendMessage(cChatColor.Red .. "You cannot afford the iron kit!")
end
return true
end
function BuyIronKit(Split, Player)
Server = cRoot:Get():GetServer()
if(CanAfford(500, Player)) then
Server:SendMessage(cChatColor.Red .. "The iron kit has been added to your inventory")
Player:GetInventory():AddItem( cItem( 267, 1 ) )
Player:GetInventory():AddItem( cItem( 256, 1 ) )
Player:GetInventory():AddItem( cItem( 257, 1 ) )
Player:GetInventory():AddItem( cItem( 258, 1 ) )
else
Server:SendMessage(cChatColor.Red .. "You cannot afford the iron kit!")
end
return true
end
function BuyGoldKit(Split, Player)
Server = cRoot:Get():GetServer()
if(CanAfford(800, Player)) then
Server:SendMessage(cChatColor.Red .. "The gold kit has been added to your inventory")
Player:GetInventory():AddItem( cItem( 283, 1 ) )
Player:GetInventory():AddItem( cItem( 284, 1 ) )
Player:GetInventory():AddItem( cItem( 285, 1 ) )
Player:GetInventory():AddItem( cItem( 286, 1 ) )
else
Server:SendMessage(cChatColor.Red .. "You cannot afford the gold kit!")
end
return true
end
function BuyDiamondKit(Split, Player)
Server = cRoot:Get():GetServer()
if(CanAfford(1000, Player)) then
Server:SendMessage(cChatColor.Red .. "The diamond kit has been added to your inventory")
Player:GetInventory():AddItem( cItem( 276, 1 ) )
Player:GetInventory():AddItem( cItem( 277, 1 ) )
Player:GetInventory():AddItem( cItem( 278, 1 ) )
Player:GetInventory():AddItem( cItem( 279, 1 ) )
else
Server:SendMessage(cChatColor.Red .. "You cannot afford the diamond kit!")
end
return true
end
function Buy64Torches(Split, Player)
Server = cRoot:Get():GetServer()
if(CanAfford(64, Player)) then
Server:SendMessage(cChatColor.Red .. "64 torches have been added to your inventory")
Player:GetInventory():AddItem( cItem( 50, 64 ) )
else
Server:SendMessage(cChatColor.Red .. "You cannot afford 64 torches!")
end
return true
end
-- end of store values --
function KitCommand1(Split, Player)
Player:GetInventory():AddItem( cItem( 283, 1 ) )
Player:GetInventory():AddItem( cItem( 284, 1 ) )
Player:GetInventory():AddItem( cItem( 285, 1 ) )
Player:GetInventory():AddItem( cItem( 286, 1 ) )
Player:GetInventory():AddItem( cItem( 314, 1 ) )
Player:GetInventory():AddItem( cItem( 315, 1 ) )
Player:GetInventory():AddItem( cItem( 316, 1 ) )
Player:GetInventory():AddItem( cItem( 317, 1 ) )
Server = cRoot:Get():GetServer()
Server:SendMessage(cChatColor.Red .. "Get your kit on!")
return true
end
function PricesCommand(Split, Player)
local PlayerName = Player:GetName()
Server = cRoot:Get():GetServer()
local IniFile = cIniFile("score.ini")
if ( IniFile:ReadFile() == true ) then
PlayerScore = IniFile:GetValueI(PlayerName, "score" )
Server:SendMessage(cChatColor.Green .. PlayerName)
Server:SendMessage(cChatColor.Green .. "You have earned "..PlayerScore.." credits.")
Server:SendMessage(cChatColor.Green .. "Keep mining to earn more!")
Server:SendMessage(cChatColor.Green .. "Buy 64 torches: 64 credits - use /buytorches")
Server:SendMessage(cChatColor.Green .. "Wood Kit: 0 credits - use /buywoodkit")
Server:SendMessage(cChatColor.Green .. "Stone Kit: 100 credits - use /buystonekit")
Server:SendMessage(cChatColor.Green .. "Iron Kit: 500 credits - use /buyironkit")
Server:SendMessage(cChatColor.Green .. "Gold Kit: 800 credits - use /buygoldkit")
Server:SendMessage(cChatColor.Green .. "Diamond Kit: 1000 credits - use /buydiamondkit")
end
return true
end
Plugin = KitPlugin:new()
cRoot:Get():GetPluginManager():AddPlugin( Plugin )
Before I forget, you can access the prices list by typing "/store" into the chat window.
That should be all else you need