JC-MP

Scripting => Releases => Topic started by: JasonMRC on March 26, 2014, 10:20:24 pm

Title: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on March 26, 2014, 10:20:24 pm
Advanced BuyMenu
ALL Vehicles, Templates, Decals, Custom Names, Left/Right/Primary Weapons, Rank/Permission System, Saved Colors, and Appearance system!
Version 1.1

(http://s28.postimg.org/d788kr3il/Advanced_Buymenu_Splash.png) (http://s2.postimg.org/ak3ihnty1/Advanced_Buymenu_Splash.png)

Description
It seems like one of the best kept secrets in JC2-MP is the Vehicle Template and Decals. How do we apply these to vehicles in an easy and effective manner? For the longest time this has remained elusive. A large thanks goes to Eraknelo (http://www.jc-mp.com/forums/index.php?action=profile;u=22653) who taught me how to add templates. From there I just kept advancing  8)

Note that this is an Updated Release of Urik's (http://www.jc-mp.com/forums/index.php?action=profile;u=8751) BuyMenu Edit (http://www.jc-mp.com/forums/index.php/topic,3849.0.html). It's the same BuyMenu we're all accustomed to but updated with new features. Not trying to take any glory from Urik as his was a vital part in the Modern BuyMenu.

Features
(http://s13.postimg.org/8yn9zdm8n/ABMVehicles.png)
Vehicle Templates (http://wiki.jc-mp.com/Lua/Server/Vehicle/Functions/GetTemplate) & Decals (http://wiki.jc-mp.com/Lua/Server/Vehicle/Functions/GetDecal)!
Every Vehicle that can have a template or decal is already preset in the shared file. You can duplicate or remove lines as you like. For those that don't know, Decals are the Faction symbols: Military, Reapers, Roaches, and UlarBoys. Putting one of these in the appropriate field will spawn the vehicle with that symbol.

Custom Names
By default the vehicles display their Model Name. If a Template or Decal is added the name of that Template or Decal is added on to the name. If a custom name is defined then that is added on after the Model Name but before the Template and Decal.

(http://s13.postimg.org/qd7i7njdj/ABMWeapons.png)
Left & Right Hand Weapons
Some servers have dual wield, some don't. Now we all can. The weapons tab now has three tabs; Right Hand, Left Hand, and Primary. Unfortunately when actually dual wielding a weapon in each hand the left hand doesn't sync. This is something the Devs are working on.

Ranks and Permission System
Useful for restricting certain vehicles to certain people, such as staff only. Simply set a rank number on the vehicle line entry and then set the rank in the server file. By default ranks up to 5 are accepted. Only players on the 'VIP' list in the server file may buy items with a rank set. This system may be expanded easily.

Saved Colors
One of the most annoying things to me is that every time I join a server my vehicle color defaults back to white. Well Eraknelo (http://www.jc-mp.com/forums/index.php?action=profile;u=22653) also designed a save vehicle color system which is awesome. Simply set a color and the next time you login your color will be the same. By default your starting color is your Player Color. Just set a new color to change this.

(http://s13.postimg.org/5dreg5hp3/ABMAppearance.png)
Comprehensive Appearance and Cosmetics System
By combining the concepts of Jman's (http://www.jc-mp.com/forums/index.php?action=profile;u=47864) Hat Demo (http://www.jc-mp.com/forums/index.php/topic,4728.0.html) with the buymenu and SQL Database I have designed a comprehensive Appearance system. Currently there are items for the Head Slot, Covering Slot, Hair Slot, Face Slot, Neck Slot, and Back Slot. However I have coded functions in advance to handle Torso, Right Hand, Left Hand, Legs, Right Foot, and Left Foot as well. Simply add an appearance line in shared and change the slot name to the appropriate slot and your new item will show there. Each slot also has a 'Clear Slot' ability to remove any unwanted cosmetics in that slot. All items worn are saved and returned on re-entry.

Configuration
Like in the normal Buymenu, you can edit lines in the shared file.
Permissions are changed in the server file.

Please let me know of any bugs/glitches.

GitHub Download Link (https://github.com/Jasonmrc/AdvancedBuyMenu)

To see it in action, go to my server:
:: Problem Solvers FreePlay ::
IP Address: 216.108.230.23

Changelog
3-30-14 Fixed a major bug that would cause the module to crash if a player attempted to change the color of a vehicle before buying one. This was due to an improperly written function borrowed from Jman's Buymenu (https://github.com/Jman100/jc2mp-buymenu).
4-25-14 Made the three Rank system examples no longer active by default, now they are commented.

Enjoy!
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: Jman100 on March 26, 2014, 11:01:35 pm
Excellent job, I was wondering when someone was going to release this :D

Very well done!
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: misterff1 on March 27, 2014, 09:24:36 am
Ah,so you released it:)
Good. For everyone, this has been tested on my server aswell and it works flawless.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: IceDragon on March 27, 2014, 10:10:40 pm
This is very useful.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on March 30, 2014, 09:39:08 am
Update: Fixed a module crashing bug in the color changed function. Only happened if a player attempted to change the color of their vehicle before they owned one.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: Trip[ABK] on April 02, 2014, 06:03:31 pm
nice work.  busy atm, but i will be sure to try and remember to add this to our server  8)
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: flyingman1900 on April 18, 2014, 06:30:46 pm
Can I have a version of this with the VIP/donor system disabled? This is a nice menu but I don't understand how to disable the rank thing.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on April 18, 2014, 07:19:30 pm
Can I have a version of this with the VIP/donor system disabled? This is a nice menu but I don't understand how to disable the rank thing.
By default the rank system is only active on the Tuk-Tuk Rickshaw, Razak, and the Arctic hat. This is as an example.
Code: [Select]
VehicleBuyMenuEntry( 9, 0, nil, nil, nil, 1 ),
-- ^ Tuk-Tuk Rickshaw
Simply remove that 1 and it will no longer require a rank.
Code: [Select]
VehicleBuyMenuEntry( 9, 0, nil, nil, nil ),
-- ^ Tuk-Tuk Rickshaw

Vehicles are only restricted if they have a number in the last field.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: Noob-Floore on April 26, 2014, 01:21:38 am
How come everything is free with me? even though the line :  self.price = price " is set to price..

Anyone else got this?
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on April 26, 2014, 04:14:24 am
Because by default all of the vehicle's prices are set to 0. You can go in and set prices for each vehicle if you wish.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: deathdragonaw on June 21, 2014, 11:03:47 pm
How come everything is free with me? even though the line :  self.price = price " is set to price..

Anyone else got this?

For me it's also everything free, not only vehilces. Also, where can you set prices for the vehicles?
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on June 22, 2014, 08:43:05 am
The reason all vehicles are free by default is because most people prefer a freeshop, so I just removed the prices. However y'alls responses seem to indicate you want the prices in there, but with a toggle to switch between free and cost.

Advanced Buy Menu 2.0 Intended Feature List:
Prices reinstated, admin toggle controlled.
Weapons saved, admin toggle controlled.
Updated and more efficient Appearance system. Mostly backend but allows the precise tweaking of every cosmetic's position.
Vehicle UnderGlow! Using the new ClientLight system.


Would Player Settable Player colors be desired? If so, should they save or only be temporary?

Release date is TBD.
To view these features as they are made, visit my server, Problem Solvers. Vehicle UnderGlow will be available on my server tomorrow night..
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: DaAlpha on July 24, 2014, 04:23:57 am
Does every decal still have an own entry? Because I hate that so many vehicles have 4 entries each for some decals which are barely ever used. My idea was that you have a tab behind the color tab for the vehicle decal where you can set a decal which will be applied to all of your vehicles. Options should be "Default", "Military" (MilStandard), "Japan" (OldJapan), "Reapers", "Roaches" and "UlarBoys".

Also, I do not know if it is known but when using the decal Taxi or Licenseplate, you can actually remove the decals on certain vehicles like the PVD, the Bering or the Amen 69. However, if you use it on vehicles like the Leopard or the Wilforce jeeps, it will kinda glitch out. They will have their default decal but it will disappear sometimes when moving the camera or the vehicle itself. Maybe you have a nice idea how to add this no decal-feature for those certain vehicles (Do not know them by heart, think it is 6 vehicles or so). On my server I have created a seperate tab in the vehicles section for those vehicles on which this trick works properly.

And you could add an option in the initiator to disable money completely. The option should remove the price column and the money display next to the spawn button completely and should set all prices to 0. Mister did that manually and so did I, but it would be way easier if there was an option for it, since most servers probably use free buy menus anyways.

Edit: Does ABM 2.0 also include the proper names for templated vehicles, like the MV Command? I have seen this on your server and I did it for mine manually.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on July 24, 2014, 11:00:45 pm
Vehicles that support multiple Decals currently have 6 entries; None, Reapers, Roaches, Ular Boys, Military, and Japan. It is annoying having them each with their own and some of my players have asked about that. I could probably put together a dropdown or radio buttons to select custom decals.

Any Decal which isn't valid will often display no decal, but sometimes display the default decal.

I have a toggle to disable item costs. I have no intentions of removing the price columns as that seems unnecessary to me. I may give a brief lookover to see if it's easy to do, but if it requires re-writing lots of the GUI I won't be doing that.

ABM currently doesn't have the exact Vehicle names. I only have that in my common tag. I may go through and add these names before release, not sure.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: DaAlpha on July 25, 2014, 03:02:30 am
Yeah, I would really appreciate a better way of choosing decals like that dropdown menu. Mister will not like it, since he thinks those additional entries make it look like there was a huge selection of vehicles :D

I removed those columns by commenting a few lines out, where they are created and referred. I think you could do it by just putting these lines into if-conditions which check if the option is true or false, should not be that big of a deal.

I would help you with the vehicle names, but as you know, I am far away from home. When I am back on tuesday and it is not done yet, I can do it for you.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: Mike-FM on September 12, 2014, 12:58:51 am
I have a problem, it seems that the money earned it's not saved, so when the player leaves(disconnect) when he returns he has 0$ , how can i make it to save the amount of money every player has ?
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on September 12, 2014, 03:21:06 am
I have a problem, it seems that the money earned it's not saved, so when the player leaves(disconnect) when he returns he has 0$ , how can i make it to save the amount of money every player has ?
That would be because you don't have the Bank script running. You can find the Bank script in your default_scripts folder.

ABM is a Shop, it does not save player's money.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: Mike-FM on September 12, 2014, 01:13:57 pm
Thx :) and sorry for not knowing this, i'm new to this type of servers.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: deathdragonaw on October 22, 2014, 05:55:09 am
Advanced Buy Menu 2.0 Intended Feature List:
Prices reinstated, admin toggle controlled.
Weapons saved, admin toggle controlled.

How?? You neither mention this here nor in the readme. And I am also wondering, my AdvancedBuyMenuShared.lua reads:
Code: [Select]
self.price = price -- Change price to 0 to make everything free. Default: priceSo it should be already set to normal prices, or am I wrong? But everything is still for free.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on October 22, 2014, 06:34:26 am
What you quoted is referring to a future release, not the current release.

The default prices of all entries in this shop are set to 0 because at the time of release most people preferred a fully free shop. You can add prices to each thing by changing the price field in the shared file.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: SegralJr on July 27, 2015, 12:46:40 am
Is there any way to spawn vehicles without previous vehicles dissapearing?
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on October 03, 2015, 02:02:35 am
Is there any way to spawn vehicles without previous vehicles dissapearing?
Comment out the following lines
Code: [Select]
if IsValid( self.vehicles[ player:GetId() ] ) then
self.vehicles[ player:GetId() ]:Remove()
self.vehicles[ player:GetId() ] = nil
end
However I do NOT advise this unless it is a personal server for only you and your friends. Doing this will make every vehicle stay around until server restart, which will eventually slug down your server.
This is not the same thing as adding new vehicle spawns. To do that, you need to edit the spawns file in freeroam.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: Dbeast247 on December 29, 2015, 02:54:00 am
I get this Error if a player destroys there own vehicle spawned by Buy Menu then gets in a vehicle spawned by freeroam and attempts to set the color.

15:48:22 | [error] | Lua error in module AdvancedBuyMenu-master when running event ColorChanged:
15:48:22 | [error] |   Runtime Error: Non-existent object used in statement. Was it removed?
15:48:22 | [error] |   Callstack:
15:48:22 | [error] |     API function: in method GetId
15:48:22 | [error] |     server/AdvancedBuyMenu-Server.lua:107: in function <server/AdvancedBuyMenu-Server.lua:103>
15:48:22 | [error] |   Arguments:
15:48:22 | [error] |     tone2: 54, 155, 0, 255
15:48:22 | [error] |     tone1: 226, 11, 61, 255

steps to reproduce error:
1. spawn vehicle with Buy Menu
2. destroy vehicle
3. get in already spawned vehicle (ex: spawned by freeroam script)
4. attempt to set color
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: DaAlpha on December 29, 2015, 03:02:02 am
It looks to me like line 106

Code: Lua
  1. if self.vehicles[sender:GetId()] ~= nil then

has to be changed to

Code: Lua
  1. if IsValid(self.vehicles[sender:GetId()]) then

in order to make sure that the vehicle where GetId() is called on in line 107 even exists. I would recommend merging lines 106 and 107 into one anyways.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: Dbeast247 on December 29, 2015, 03:38:53 am
-snip-
That fixed it Thanks.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: JasonMRC on December 29, 2015, 09:17:21 am
Sorry, didn't see this. Thanks for the fix, DaAlpha.

This issue has been long since fixed in my files, but I haven't updated the release yet.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: th-1558 on January 17, 2016, 03:28:50 am
how do i open menu ::) ::)
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: adam1305_ on January 24, 2016, 09:13:51 pm
how do i open menu ::) ::)
Press B.


Make sure the script is unzipped and loaded in your scripts folder if it doesnt work.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: otilane on March 03, 2018, 03:18:40 pm
Any way to disable the wait time between spawns? Using it for just goofing around with friends anyways.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: SinisterRectus on March 04, 2018, 11:04:12 pm
What wait time?
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: Kesarion on July 31, 2019, 08:20:50 pm
I need some help!
I'm trying to modify the ABM so write to sql so that another script can use that info.
I have edited the executevehicle function on server side to this
Code: [Select]
function BuyMenu:ExecuteVehicle( player, item, tone1, tone2 )
    if player:GetState() == PlayerState.InVehiclePassenger then
        return false, "You cannot purchase a vehicle while in the passenger seat!"
    end

    if IsValid( self.vehicles[ player:GetId() ] ) then -- if driving a vehicle remove that
        self.vehicles[ player:GetId() ]:Remove()
        self.vehicles[ player:GetId() ] = nil
    end
    local argu = {} -- args is the table that contains all the vehicles values
    argu.model_id           = item:GetModelId()

if item:GetTemplate() ~= nil then
argu.template = item:GetTemplate()
end

if item:GetDecal() ~= nil then
argu.decal = item:GetDecal()
end
 argu.position           = player:GetPosition()
    argu.angle              = player:GetAngle()
    argu.linear_velocity    = player:GetLinearVelocity() * 1.1
    argu.enabled            = true
    argu.tone1              = tone1
    argu.tone2              = tone2

  local cmd = SQL:Command("INSERT INTO vehicles (modelid,pos,angle,col1,col2,ownerid,health,price,storage,trap,guard,insurance,template,decal) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)")--local cmd = SQL:Command("INSERT INTO vehicles (modelid,pos,angle,col1,col2,ownerid,health,price,storage,trap,guard,insurance,template,ownername,decal) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
        cmd:Bind( 1, argu.model_id )
cmd:Bind( 2, argu.position )
cmd:Bind( 3, argu.angle )
cmd:Bind( 4, argu.tone1)
cmd:Bind( 5, argu.tone2 )
cmd:Bind( 6, Player:GetSteamId().id)
cmd:Bind( 7, 1 ) -- was health
cmd:Bind( 8, 1000) -- price
cmd:Bind( 9, "|") -- was storage
cmd:Bind( 10, 0) --?  trap what are the off value
cmd:Bind( 11, 0) -- ? what are the off value guard
cmd:Bind( 12, 1) -- insurance
cmd:Bind( 13, argu.template )
--cmd:Bind( 14, Player:GetName())
cmd:Bind( 14, argu.decal )
  cmd:Execute()

    local v = Vehicle.Create( argu )
    self.vehicles[ player:GetId() ] = v

    v:SetUnoccupiedRespawnTime( nil )
v:SetDeathRemove(true)
    player:EnterVehicle( v, VehicleSeat.Driver )
    return true, ""
end

The problem appears when I try to test the script.It gives me errors that it can't write sql since its in a unaccepted format.
Also lists the PlayerFired function
and another line inside it

Code: [Select]
success, err = self:BuyVehicle( player, item, tone1, tone2 )I think that it tries to pass as arguments  the actual items of the menu itself and not the actual values that its supposed to have.

Any ideas would be greatly appreciated.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: DaAlpha on July 31, 2019, 09:07:18 pm
It would have helped if you would have given the exact error message and specified to which line in your snippet it corresponds.

That being said, I am pretty sure the issue starts in line 29 where you are trying to bind argu.position. Bind() only takes a number or a string as second argument, argu.position is userdata though (an instance of Vector3 to be exact, assigned in line 20). If you want to store it, you have to store its x, y and z values in separate columns (and of course put them back together when you retrieve them in your other module). The same applies to argu.angle, argu.tone1 and argu.tone2.

I am also pretty sure you can not bind nil values but that is exactly what's going to happen in lines 40 and 42 if item:GetDecal() or item:GetTemplate() returns nil. If you want to store an empty value, don't bind that placeholder.
Title: Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
Post by: Kesarion on July 31, 2019, 09:19:44 pm
THANK YOU !
I'll give it a try
Edit : It worked ! Thank you DaAlpha !