How to give player a custom gun;

The best and quickest support by a group of top-notch editing specialists, guaranteed!

Moderator: Forum Guards

How to give player a custom gun;

Postby bambi » Sun Feb 12, 12 4:14 am

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);
      
   }
}
Image
bambi
Regular
 
Posts: 476
Joined: Sun Nov 27, 05 7:26 pm

Postby Poor » Sun Feb 12, 12 5:40 am

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.
Poor
Poster
 
Posts: 190
Joined: Tue Jan 04, 11 7:42 pm

Postby bambi » Sun Feb 12, 12 5:46 am

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!
Last edited by bambi on Sun Feb 12, 12 6:08 am, edited 2 times in total.
Image
bambi
Regular
 
Posts: 476
Joined: Sun Nov 27, 05 7:26 pm

Postby Dae » Sun Feb 12, 12 10:24 am

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".
User avatar
Dae
Alpha
 
Posts: 12086
Joined: Sat Sep 06, 03 4:40 pm

Postby Poor » Sun Feb 12, 12 4:23 pm

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.
Poor
Poster
 
Posts: 190
Joined: Tue Jan 04, 11 7:42 pm

Postby ~ô¿ô~Nobody~ » Sun Feb 12, 12 8:12 pm

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
Nobody is perfect...
------------------------------
Longc[A]t wrote:I still think Dae is a russian spambot.

~[A]Daedalus~ wrote:There will be a day when my patience goes away and you, along with all who rant with you, will get banned.

ô¿ô¥[GODZ]¥NOCHANC wrote:I can ban any one I want ANY time I want. You have no rights here.
User avatar
~ô¿ô~Nobody~
Alpha
 
Posts: 2520
Joined: Fri Dec 31, 04 3:20 pm
Location: Proclarush Taonas

Postby bambi » Sun Feb 12, 12 8:33 pm

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!
Image
bambi
Regular
 
Posts: 476
Joined: Sun Nov 27, 05 7:26 pm


Return to Editing issues

Who is online

Users browsing this forum: No registered users and 5 guests