John Smith Posted April 19, 2014 Share Posted April 19, 2014 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 Link to comment
John Smith Posted April 19, 2014 Author Share Posted April 19, 2014 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 Link to comment
Castillo Posted April 19, 2014 Share Posted April 19, 2014 -- 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. Link to comment
John Smith Posted April 19, 2014 Author Share Posted April 19, 2014 now when i click spawn button,cursor goes away and nothing happens Link to comment
Castillo Posted April 19, 2014 Share Posted April 19, 2014 Do you have the "spawnPoints" table defined? Link to comment
John Smith Posted April 19, 2014 Author Share Posted April 19, 2014 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 Link to comment
Castillo Posted April 19, 2014 Share Posted April 19, 2014 Write "/debugscript 3" in the chatbox and see if it outputs errors when you start the resource. Link to comment
John Smith Posted April 19, 2014 Author Share Posted April 19, 2014 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' Link to comment
Castillo Posted April 20, 2014 Share Posted April 20, 2014 I missed that when I corrected your script, since you put "true", not me. Post the script about the vehicle problem. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now