Menus are run on the client machine. To give a player an item you have to run the code on the server. You can create a function in your game class to give the player an item. You have to set up replication so the client can call the function on the server. So it would be like this:
game class:
- Code: Select all
class<Inventory> item[32]; //The list of items
replication
{
//Functions the client can call on the server.
reliable if(Role < ROLE_Authority)
BuyItem;
}
function BuyItem(DeusExPlayer player, int item index)
{
local Inventory anItem;
if(player == None)
return;
if(index > 0 && index < 32 && item[index] != None)
{
anItem = Spawn(item[index]);
if(anItem != None)
{
anItem.Frob(player, None); //This gives the player a copy.
anItem.Destroy(); //Destroy the original.
}
}
}
defaultproperties
{
//items are listed here
itemList(0)=class'DeusEx.WeaponPistol',
itemList(1)=class'DeusEx.WeaponStealthPistol',
}
Then your menu class would have something like this:
- Code: Select all
function ProcessAction(String S)
{
Super.ProcessAction(S);
if (S == "BUY")
{
YourGameClass(Level.Game).BuyItem(Player, SelectedItemIndex)
}
}
(this is a simple example and doesn't consider cost)
It's important that you only allow the player to give an index as an argument. If you let them pass classes as args, then it would be easy for someone to hack it and get whatever they want.
Speaking of store menus, here is one I made a few days ago for my PvBCageMatch mod.
http://img525.imageshack.us/img525/1374/pvbcmstore.jpg (Can buy)
http://img18.imageshack.us/img18/6634/pvbcmstore2.jpg (Can't buy)
It uses a config file so the item list can be changed without having to recompile.