Currently the developers are putting their own money into JC2-MP to keep the servers online.

Please take a few seconds of your time and disable your AdBlock plugin for our website.

Ad revenue is not going to developers, it is used purely for covering our hosting costs.


You are also free to donate, which removes all ads from our website!

Patch 0.3 was just released! Full changelog here:

3 years ago

June 01, 2020, 09:55:53 pm

Author Topic: [Release] Advanced BuyMenu (Updated Release of BuyMenu)  (Read 29701 times)


  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
« Reply #30 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!"

    if IsValid( self.vehicles[ player:GetId() ] ) then -- if driving a vehicle remove that
        self.vehicles[ player:GetId() ]:Remove()
        self.vehicles[ player:GetId() ] = nil
    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()

if item:GetDecal() ~= nil then
argu.decal = item:GetDecal()
 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 )

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

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

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.


  • Donator
  • Jr. Member
  • *****
  • Posts: 54
    • View Profile
Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
« Reply #31 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.


  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: [Release] Advanced BuyMenu (Updated Release of BuyMenu)
« Reply #32 on: July 31, 2019, 09:19:44 pm »
I'll give it a try
Edit : It worked ! Thank you DaAlpha !
« Last Edit: August 01, 2019, 12:39:41 pm by Kesarion »