Jump to content

gui button


John Smith

Recommended Posts

Posted

hi guys i wanted to ask something.

how could i make a button with text "Spawn" when player joins the game?

i dont know anything about the gui coding that's why im asking for help as im new to this.

please help

If you find my post useful or if it helped you, please like my post :)
Ingame name: ZoeN

560x95_FFFFFF_FF9900_000000_000000.png

Posted
guiCreateButton 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

tried doing that,successfully made a button,but i got few problems.

client side

button = guiCreateButton( 0.45, 0.5, 0.1, 0.1, "Spawn!", true ) 
  
function testFunction () 
triggerServerEvent("onSumoButtonSpawn",localPlayer) 
showCursor(localPlayer,true) 
end 
addEventHandler ( "onClientPlayerJoin", button, testFunction ) 
  
function otherTestFunction() 
triggerServerEvent("spawnButtonSumoPlayer",true) 
showCursor(localPlayer,false) 
end 
addEventHandler("onClientGUIClick",button,otherTestFunction) 

server side(1 part of script file)

function buttonSumoSpawn() 
fadeCamera(source,true) 
end 
addEvent("onSumoButtonSpawn",true) 
addEventHandler("onSumoButtonSpawn",root,buttonSumoSpawn) 
  
function otherSumoFunction() 
spawnPlayer ( source, unpack ( spawnPoints [ math.random ( #spawnPoints ) ] ) )--loading it from a table(other part of code) 
setCameraTarget ( source, source )  
fadeCamera(source,false) 
end 
addEvent("spawnButtonSumoPlayer",true) 
addEventHandler("spawnButtonSumoPlayer",root,otherSumoFunction) 

When i come ingame,i see a button which says "Spawn!" but i dont see cursor,and when i get cursor with F8 key,it doesnt do anything when i click the button.

please help me

If you find my post useful or if it helped you, please like my post :)
Ingame name: ZoeN

560x95_FFFFFF_FF9900_000000_000000.png

Posted

-- client side:

button = guiCreateButton( 0.45, 0.5, 0.1, 0.1, "Spawn!", true ) 
fadeCamera ( false ) 
showCursor ( true ) 
  
function otherTestFunction ( ) 
    triggerServerEvent ( "spawnButtonSumoPlayer",true ) 
    showCursor ( false ) 
end 
addEventHandler ( "onClientGUIClick", button, otherTestFunction, false ) 

-- server side:

function otherSumoFunction ( ) 
    spawnPlayer ( source, unpack ( spawnPoints [ math.random ( #spawnPoints ) ] ) ) 
    setCameraTarget ( source, source ) 
    fadeCamera ( source, true ) 
end 
addEvent ( "spawnButtonSumoPlayer", true ) 
addEventHandler ( "spawnButtonSumoPlayer",root,otherSumoFunction ) 

Problems I found:

1º The event "onClientPlayerJoin" is only triggered by remote players, you should use "onClientResourceStart" instead.

2º showCursor has no player argument when used client side.

3º If you use "false" in fadeCamera, it'll fade the camera out, meaning you won't be able to see.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Do you have the "spawnPoints" table defined?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
spawnPoints = 
{ 
    [ 1 ] = { 2702.2, -3018.6, 99.9 }, 
    [ 2 ] = { 2696.7, -3015.9, 99.9 } 
} 

idk if its defined in here,but before i just spawned normally with this table without problems so it must be defined

If you find my post useful or if it helped you, please like my post :)
Ingame name: ZoeN

560x95_FFFFFF_FF9900_000000_000000.png

Posted

Write "/debugscript 3" in the chatbox and see if it outputs errors when you start the resource.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

error was bad argument triggerServerEvent instead of element it got boolean(true)

you've put this line in script which confused me as soon as i saw your script but i've trusted u so i didn't change the line

triggerServerEvent ( "spawnButtonSumoPlayer",true ) 

but it should be

triggerServerEvent ( "spawnButtonSumoPlayer",localPlayer ) 

anyway,you've fixed my other problems so,thank you very much!

1 more question.

could you please tell me whats wrong in here?

im trying to warp player into vehicle when he spawns

warpPedIntoVehicle ( source, vehicle ) 

vehicle is defined in here

local vehicle = createVehicle ( model, unpack ( spawnPoints [ math.random ( #spawnPoints ) ] ) ) 

error is this

[01:26:20] WARNING: [gamemodes]\[sumo]\sumo\load_map\spawn_s.lua:47: Bad argument @ 'warpPedIntoVehicle'

If you find my post useful or if it helped you, please like my post :)
Ingame name: ZoeN

560x95_FFFFFF_FF9900_000000_000000.png

Posted

I missed that when I corrected your script, since you put "true", not me.

Post the script about the vehicle problem.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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