Jump to content

Help me buy gui


Recommended Posts

Hello :D

I learned a bit GUI , but i added to GMS script Buy window and i deletd the another.It didnt works . I started it and when i go to server nothing happeneds . Can you help me ? pls . Here is my code:

function guiToggleVisible ( )
 
if ( guiGetVisible ( myWindow ) == true ) then           
guiSetVisible ( myWindow, false )
showCursor ( false )
else      
guiSetVisible ( myWindow, true )
showCursor ( true )
end
end
 
myWindow = guiCreateWindow ( 0, 0, .10, .10, "Buy window", true )
local tabPanel = guiCreateTabPanel ( 0, 10.0, 6, 2, true, myWindow )
local tabCommands = guiCreateTab( "Buy", tabPanel )
 
Buynitro_button = guiCreateButton( 0.1, 0.1, 0.50, 0.10, "Buy nitro", true, tabCommands )
Buyrepair_button = guiCreateButton( 0.1, 0.2, 0.50, 0.10, "Buy repair", true, tabCommands )
exit1_button = guiCreateButton( 0.30, 0.85, 0.5, 0.03, "Close Panel (F4)", true, tabCommands )
 
bindKey ( "u", "down", guiToggleVisible )
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
function ( )
if (source == exit1_button) then
guiSetVisible( myWindow, false )
showCursor( false )
end  
end
)
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
function ( )
if (source == buynitro_button) then
getPlayerMoney(player) > 100 then
local vehicle = getPedOccupiedVehicle(player)
if vehicle then 
addVehicleUpgrade(vehicle, 1010)
takePlayerMoney(player, 100)
outputChatBox("You've bought a nitro", player, 0, 222, 0, true)
else 
outputChatBox("You are not in a vehicle", player, 222, 0, 0, true) 
end
else 
outputChatBox("Not enough cash, nitro costs 100", player, 222, 0, 0, true) 
end
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
function ( )
if (source == Buyrepair_button) then
if getPlayerMoney(player) > 100 then
local vehicle = getPedOccupiedVehicle(player)
if vehicle then 
fixVehicle(vehicle) 
takePlayerMoney(player, 100)
outputChatBox("You've bought a repair", player, 0, 222, 0, true)
else 
outputChatBox("You are not in a vehicle", player, 222, 0, 0, true) 
end
else 
outputChatBox("Not enough cash, repair costs 100 ", player, 222, 0, 0, true) 
end
end
end 
)

Can anyone help me pls ?

Edited by Guest
Link to comment

Client side outputChatBox = outputChatBox (message, r, g, b)

so no need to have outputChatBox (message, player, r, g, b)

also if calling a player required function, try using getLocalPlayer() or before the script add: player = getLocalPlayer()

Link to comment

I maked it with Gui editor

i think i worked on it 3 or 4 hours , but it didnt works -.-'

Can anyone help me ?

When i type debugscript 3 it gives:

[16:17:33] Starting resources...............
[16:17:34] Server started and is ready to accept connections!
[16:17:36] start: Requested by Console
[16:17:36] Starting buy
[16:17:36] SCRIPT ERROR: ...iles/MTA San Andreas/server/mods/deathmatch/resources/buy/Untitled 1.lua:13: unexpected symbol near '>'
[16:17:36] WARNING: Loading script failed: ...iles/MTA San Andreas/server/mods/deathmatch/resources/buy/Untitled 1.lua:13: unexpected symbol near '>'
[16:17:36] start: Resource 'buy' started
[16:18:10] debugscript: Incorrect client type for this command

Here is my code :

GUIEditor_Window = {}
GUIEditor_Button = {}
GUIEditor_Memo = {}
 
GUIEditor_Window[1] = guiCreateWindow(161,102,390,342,"Buy window",false)
GUIEditor_Button[1] = guiCreateButton(31,25,90,18,"Buy nitro",false,GUIEditor_Window[1])
GUIEditor_Button[2] = guiCreateButton(30,46,91,17,"Buy repair",false,GUIEditor_Window[1])
GUIEditor_Memo[1] = guiCreateMemo(131,25,209,50,"Press Buy nitro to buy a niro\nPress buy repair to buy a repair",false,GUIEditor_Window[1])
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
function ( )
if (source == GUIEditor_Button[1]) then
getPlayerMoney(player) > 100 then
local vehicle = getPedOccupiedVehicle(player)
local player = getLocalPlayer()
if vehicle then 
addVehicleUpgrade(vehicle, 1010)
takePlayerMoney(player, 100)
outputChatBox("You've bought a nitro", player, 0, 222, 0, true)
else 
outputChatBox("You are not in a vehicle", player, 222, 0, 0, true) 
end
else 
outputChatBox("Not enough cash, nitro costs $100", player, 222, 0, 0, true) 
end
 
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
function ( )
if (source == GUIEditor_Button[2]) then
if getPlayerMoney(player) > 100 then
local vehicle = getPedOccupiedVehicle(player)
local player = getLocalPlayer()
if vehicle then 
fixVehicle(vehicle) 
takePlayerMoney(player, 100)
outputChatBox("You've bought a repair", player, 0, 222, 0, true)
else 
outputChatBox("You are not in a vehicle", player, 222, 0, 0, true) 
end
else 
outputChatBox("Not enough cash, repair costs 100 ", player, 222, 0, 0, true) 
end
end
end 
)

Edited by Guest
Link to comment

I used outputChatBox lol

Client side outputChatBox = outputChatBox (message, r, g, b)

so no need to have outputChatBox (message, player, r, g, b)

also if calling a player required function, try using getLocalPlayer() or before the script add: player = getLocalPlayer()

I used that in red ,it should to be outputChatBox = outputChatBox (message, r, g, b) ? °-°

And i added :

player = getLocalPlayer()

Link to comment

well, i made it for you but you must know that i wont make anything u post here so start to learn by yourself :)

client side:

GUIEditor_Window = {}
GUIEditor_Button = {}
GUIEditor_Memo = {}
 
GUIEditor_Window[1] = guiCreateWindow(161,102,390,342,"Buy window",false)
GUIEditor_Button[1] = guiCreateButton(31,25,90,18,"Buy nitro",false,GUIEditor_Window[1])
GUIEditor_Button[2] = guiCreateButton(30,46,91,17,"Buy repair",false,GUIEditor_Window[1])
GUIEditor_Memo[1] = guiCreateMemo(131,25,209,50,"Press Buy nitro to buy a niro\nPress buy repair to buy a repair",false,GUIEditor_Window[1])
guiSetVisible(GUIEditor_Window[1], false)
 
function guiToggleVisible ( )
 
if ( guiGetVisible ( GUIEditor_Window[1] ) == true ) then           
guiSetVisible(GUIEditor_Window[1], false)
showCursor ( false )
else 
guiSetVisible(GUIEditor_Window[1], true)
showCursor ( true )
end
end
bindKey ( "M", "down", guiToggleVisible )
 
function fixv()
triggerServerEvent("fixRequest", getLocalPlayer())
end
addEventHandler("onClientGUIClick",GUIEditor_Button[2],fixv,false)
 
function nitro()
triggerServerEvent("nitro", getLocalPlayer())
end
addEventHandler("onClientGUIClick",GUIEditor_Button[1],nitro,false)

server side:

addEvent("nitro", true)
addEventHandler("nitro", getRootElement(),
function()
if isPedInVehicle(source) then
if ( getPlayerMoney (source) >= 7000 ) then
takePlayerMoney(source, 7000)
addVehicleUpgrade(getPedOccupiedVehicle(source),1010)
outputChatBox("Nitro Successfully added", source, 255, 255, 0, true)
else
outputChatBox("Not enough money.", source, 255, 0, 0, true)
end     
else
outputChatBox("You are not in a vehicle", source, 255, 0, 0, true)
end
end
)
 
addEvent("fixRequest", true)
addEventHandler("fixRequest", getRootElement(),
function()
if isPedInVehicle(source) then
if ( getPlayerMoney (source) >= 20000 ) then
takePlayerMoney(source, 20000)
fixVehicle(getPedOccupiedVehicle(source))
outputChatBox("Vehicle Successfully Fixed", source, 255, 255, 0, true)
else
outputChatBox("Not enough money.", source, 255, 0, 0, true)
end     
else
outputChatBox("You are not in a vehicle", source, 255, 0, 0, true)
end
end
)

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...