jkub Posted February 21, 2009 Share Posted February 21, 2009 Im trying to do a simple outputChatBox function for a a server part of a script. If the player does not have enough money it outputs the else message twice? and if he does have enough money it will output the purchased message once and right after it will output the else message also? never happend before? server side scriptVVV --Adjust Vehicle Prices BelowVVV-- bansheePrice = 20000 bulletPrice = 150000 CheetahPrice = 65000 cometPrice = 45000 elegyPrice = 25000 flashPrice = 25000 infernusPrice = 75000 jesterPrice = 35000 stratumPrice = 18000 sultanPrice = 32000 supergtPrice = 30000 turismoPrice = 80000 uranusPrice = 42000 windsorPrice = 38000 zr350Price = 50000 --Adjust Vehicle Prices Above^^^-- root = getRootElement() addEvent ( "clientRequestsBanshee", true ) addEvent ( "clientRequestsBullet", true ) addEvent ( "clientRequestsCheetah", true ) -------------------------------------------------------------------------------- shopMarker = createMarker ( -1954.3323, 295.0461, 35.4687, "cylinder", 1, 255, 0, 0, 125, root ) -------------------------------------------------------------------------------- function playerEntersShop ( marker ) if marker == shopMarker then triggerClientEvent( source, "clientRequestsOpenShopGui", root ) else end end addEventHandler ( "onPlayerMarkerHit", getRootElement(), playerEntersShop ) -------------------------------------------------------------------------------- addEventHandler ( "clientRequestsBanshee", root, function ( ) local money = getPlayerMoney ( client ) local x, y, z = getElementPosition ( client ) if money >= bansheePrice then takePlayerMoney ( client, bansheePrice ) createVehicle ( 429, x, y+5, z+1 ) outputChatBox ( "You have Purchased a Banshee", client, 100, 255, 0 ) else outputChatBox ( "You need more money for a Banshee>Cost$20000", client, 255, 255, 100 ) end end ) -------------------------------------------------------------------------------- Link to comment
50p Posted February 21, 2009 Share Posted February 21, 2009 Seems like you trigger event twice. It's not possible that "if - else" statement executes twice by itself. If it was C or C++ and you had "goto" then yes, but it's Lua. This piece of code looks OK to me or you've given us not the info you was meant to. Link to comment
Lordy Posted February 21, 2009 Share Posted February 21, 2009 I guess that he triggers the server side events on gui click and doesn't check for button state, so it triggers for both up and down. You need to give information about your triggering system too.. And btw, you don't need to add separate events for each vehicle, just add one event and pass the vehicle name as a string or something. Link to comment
50p Posted February 21, 2009 Share Posted February 21, 2009 jkub, if you use my GUI Classes, don't use :AddOnClick() twice with the same function because it will be triggered twice. Like: button:AddOnClick( A_Function ); button:AddOnClick( A_Function ); function A_Function() triggerServerEvent( "clientRequestBanshee", ...... ); end I don't check if the function you're trying to add is already added. That's why it may call it twice. Link to comment
Lordy Posted February 22, 2009 Share Posted February 22, 2009 I don't check if the function you're trying to add is already added. That's why it may call it twice. You also don't check the button state (checked the source at GUISharedFuncs:AddOnClick and Button:Create).. I really think that he just triggering it for both mouse states up and down. But still, without his client side code I cannot tell. Link to comment
50p Posted February 22, 2009 Share Posted February 22, 2009 I don't check if the function you're trying to add is already added. That's why it may call it twice. You also don't check the button state (checked the source at GUISharedFuncs:AddOnClick and Button:Create).. I really think that he just triggering it for both mouse states up and down. But still, without his client side code I cannot tell. http://development.mtasa.com/index.php? ... ntGUIClick Please note currently only the up state is supported. Enough said. Link to comment
Lordy Posted February 23, 2009 Share Posted February 23, 2009 In that case wiki lies perhaps.. because unless I add a check for state == "down" then it always triggers twice.. And I'm using "down" state not "up".. So I have no idea why wiki would say so edit: Can't test atm, but I'm not sure anymore was it the case with onClientClick or onClientGUIClick (have been using both lately ).. But I remember something triggering twice Link to comment
darkdreamingdan Posted February 23, 2009 Share Posted February 23, 2009 It was the case with onClientClick, which triggers twice as it should. Link to comment
Lordy Posted February 23, 2009 Share Posted February 23, 2009 Which still concludes to the need of his triggering mechanism to help him. But I'm afraid he has forgotten this thread anyway Link to comment
50p Posted February 23, 2009 Share Posted February 23, 2009 It was the case with onClientClick, which triggers twice as it should. Then wiki tells what's gonna be in 1.0 because I tested my classes with nightlies and it was always triggered once. This was also a reason I had to script a workaround for Dragable() method, you couldn't just click and drag because onClientGUIClick wasn't triggered for "down" state. I'd need more info to "fix what's fixed". 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