• Print

Author Topic: Melees and PointShop  (Read 6350 times)

0 Members and 1 Guest are viewing this topic.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Melees and PointShop
« on: July 30, 2014, 12:57:39 pm »
As I said before, I'm still pretty new to Lua and not really sure how to do everything yet

So what I want to do is add a category in the PointShop (which I already did) that will contain various melee weapons that you buy, and the one you have equipped is the one you will spawn with every round instead of spawning with the crowbar that the gamemode has you spawn with.

I went to the gamemode's init.lua file and made it so instead of giving you "weapon_crowbar" it gives you a variable, which I made MyDRWeapon
Here's the code for that part of the file
Code: Lua
  1. function GM:PlayerLoadout( ply )
  2.  
  3.         ply:Give(MyDRWeapon)
  4.  
  5. end
  6.  
  7. MyDRWeapon = "weapon_crowbar"

What I'm unsure of is what do I put in each of the weapons' files in the PointShop addon
I assumed I would need ObEquip, OnHolster, and OnSell, so I set those up for you all

Code: Lua
  1. ITEM.Name = 'NameOfWeapon'
  2. ITEM.Price = 10000
  3. ITEM.Model = 'location/of/weapon.mdl'
  4.  
  5. function ITEM:OnEquip(ply)
  6.  
  7. end
  8.  
  9. function ITEM:OnSell(ply)
  10.  
  11. end
  12.  
  13. function ITEM:OnHolster(ply)
  14.  
  15. end
Any help on this is greatly appreciated

Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Re: Melees and PointShop
« Reply #1 on: July 30, 2014, 02:39:00 pm »
What I'm unsure of is what do I put in each of the weapons' files in the PointShop addon.

Pointshop is not for your SWEP, you have to create the weapon in entities/weapons/weapon_name first, before adding it to the pointshop.
Just google and you will find lots of results about SWEP creation.

~Avoid

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Melees and PointShop
« Reply #2 on: July 30, 2014, 02:49:45 pm »
I got the weapon off of the workshop and that's not my problem. It already exists as a weapon


Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Re: Melees and PointShop
« Reply #3 on: July 30, 2014, 03:06:11 pm »
I got the weapon off of the workshop and that's not my problem. It already exists as a weapon

Sorry, then I got you wrong.

Well for the OnEquip part, take a look at those two functions:
Give()
SelectWeapon()

For the selling/holser I'd suggest something like:
StripWeapon()

Hopefully this will get you any further!
Avoid

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Melees and PointShop
« Reply #4 on: July 30, 2014, 03:32:06 pm »
Following what you suggested, I ended up with this code in my dsword.lua file (PointShop file)
Code: Lua
  1. ITEM.Name = 'Diamond Sword'
  2. ITEM.Price = 15000
  3. ITEM.Model = 'models/weapons/v_diamond_mc_sword.mdl'
  4.  
  5. function ITEM:OnEquip(ply)
  6.         ply:Give( "mc_sword_diamond" )
  7.         ply:SelectWeapon( "mc_sword_diamond" )
  8.         ply:StripWeapon( "weapon_crowbar" )
  9. end
  10.  
  11. function ITEM:OnSell(ply)
  12.         ply:StripWeapon( "mc_sword_diamond" )
  13.         ply:Give( "weapon_crowbar" )
  14.         ply:SelectWeapon( "weapon_crowbar" )
  15. end
  16.  
  17. function ITEM:OnHolster(ply)
  18.         ply:StripWeapon( "mc_sword_diamond" )
  19.         ply:Give( "weapon_crowbar" )
  20.         ply:SelectWeapon( "weapon_crowbar" )
  21. end

It worked pretty good, but there were some problems

First of all, I would only get my diamond sword if I was on the Runner team (Fixed this problem by adding "dr_allow_death_pickup 1" to server.cfg)

And my other problem is when I would spawn I would only receive the diamond sword (which is good), but then after the few second wait time for the round to start (After a round ends everybody spawns but is frozen for a few seconds before the round actually starts) I would also receive the crowbar.

Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Re: Melees and PointShop
« Reply #5 on: July 30, 2014, 03:55:40 pm »
It looks like you are running the deathrun version by Mr. Gash, open up init.lua and take a look at the Loadout of the player:

Code: [Select]
function GM:PlayerLoadout( ply )

ply:Give("weapon_crowbar")

end

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Melees and PointShop
« Reply #6 on: July 30, 2014, 04:00:07 pm »
I previously changed that to a variable on a failed attempt to do this myself
Code: [Select]
function GM:PlayerLoadout( ply )

ply:Give(MyDRWeapon)

end

MyDRWeapon = "weapon_crowbar"

My guess on fixing this would be to remove that line then add crowbar to the PointShop and make it free

(Edit: I knew that would fix my problem, but I was hoping there would be another way)

(Second edit: Problem solved thanks to Avoid's solution. Thanks!)
« Last Edit: July 30, 2014, 05:03:49 pm by Zmaster »

  • Print