gghvcffcv Posted March 2, 2014 Share Posted March 2, 2014 Sorry For posting here again, i got a problem that i don't understand, The problem is that i want to destroy the marker when the player Press Buy But when i put the Elemen in this case ( theMarker) There is an error that says Argument nil, If you can help me, Thanks!! Server: function consoleCreateMarker ( thePlayer, commandName ) if ( thePlayer ) then local x, y, z = getElementPosition ( thePlayer ) local theMarker = createMarker ( x + 0, y + 0, z - 1, "cylinder", 1.5, 255, 0, 0, 170 ) if ( theMarker ) then outputConsole ( "Marker created successfully", thePlayer ) else outputConsole ( "Failed to create marker", thePlayer ) end end end addCommandHandler ( "sell", consoleCreateMarker ) function greetingHandler ( ) destroyElement ( theMarker ) end addEvent( "onGreeting", true ) addEventHandler( "onGreeting", root, greetingHandler ) Client: addEventHandler("onClientMarkerHit", resourceRoot, function( hitElement ) if ( hitElement == localPlayer ) then panel = guiCreateWindow(471, 143, 493, 575, "Arms Dealer", false) guiWindowSetSizable(panel, false) comprar = guiCreateButton(35, 476, 143, 65, "Buy", false, panel) guiSetFont(comprar, "sa-header") cerrar = guiCreateButton(311, 476, 143, 65, "Close", false, panel) guiSetFont(cerrar, "sa-header") arma1 = guiCreateButton(34, 38, 423, 54, "M4 2000 $", false, panel) guiSetFont(arma1, "sa-header") arma2 = guiCreateButton(34, 112, 423, 54, "AK-47 2000 $", false, panel) guiSetFont(arma2, "sa-header") francotirador = guiCreateButton(34, 358, 423, 54, "Sniper", false, panel) guiSetFont(francotirador, "sa-header") escopeta = guiCreateButton(34, 276, 423, 54, "CombatShotgun 1000 $", false, panel) guiSetFont(escopeta, "sa-header") granada = guiCreateButton(34, 194, 423, 54, "Grenade 500 $", false, panel) guiSetFont(granada, "sa-header") showCursor ( true ) addEventHandler ("onClientGUIClick", comprar, comprarr, false ) addEventHandler ("onClientGUIClick", cerrar, cerrarr, false ) addEventHandler ("onClientGUIClick", arma1, arma11, false ) addEventHandler ("onClientGUIClick", arma2, arma22, false ) addEventHandler ("onClientGUIClick", arma3, arma33, false ) addEventHandler ("onClientGUIClick", arma4, arma44, false ) addEventHandler ("onClientGUIClick", arma5, arma55, false ) end end ) function cerrarr ( hitElement ) showCursor ( false ) guiSetVisible (panel, not guiGetVisible ( panel ) ) end addEventHandler ( "onClientGUIClick", cerrarr, true ) function comprarr ( hitElement ) showCursor ( false ) guiSetVisible (panel, not guiGetVisible ( panel ) ) triggerServerEvent ( "onGreeting", localPlayer ) end addEventHandler( "onClientGUIClick", comprarr, true ) Link to comment
Arsilex Posted March 2, 2014 Share Posted March 2, 2014 function consoleCreateMarker ( thePlayer, commandName ) if ( thePlayer ) then local x, y, z = getElementPosition ( thePlayer ) theMarker = createMarker ( x + 0, y + 0, z - 1, "cylinder", 1.5, 255, 0, 0, 170 ) if ( theMarker ) then outputConsole ( "Marker created successfully", thePlayer ) else outputConsole ( "Failed to create marker", thePlayer ) end end end addCommandHandler ( "sell", consoleCreateMarker ) function greetingHandler ( ) destroyElement ( theMarker ) end addEvent( "onGreeting", true ) addEventHandler( "onGreeting", root, greetingHandler ) Link to comment
gghvcffcv Posted March 2, 2014 Author Share Posted March 2, 2014 Thanks you very much Link to comment
Moderators Citizen Posted March 2, 2014 Moderators Share Posted March 2, 2014 function consoleCreateMarker ( thePlayer, commandName ) if ( thePlayer ) then local x, y, z = getElementPosition ( thePlayer ) theMarker = createMarker ( x + 0, y + 0, z - 1, "cylinder", 1.5, 255, 0, 0, 170 ) if ( theMarker ) then outputConsole ( "Marker created successfully", thePlayer ) else outputConsole ( "Failed to create marker", thePlayer ) end end end addCommandHandler ( "sell", consoleCreateMarker ) function greetingHandler ( ) destroyElement ( theMarker ) end addEvent( "onGreeting", true ) addEventHandler( "onGreeting", root, greetingHandler ) OMG ! I can't believe you just made a global to fix stuff on server side :facepalm: What if player2 uses the /sell command right after player1 ? Yeah, the marker of player1 will never be destroyed and will stay untill the server restart. Still thinking it was a good solution ? I don't think so ... And btw why did you do x + 0 and y + 0 ? Also the gui will be shown on every markers created by that same resource ... Here's a real solution: Server: function consoleCreateMarker ( thePlayer, commandName ) if ( thePlayer ) then local x, y, z = getElementPosition ( thePlayer ) local theMarker = createMarker ( x, y, z - 1, "cylinder", 1.5, 255, 0, 0, 170 ) if ( theMarker ) then setElementData(theMarker, "markerType", "WeaponShop") outputConsole ( "Marker created successfully", thePlayer ) else outputConsole ( "Failed to create marker", thePlayer ) end end end addCommandHandler ( "sell", consoleCreateMarker ) function onPlayerBuyWeaponHandler ( marker ) if not marker then return end destroyElement ( marker ) end addEvent( "onPlayerBuyWeapon", true ) addEventHandler( "onPlayerBuyWeapon", root, onPlayerBuyWeaponHandler ) Client: local inMarker addEventHandler("onClientMarkerLeave", resourceRoot, function( hitElement ) if not hitElement == localPlayer then return end inMarker = nil end) addEventHandler("onClientMarkerLeave", resourceRoot, function( hitElement ) if not hitElement == localPlayer then return end inMarker = source end) addEventHandler("onClientMarkerHit", resourceRoot, function( hitElement ) local markerType = getElementData(source, "markerType") if hitElement == localPlayer and markerType and markerType == "WeaponShop" then panel = guiCreateWindow(471, 143, 493, 575, "Arms Dealer", false) guiWindowSetSizable(panel, false) comprar = guiCreateButton(35, 476, 143, 65, "Buy", false, panel) guiSetFont(comprar, "sa-header") cerrar = guiCreateButton(311, 476, 143, 65, "Close", false, panel) guiSetFont(cerrar, "sa-header") arma1 = guiCreateButton(34, 38, 423, 54, "M4 2000 $", false, panel) guiSetFont(arma1, "sa-header") arma2 = guiCreateButton(34, 112, 423, 54, "AK-47 2000 $", false, panel) guiSetFont(arma2, "sa-header") francotirador = guiCreateButton(34, 358, 423, 54, "Sniper", false, panel) guiSetFont(francotirador, "sa-header") escopeta = guiCreateButton(34, 276, 423, 54, "CombatShotgun 1000 $", false, panel) guiSetFont(escopeta, "sa-header") granada = guiCreateButton(34, 194, 423, 54, "Grenade 500 $", false, panel) guiSetFont(granada, "sa-header") showCursor ( true ) addEventHandler ("onClientGUIClick", comprar, comprarr, false ) addEventHandler ("onClientGUIClick", cerrar, cerrarr, false ) addEventHandler ("onClientGUIClick", arma1, arma11, false ) addEventHandler ("onClientGUIClick", arma2, arma22, false ) addEventHandler ("onClientGUIClick", arma3, arma33, false ) addEventHandler ("onClientGUIClick", arma4, arma44, false ) addEventHandler ("onClientGUIClick", arma5, arma55, false ) end end) function cerrarr ( hitElement ) showCursor ( false ) guiSetVisible (panel, false ) end function comprarr ( hitElement ) showCursor ( false ) guiSetVisible (panel, false ) triggerServerEvent ( "onPlayerBuyWeapon", localPlayer, inMarker) end 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