Quantcast

Jump to content

» «
Photo

Save Player Weapons

3 replies to this topic
camsy95
  • camsy95

    Player Hater

  • Members
  • Joined: 02 Jan 2011

#1

Posted 05 April 2013 - 02:14 AM Edited by camsy95, 05 April 2013 - 09:52 AM.

Hi All,

I am trying to make a script where the player is given a baseball bat and a gun when a key is pressed. However, I want to be able to remove the baseball bat and gun and give the player back their weapons when the key is pressed again.

Can anyone give me some help on how to save and recover weapons?

Thanks in advance smile.gif

unknown modder
  • unknown modder

    Player Hater

  • Members
  • Joined: 04 Jul 2012

#2

Posted 05 April 2013 - 01:11 PM

QUOTE (camsy95 @ Friday, Apr 5 2013, 02:14)
Hi All,

I am trying to make a script where the player is given a baseball bat and a gun when a key is pressed. However, I want to be able to remove the baseball bat and gun and give the player back their weapons when the key is pressed again.

Can anyone give me some help on how to save and recover weapons?

Thanks in advance smile.gif

Set up some bools, one for each weapon.
check each weapon if you have it, if you do, set that bool true, otherwise set it false
then when you want to give weapons back, remove the weapons you have, then check the bools. if its true then give them that weapon

camsy95
  • camsy95

    Player Hater

  • Members
  • Joined: 02 Jan 2011

#3

Posted 05 April 2013 - 01:34 PM

Thanks very much, I will give that a go.

pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#4

Posted 05 April 2013 - 02:29 PM

The way I would do it.

To save weapons :

Save a new instance of WeaponsCollection class, based on the player's Weapons instance member, this should keep the state of everything.
Depending on what you want to do, you may want to save that new instance to the hard drive in binary form just to free RAM.

To load weapons :

From the little I read, the best option is really loop through all weapons in WeaponCollection obejct you've just saved. And replacing weapons as they loop.
First remove the slot data them updated it.

I do think it is a better approach than a lot of boolean variables, and using bools you can't save ammo data, right ?

In any case, if you adopt the 'boolean approach' use an array of them.

I haven't tried this, this is just the way I would first start with.








0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users