mores3 Posted January 10, 2017 Share Posted January 10, 2017 Hi Someguys know me, but this time I will try do something. can you tell me what's wrong with this code and how to solve it ? working - not resers/disappears when map is loading local sX,sY = guiGetScreenSize() local counter = 15 local r,g,b = 0,255,0 function drawCounterSHI() dxDrawText("Your vehicle will change in: "..counter,0,sY*0.8,sX,sY,tocolor(r,g,b,255),2,"default","center","top",false,false,false) end function startEverything() addEventHandler("onClientRender",root,drawCounterSHI) setTimer(function() counter = counter - 1 if counter < 1 then counter = 15 r,g,b = 0,255,0 end end,1000,0) end addEvent("onCounterStart",true) addEventHandler("onCounterStart",getRootElement(),startEverything) dont working after my changes (i tried use racestates) local sX,sY = guiGetScreenSize() local counter = 15 local r,g,b = 0,255,0 function drawCounterSHI() dxDrawText("Your vehicle will change in: "..counter,0,sY*0.8,sX,sY,tocolor(r,g,b,255),2,"default","center","top",false,false,false) end function startEverything() addEventHandler("onClientRender",root,drawCounterSHI) setTimer(function() counter = counter - 1 if counter < 1 then end,1000,0) removeEventHandler("onClientRender", root, draw) if(newState == "LoadingMap") then killTimer(timer) end end addEvent("onCounterStart",true) addEventHandler("onCounterStart",getRootElement(),startEverything) Link to comment
Moderators IIYAMA Posted January 10, 2017 Moderators Share Posted January 10, 2017 A counter has to have a start / number value. local counter = 10 Link to comment
mores3 Posted January 10, 2017 Author Share Posted January 10, 2017 I dont understand It have ( local counter = 15 ) Link to comment
LoPollo Posted January 10, 2017 Share Posted January 10, 2017 (edited) This is not code lol. Check the errors in the console. There must be errors since there are some undefined variables: draw (it should be a function) timer (it should be a timer) newState (it should be a string?) Before i said this is not code because the if at line 13 is not closed (well, it get closed actually... but this leave open other things) I would sugget to use indentation so you can visually know where there are these kind of errors local sX,sY = guiGetScreenSize() local counter = 15 local r,g,b = 0,255,0 addEvent( "onCounterStart", true ) function drawCounterSHI() dxDrawText("Your vehicle will change in: "..counter,0,sY*0.8,sX,sY,tocolor(r,g,b,255),2,"default","center","top",false,false,false) end function startEverything() addEventHandler( "onClientRender", root, drawCounterSHI ) removeEventHandler("onClientRender", root, draw) --define draw setTimer( --someTimer? function() counter = counter - 1 if counter < 1 then --counter = 15 --??? end--this was missing end, 1000, 0 ) if newState == "LoadingMap" then --define newState. Is it derived from "racestates"??? killTimer(timer) --define timer. Is it the timer "someTimer"? end end addEventHandler( "onCounterStart", root, startEverything ) 3 hours ago, mores3 said: (i tried use racestates) Can you link? i can't find it Edited January 10, 2017 by LoPollo Link to comment
mores3 Posted January 11, 2017 Author Share Posted January 11, 2017 this is the link : https://wiki.multitheftauto.com/wiki/Resource:Race go to the parameters and I wanted to remove full inscription with timer I will show you later what I do Link to comment
mores3 Posted January 11, 2017 Author Share Posted January 11, 2017 I haven't understood everything I've done it , and I dont know what exactly mean define what you mean by this word ? local sX,sY = guiGetScreenSize() local counter = 15 local r,g,b = 0,255,0 addEvent( "onCounterStart", true ) function drawCounterSHI() dxDrawText("Your vehicle will change in: "..counter,0,sY*0.8,sX,sY,tocolor(r,g,b,255),2,"default","center","top",false,false,false) end function startEverything() addEventHandler( "onClientRender", root, drawCounterSHI ) removeEventHandler("onClientRender", root, draw) --define draw setTimer( --someTimer? function() counter = counter - 1 if counter < 1 then counter = 15 r,g,b = 0,255,0 end end, 1000, 0 ) if newState == "LoadingMap" then --define newState. Is it derived from "racestates"??? killTimer(timer) --define timer. Is it the timer "someTimer"? end end addEventHandler( "onCounterStart", root, startEverything ) Link to comment
marty000123 Posted January 11, 2017 Share Posted January 11, 2017 Shouldnt you use resetTimer? Link to comment
myonlake Posted January 11, 2017 Share Posted January 11, 2017 (edited) 2 hours ago, mores3 said: I haven't understood everything I've done it , and I dont know what exactly mean define what you mean by this word ? local sX,sY = guiGetScreenSize() local counter = 15 local r,g,b = 0,255,0 addEvent( "onCounterStart", true ) function drawCounterSHI() dxDrawText("Your vehicle will change in: "..counter,0,sY*0.8,sX,sY,tocolor(r,g,b,255),2,"default","center","top",false,false,false) end function startEverything() addEventHandler( "onClientRender", root, drawCounterSHI ) removeEventHandler("onClientRender", root, draw) --define draw setTimer( --someTimer? function() counter = counter - 1 if counter < 1 then counter = 15 r,g,b = 0,255,0 end end, 1000, 0 ) if newState == "LoadingMap" then --define newState. Is it derived from "racestates"??? killTimer(timer) --define timer. Is it the timer "someTimer"? end end addEventHandler( "onCounterStart", root, startEverything ) Always when you define variables, you define them like this in Lua: variable = something -- timer = setTimer(...) etc. So, your timer is never defined in a variable, so calling a variable called timer would do nothing... Same problem with newState, where is it defined? How can it know what it is, if you never define what it is? Edited January 11, 2017 by myonlake Link to comment
mores3 Posted January 11, 2017 Author Share Posted January 11, 2017 (edited) if my mind is good, have I to use one of these variables ? https://wiki.multitheftauto.com/wiki/Predefined_variables_list Edited January 11, 2017 by mores3 missing letter :) Link to comment
ViRuZGamiing Posted January 11, 2017 Share Posted January 11, 2017 define means to give it a name. for example; your code needs to use getPlayerName(thePlayer) 10 times. Instead of writing this 10 times (especially with longer lines it's better) you can give it a 'name'. name = getPlayerName(thePlayer) name is now defined as the result of getPlayerName (which returns a name as a string or false value) Another little example: outputChatBox(number) --number doesn't exist as a name, it's unDEFINED number = 7 outputChatBox(number) --outputs: 7 Hope this helps Link to comment
myonlake Posted January 12, 2017 Share Posted January 12, 2017 7 hours ago, mores3 said: if my mind is good, have I to use one of these variables ? https://wiki.multitheftauto.com/wiki/Predefined_variables_list I advise you to check out these topics to get you started with Lua: https://wiki.multitheftauto.com/wiki/Scripting_Introduction Link to comment
mores3 Posted January 12, 2017 Author Share Posted January 12, 2017 Hello guys can you tell me if it is possible ? Here I give you link from my script - watch to the end please Link to comment
ViRuZGamiing Posted January 12, 2017 Share Posted January 12, 2017 (edited) Kill the timer when you die, create it when you spawn. Edited January 12, 2017 by ViRuZGamiing Link to comment
mores3 Posted January 13, 2017 Author Share Posted January 13, 2017 no no man, I think about disapper all the timer when map is changing and ( disappear mean hmm.. like erase by rubber ) if you know what I mean Link to comment
LoPollo Posted January 13, 2017 Share Posted January 13, 2017 onRaceStateChanging will be called on race end - map change, i think. Use this to stop and reset the timer and stop drawing the text. 15 hours ago, ViRuZGamiing said: Kill the timer when you die, create it when you spawn. Even if this wasn't the answer to you prevoious question, it's a good idea to reset the timer here too, since (i guess) the timer which will make you change vehicle get resetted too (stopped on death, resetted and started on spawn)- Link to comment
mores3 Posted January 13, 2017 Author Share Posted January 13, 2017 And there start "stairs" I hope that I will do this Link to comment
mores3 Posted January 13, 2017 Author Share Posted January 13, 2017 you know guys I think about it and in my view only numbers will be enough It will be much easier And my question is : What function should I use Link to comment
LoPollo Posted January 13, 2017 Share Posted January 13, 2017 (edited) i don't understant any of your latest replies... can you explain? sorry for this 24 minutes ago, mores3 said: in my view only numbers will be enough only numbers to do what? 24 minutes ago, mores3 said: What function should I use to stop/reset/start the timer? isTimer, killTimer, setTimer are enough if that's the answer EDIT: remember to stop/start showing the text, adding or removing the onClientRender handler 1 hour ago, mores3 said: And there start "stairs" what do you mean? that from now it will not be easy? I feel dumb Edited January 13, 2017 by LoPollo Link to comment
mores3 Posted January 13, 2017 Author Share Posted January 13, 2017 of course will not be easy (stairs) and only number I mean without inscription " your vehicle will be change in: " i think it will be easier Link to comment
LoPollo Posted January 13, 2017 Share Posted January 13, 2017 oh ok did you solve the bug that keeps the timer running and the text on screen on map change? also did you fixed the timer when a player die? bug and fix are big words here... that's more completing the code Link to comment
mores3 Posted January 13, 2017 Author Share Posted January 13, 2017 I can't i'm noob I need a example or something Link to comment
ViRuZGamiing Posted January 14, 2017 Share Posted January 14, 2017 well if you have these example events that supposable would be triggered on the described moment: local vehicleIDS = { 602, 545, 496, 517, 401, 410, 518, 600, 527, 436, 589, 580, 419, 439, 533, 549, 526, 491, 474, 445, 467, 604, 426, 507, 547, 585, 405, 587, 409, 466, 550, 492, 566, 546, 540, 551, 421, 516, 529, 592, 553, 577, 488, 511, 497, 548, 563, 512, 476, 593, 447, 425, 519, 520, 460, 417, 469, 487, 513, 581, 510, 509, 522, 481, 461, 462, 448, 521, 468, 463, 586, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 485, 552, 431, 438, 437, 574, 420, 525, 408, 416, 596, 433, 597, 427, 599, 490, 432, 528, 601, 407, 428, 544, 523, 470, 598, 499, 588, 609, 403, 498, 514, 524, 423, 532, 414, 578, 443, 486, 515, 406, 531, 573, 456, 455, 459, 543, 422, 583, 482, 478, 605, 554, 530, 418, 572, 582, 413, 440, 536, 575, 534, 567, 535, 576, 412, 402, 542, 603, 475, 449, 537, 538, 570, 441, 464, 501, 465, 564, 568, 557, 424, 471, 504, 495, 457, 539, 483, 508, 571, 500, 444, 556, 429, 411, 541, 559, 415, 561, 480, 560, 562, 506, 565, 451, 434, 558, 494, 555, 502, 477, 503, 579, 400, 404, 489, 505, 479, 442, 458, 606, 607, 610, 590, 569, 611, 584, 608, 435, 450, 591, 594 } local carTimer //this might be a real event, haven't checked I don't do race stuff usually addEventHandler("onPlayerRaceSpawn", getRootElement(), function() if (isTimer(carTimer)) then killTimer(carTimer) end carTimer = setTimer(function() --also suppose that source is the driver setVehicleModel(getPedOccupiedVehicle(source), vehicleIDS[math.random(0, #vehicleIDS)]) end, 15000, 0) end) addEventHandler("onPlayerRaceWasted", getRootElement(), function() if (isTimer(carTimer)) then killTimer(carTimer) end end) Link to comment
mores3 Posted January 14, 2017 Author Share Posted January 14, 2017 (edited) it's main script example (server side) I need an example for timer ( counter ) I mean only number 15,14.....1 withouth your vehicle will be change in And I need an example for it Edited January 14, 2017 by mores3 Link to comment
ViRuZGamiing Posted January 14, 2017 Share Posted January 14, 2017 Just remove the text; "Your vehicle will change in: "..counter Link to comment
mores3 Posted January 14, 2017 Author Share Posted January 14, 2017 ok bro But I don't know what is in your penultimate post, Is it main script ??? 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