-
Posts
353 -
Joined
-
Last visited
-
Days Won
3
Everything posted by LoPollo
-
I was talking about this when i said: If you have time the best thing may be rewrite the "logic" part of the code: server: The variable about the poll (question, answer1, answer2) should be here. These variables are passed then to the clients on vote start to let them vote. The check to prevent 2 votes ongoing should be there. It should accept clients votes with an event. The number of votes for one or other answer are handled serverside. It should send to clients the numbers of votes each answer have every time a new vote is made client: All the gui part should (must) be here (lol). You already have this part, with some changes you can adapt the existing one. The vote the player make is handled here, and then sent to server. You should think if you want players to have the possibility to change or remove their vote. The base of a possible new script is there. If you don't want to completely rewrite the script then big changes must be made, a rewrite could be "cleaner". Also remember to write code using english: i'm not talking about chatbox or similar, i'm talking about functions names and variables. Last but not least, in case you don't already, the names of variables and functions should be as more code-related as possible ( e.g. if i say getPlayerName i think about a function that return the name of a player element ). If you don't want to rewrite, a lot of small steps must be made... and i'm not good with lots of small things. If you find yourself more comfortable this way, then do this way, i'm not giving "orders"
-
Client: local szavon = false --is this something used to prevent double questions? it should be serverside :/ local ido = 30 local valasz = 0 local valasz2 = 0 -- I need an explanation of valasz and valasz2, if you use them to keep track of the selected answer then there are errors GUIEditor_Window = {} GUIEditor_Label = {} function szAblak(ker,v1,v2) --question, answ1, answ2, all strings if not szavon then local v_1 = v1 --answ1, useless variable local v_2 = v2 --answ2, useless variable local szavon = true local sw,sh = guiGetScreenSize() GUIEditor_Window[1] = guiCreateWindow(sw/1.48,sh/1.4,sw/3.2,sh/3.6,"Szavazás",false) --wow it's hard to me thinking relatives coord like this, wouldn't be % much easier? guiWindowSetMovable(GUIEditor_Window[1],false) guiWindowSetSizable(GUIEditor_Window[1],false) GUIEditor_Label[1] = guiCreateLabel(0.0474,0.1242,0.9161,0.2919,ker,true,GUIEditor_Window[1]) guiLabelSetHorizontalAlign(GUIEditor_Label[1],"center",true) guiSetFont(GUIEditor_Label[1],"default-bold-small") GUIEditor_Label[2] = guiCreateLabel(0.0657,0.4783,0.8759,0.1553,"1.) "..v_1,true,GUIEditor_Window[1]) GUIEditor_Label[3] = guiCreateLabel(0.0657,0.6335,0.8759,0.1491,"2.) "..v_2,true,GUIEditor_Window[1]) GUIEditor_Label[4] = guiCreateLabel(0.0474,0.8075,0.8,0.1,ido,true,GUIEditor_Window[1]) guiLabelSetColor(GUIEditor_Label[4],150,150,255) guiSetFont(GUIEditor_Label[4],"clear-normal") bindKey ("1", "down", function() guiSetFont(GUIEditor_Label[3],"clear-normal") guiLabelSetColor(GUIEditor_Label[3],255,255,255) valasz = 1 guiLabelSetColor(GUIEditor_Label[2],255,200,200) guiSetFont(GUIEditor_Label[2],"default-bold-small") end ) bindKey ("2", "down", function() guiSetFont(GUIEditor_Label[2],"default-normal") guiLabelSetColor(GUIEditor_Label[2],255,255,255) valasz2 = 2 guiLabelSetColor(GUIEditor_Label[3],255,200,200) guiSetFont(GUIEditor_Label[3],"default-bold-small") end ) lejar = setTimer( function() ido = ido-1 guiSetText(GUIEditor_Label[4], ido ) if ido == 0 then szVeg() --so it will be called 30s after szAblak end end, 1000,30) end end function szVeg() if isTimer(lejar) then --is it possible? It's useless i think killTimer(lejar) end szavon = false guiSetText(GUIEditor_Label[4], "szavazatok számlálása..." ) guiSetFont(GUIEditor_Label[2],"default-normal") guiSetFont(GUIEditor_Label[3],"default-normal") guiLabelSetColor(GUIEditor_Label[3],255,255,255) guiLabelSetColor(GUIEditor_Label[2],255,255,255) local v2 = valasz2 --if 2 was pressed this will be 2, otherwise 0 triggerServerEvent("submit",getLocalPlayer(),valasz,v2) --valasz will be 1 if 1 key got pressed, otherwise 0 unbindKey ("1", "down", function() guiSetFont(GUIEditor_Label[3],"clear-normal") guiLabelSetColor(GUIEditor_Label[3],255,255,255) valasz = 1 guiLabelSetColor(GUIEditor_Label[2],255,200,200) guiSetFont(GUIEditor_Label[2],"default-bold-small") end ) unbindKey ("2", "down", function() guiSetFont(GUIEditor_Label[2],"default-normal") guiLabelSetColor(GUIEditor_Label[2],255,255,255) valasz2 = 2 guiLabelSetColor(GUIEditor_Label[3],255,200,200) guiSetFont(GUIEditor_Label[3],"default-bold-small") end ) end addEvent("szvzas",true) --this will be called once a one player in the server makes a question addEventHandler("szvzas",root, function(question,answ1,answ2) --the handler attached to the root (resourceRoot should also work) accept 3 arguments szAblak(question,answ1,answ2) --and call the function with these paramenters end ) addEvent("valaszok",true) addEventHandler("valaszok",getRootElement(), function(v1,v2) --after 5 second from szVeg this will be triggered --v1 1 or 0, v2 2 or 0. BOTH CAN BE 0!!!! ALSO BOTH CAN BE 1 AND 2. The font wans't already set? you are not changing any passed var serverside. This doesn't make sense guiSetText(GUIEditor_Label[4], "_@/\"" ) guiSetText(GUIEditor_Label[2], guiGetText(GUIEditor_Label[2]) .. " - " .. v1 ) guiSetText(GUIEditor_Label[3], guiGetText(GUIEditor_Label[3]) .. " - " .. v2 ) if v1 > v2 then --i need explanation here. It's error if you are using them to see what localPlayer choose guiSetFont(GUIEditor_Label[2],"default-bold-small") elseif v1 < v2 then guiSetFont(GUIEditor_Label[3],"default-bold-small") end setTimer( function()--reset to default destroyElement(GUIEditor_Window[1]) szavon = false ido = 30 valasz = 0 valasz2 = 0 end, 5000, 1) end ) Server addEvent( "submit", true ) addEventHandler( "submit", root, function (v1, v2) -- 1 or 0, 2 or 0 depending on keypress setTimer( function() triggerClientEvent(root, "valaszok", resourceRoot, v1, v2) end, 5000, 1) end ) function szvzas(playerSource, cmd, theQuestion, theFirstAnswer, theSecondAnswer) --read the wiki for more infos triggerClientEvent ( root, "szvzas", resourceRoot, theQuestion, theFirstAnswer, theSecondAnswer ) --trigger on root, event "szvzas", source is the resource, and there are 3 arguments end addCommandHandler ( "k", szvzas ) Check the comments, starting from the cmdHandler serverside, following the functions. Like if you were the computer Even if clients check if a "poll" is ongoing, wouldn't be better to make the check serverside? less events triggered means less bandwidth used, more reliable, more secure, much faster. I'm talking about szavon What are valasz and valasz2 used for? check my comments. I can't understand the part Why is the event submit serverside? it will be spammed: every player will trigger it, and for every trigger it will trigger another event to the whole server!!! let's start with these. PS keep in mind the commandhandler of @Tails because once we get this working we will use it
-
This is what i was thinking about, but comma is too much used in questions. I think that semicolon ; will fit that role better. Also i don't think that turbo has its script working 100%, i'm now going to read it @Turbo777 post also the serverside, so i can see the event. I will read from the command handler and try to find if every variable is where it's supposed to be. PS: next time you make a script try to make it in english. Give every function a "logic" name, so the code will be much more easier to read since it we can guess what every line should do. Otherwise commenting your code will be helpful
-
Honestly if you need to change a window title... it's very possible that there's a better way to do it (or at least respecting mta's limits) Yep, there's no function to change the title. A workaround may be crating a temp window with the new title, move all elements of the old window to the new one, destroy the old window and assign the temp window to the old var
-
v2 will have the same value as valasz, i don't think you want this. What this event should work with? Think what the event need to know from the function that trigger it Shouldn't be the 2 parameters the 2 answers? I'm not sure... i lost myself in all these replies
-
Just so i know The differences with what @Savannah posted and mine were (talking about errors): stopSound also destroy the element, so destroyelement was useless and also should have thrown a warning I did not correct an error with bindKey parameter All here? I ask to make sure i don't make the same errors next time. But other than differences that are not errors (like tables, nilling the value instead of checking the element existence etc) i don't find anything else. Also a little note that could prevent bugs. When destroying an element (so after using stopSound, i learned that also destoys the element*) is a good practice to nil the variable, to prevent bugs due to id recycle**. I say this cause i don't think that stopSound nils the variable, since it don't have access to it
-
@Savannah ... i would check again your code, when sound is an element, it will be destroyed and then recreated. Also we solved this issue already. If this was to prevent the overlapping sound, then we don't know what @Turbo777 exactly want
-
triggerServerEvent("submit",getLocalPlayer(),valasz) valasz will be v1, but you are not givin any other argument, so v2 will be nil. triggerServerEvent("submit",getLocalPlayer(),valasz, insertV2Here)
-
A note: since it's in a default resource, keep a copy of the merged resource. It's possible that with an update the defaults resources will be overwritten.
-
It's possible that when you trigger "submit" event you are not passing the correct variables Post the line when you trigger the submit event
-
There's a security problem here. Yes, source is the player that triggered the event. But it's better to use the hidden variable "client". The 4th argument is the function that handles the keypress of the bound key (basically the function that is called when you press the key). function someFunction(firstArgument) --code end --inside some event --when using bindkey, the player who triggered the event ("client") will have its "1" key calling "someFunc" with "someArgument" when pressed bindKey(client, "1", "down", someFunction, someArgument) --example function someFunction(sSomeString) outputDebugString( "Some function has to say something: "..sSomeString ) end function submit() bindKey(client, "1", "down", someFunction, "key 1 was pressed") bindKey(client, "2", "down", someFunction, "key 2 was pressed") end addEvent( "submit", true ) addEventHandler( "submit", root, submit ) --When a player execute triggerServerEvent on "submit" event, the function "submit" will be executed: --key 1 and key 2 will be bound to "someFunction". --So if i press 1 some text will be displayed: --"Some function has to say something: key 1 was pressed" --And if key 2 is pressed another text gets outputted: --"Some function has to say something: key 2 was pressed"
-
triggerServerEvent("submit",getLocalPlayer(),valasz) --> function submit()--shouldn't the function accept an argument? --also isn't the syntax of bindKey wrong? https://wiki.multitheftauto.com/wiki/BindKey bindKey ("1", "down", function() valasz = 1 end) bindKey ("2", "down", function() valasz = 2 end) end addEvent( "submit", true ) addEventHandler( "submit", root, submit ) What szVeg should do? unbinding and binding keys? what exactly doesn't work? nothing at all? are there errors in the client conosle? are there errors in the server console?
-
What's that in the script? i guess it's not a function, but you say that's not working so it doesn't make sense What's that in the script? the timer "lejar"? explain
-
--server, line 14 function szvzas(playerSource, cmd, theQuestion, theFirstAnswer, theSecondAnswer) --read the wiki for more infos triggerClientEvent ( root, "szvzas", resourceRoot, theQuestion, theFirstAnswer, theSecondAnswer ) --trigger on root, event "szvzas", source is the resource, and there are 3 arguments end addCommandHandler ( "k", szvzas ) --commandName, handlerFunc --players will write: /k someQuestion someAnswer1 someAnswer2. Also please note that there MUST BE NO SPACES since arguments are splitted by spaces... do what you want to fix this, i don't know your plans --client, line 91 addEvent("szvzas",true) addEventHandler("szvzas",root, function(question,answ1,answ2) --the handler attached to the root (resourceRoot should also work) accept 3 arguments szAblak(question,answ1,answ2) --and call the function with these paramenters end )
-
Also please note that v_1 and v_2 are useless since there are v1 and v2 take a look here pls https://wiki.multitheftauto.com/wiki/TriggerClientEvent PS: even text is nil since it doesn't exists lol Ok i think you don't have many skills and have to learn, give me 5 minutes
-
read what i said it will be "nil" if you do tostring Also local v_1 = v1 was ok @iPrestege triggerClientEvent ( root, "szvzas", root, text) -> addEventHandler("szvzas",getRootElement(), function(question,answ1,answ2) --text, nil, nil szAblak(question,answ1,answ2) --text, nil, nil end) -> function szAblak(ker,v1,v2) --ker = text, v1 and v2 are nil -> local v_1 = v1 --both will be nil local v_2 = v2 --both will be nil
-
error is in line 18, server. You are no passing anything (so it will be nil), the event handler will receive nil and pass that value as v1, when you do local v_1 = nil it will be nil and you concatenate nil Also remove root as source PS: next time give me correct informations it was not server@20 but client@20
-
So both are looped (true as second arg of playSound) but only the 003 can be stopped? EDIT: oh i'm stupid, only 003 is looped and it's ok, but 012 can be started but can't be stopped. So you want to prevent "overlapping" right?