Jump to content

[HELP] Saving values from client-side gui to serverside to setVehicleHandling


Dziugasc

Recommended Posts

Hello,

Basically today I wanted to finish my car performance tuning system, and I have few problems.

  1. When I start resource, it searches for vehicle that player is occupied and only runs once, so basically if player left/wasn't in car performance tuning wont work, or if vehicles were changed it will say oldCar Perfomance Tuning and will show oldCar getVehicleOriginalProperty, not new one that player is in.
  2. I tried many ways, but couldn't get working transfer of tonumber(guiText) from client to server.

CLIENT

        local theVehicle = getPedOccupiedVehicle(localPlayer) 
        window1 = guiCreateWindow(475, 225, 416, 309,  getVehicleName( theVehicle ).." VAŽIOKLĖS TUNINGAS", false)
--..................................................

addEventHandler ( "onClientGUIClick", resourceRoot,  
  function (  ) 
    if (source == button3) then
    guiSetVisible (window1, not guiGetVisible ( window1	) ) 
	showCursor(false)
	local label = tonumber(getVehicleOriginalProperty( theVehicle, "maxVelocity" )+math.round(guiScrollBarGetScrollPosition( scrollbar1 )*tonumber(getVehicleOriginalProperty( theVehicle, "maxVelocity" ))/207*2 ))
	
	local money = tonumber(guiGetText(moneyLabel)) 
if getElementType(localPlayer) ~= "player" then return end
	 if getPlayerMoney(localPlayer) >= money then
     takePlayerMoney ( money )	 
	 setElementFrozen ( theVehicle, false )
     setElementData ( theVehicle, "maxVelocity", label)
	 else
	 outputChatBox("[error] No money")
	 setElementFrozen ( theVehicle, false )
	 end
  end 
  end 

)  

SERVER I tried using getElementData, but it doesnt work :(

function getHandling(theVehicle)
local data = getElementData( theVehicle, "maxVelocity"  )
    	outputChatBox( tostring(data) )
end
addCommandHandler("get",getHandling)

function setHandling(theVehicle)
--setVehicleHandling ( theVehicle, "maxVelocity",  label)
outputChatBox(tostring(data))
end
addCommandHandler("set",setHandling)

I am trying to solve this whole morning, in future if I can I want to make this work with database to save vehicle handling to players account(garage)

Edited by Dziugasc
lua
Link to comment
21 minutes ago, Tekken said:

takePlayerMoney -- Use it ONLY server side !

to send data from client to server or vice versa use triggerClientEvent or triggerServerEvent

May you explain a bit further?

Basically, I want to make a car performance tuning shop with scrollbars, and I am at point where gui shows getOriginal

spacer.png Something like this, and when player clicks buy, it would close window and take away money and finally setVehicleHandling with my written formula.

Also, I would want to save handlings to database, but for now I try with elementData.

And my script fails where I want to transfer vMax or accelaration value from client to server (vehicle speed is defined as 240+232=472 as a number, but as a string in GUI)

I think all problems is in ElementData place, and doesn't save speed value to elementData, I have pretty much 0experience in ElementData.

Now I am trying: Client

function clickHandling(  ) 
    if (source == button3) then
    guiSetVisible (window1, not guiGetVisible ( window1	) ) 
	showCursor(false)
	setElementFrozen ( theVehicle, false )
	local vMax = tonumber(getVehicleOriginalProperty( theVehicle, "maxVelocity" )+math.round(guiScrollBarGetScrollPosition( scrollbar1 )*tonumber(getVehicleOriginalProperty( theVehicle, "maxVelocity" ))/207*2 ))
    local money = tonumber(guiGetText(label13)) 
--	triggerServerEvent('anEvent',localPlayer) 
--	triggerServerEvent('anEvent',localPlayer,vMax) 
  end 
end  
addEventHandler ( "onClientGUIClick", resourceRoot,  clickHandling) 
addEvent("getPrice",true)
addEventHandler("getPrice", resourceRoot, clickHandling)

Server

function getSelectedHandling(thePlayer) 
local theVehicle = getPedOccupiedVehicle ( thePlayer )
if getElementType(thePlayer) ~= "player" then return end
    if theVehicle then 
	triggerClientEvent (  thePlayer , "onClientGUIClick" , theVehicle ) 
      outputChatBox("you have to pay:"..money)
      
	  else
	  outputChatBox ( "You do not have a Vehicle!", thePlayer, 255, 0, 0, true )
   end
end
addEvent("anEvent", true)
addEventHandler ( "anEvent", resourceRoot,  getSelectedHandling) 

I am pretty confused right now. serverside seems not to be working

Link to comment

Client add this

triggerServerEvent('anEvent', localPlayer, vMax, money)

server do this 

function getSelectedHandling(vmax, money) 
    local theVehicle = getPedOccupiedVehicle (client )
    if theVehicle then
        outputChatBox("you have to pay:"..money)
    else
        outputChatBox ( "You do not have a Vehicle!", client, 255, 0, 0, true );
    end
end
addEvent("anEvent", true);
addEventHandler("anEvent", resourceRoot,  getSelectedHandling);

try and tell me

Link to comment
54 minutes ago, Tekken said:

Client add this




triggerServerEvent('anEvent', localPlayer, vMax, money)

server do this 




function getSelectedHandling(vmax, money) 
    local theVehicle = getPedOccupiedVehicle (client )
    if theVehicle then
        outputChatBox("you have to pay:"..money)
    else
        outputChatBox ( "You do not have a Vehicle!", client, 255, 0, 0, true );
    end
end
addEvent("anEvent", true);
addEventHandler("anEvent", resourceRoot,  getSelectedHandling);

try and tell me

It does not output in chat

EDIT: It works if I add event such as onMarkerHit, so it means anEvent doesnt work

2#, It also returns outputChatBox("you have to play:"..money); money nil value

Edited by Dziugasc
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...