Page 1 of 1

How to give player a custom gun;

PostPosted: Sun Feb 12, 12 4:14 am
by bambi
Hi folks,

I'm working on my counterstrike mod again, and I need some help.

How might I give a player a custom weapon from within a MenuUIScreenWindow class?

I know how to give the player a weapon from the player class, but I can't within a class that extends MenuUIScreenWindow:

Here is the context of the method;
Code: Select all
function ProcessAction(String S)
{
   local DeusExPlayer anItem;
   Super.ProcessAction(S);

   if (S == "DONT BUY")
   {
      PlayerBuy.ClientSetBuy(-1);
      Current.SetText("");
   }
   else if (S == "BUY") //WHAT DO I DO?????
   {
      // Items
      //anItem = Spawn(class'MP5S.Weaponm16;);
      //anItem.Frob(Self,None); //DOESN'T WORK

      Player = seal(GetPlayerPawn());
      seal.GiveInventory(Player); //DOESN'T WORK
      //anItem.GiveInitialInventory(); 

      //actionButtons[2].btn.SetSensitivity(false);
      
   }
}

PostPosted: Sun Feb 12, 12 5:40 am
by Poor
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.

PostPosted: Sun Feb 12, 12 5:46 am
by bambi
hpoly mother of god poor, that store is perfect for my counterstrike mod!!!

Ok, I got a couple questions poor,

1. class<Inventory> item[32]; why is Inventory in brackets?

damn poor, u're becoming a top notch deus ex programmer!

PostPosted: Sun Feb 12, 12 10:24 am
by Dae
bambi wrote: 1. class<Inventory> item[32]; why is Inventory in brackets?

If I remember correctly, it'd make the variable appear in properties menu in UnrealEd under "Inventory".

PostPosted: Sun Feb 12, 12 4:23 pm
by Poor
Sorry, it should be

Code: Select all
var class<Inventory> item[32];


It's class<Inventory> and not Inventory because you need to hold classes, not objects. Spawn() takes a class as it's first argument and will return a new object of that class.

PostPosted: Sun Feb 12, 12 8:12 pm
by ~ô¿ô~Nobody~
Dae wrote:
bambi wrote: 1. class<Inventory> item[32]; why is Inventory in brackets?

If I remember correctly, it'd make the variable appear in properties menu in UnrealEd under "Inventory".

What you mean would look like..
var(Inventory) class item[32];
Poor wrote:Sorry, it should be

Code: Select all
var class<Inventory> item[32];


It's class<Inventory> and not Inventory because you need to hold classes, not objects. Spawn() takes a class as it's first argument and will return a new object of that class.

The type specifier within that angle brackets describes the parent class of the classes you put in the variable.
In other words.. you couldn't put a class'AmmoCrate' into the variable because it doesn't inherit from Inventory directly or indirectly.

The [32] indicates an array.
Thus.. item is not ONE variable but an array for MANY class values

PostPosted: Sun Feb 12, 12 8:33 pm
by bambi
thanks, that clarifies my questions, However, I'm just going to wait for Poor to release this mod, so I can creal it. :)

and then counterstrike time!