Overkillz Posted September 15, 2014 Posted September 15, 2014 Hey guys, I will like to make a "Toggle 3 different images" status = 1 function DaFvck() if status==1 then dxDrawImage(posx,posy*0.97,height,height, "img/lala.png",0,0,0,tocolor(255,255,255,255)) outputChatBox("lala1 Test", 255, 255, 255, true) status = 2 elseif status==2 then dxDrawImage(posx,posy*0.97,height,height, "img/lala2.png",0,0,0,tocolor(255,255,255,255)) outputChatBox("lala2 test", 255, 255, 255, true) status = 3 else dxDrawImage(posx,posy*0.97,height,height, "img/lala3.png",0,0,0,tocolor(255,255,255,255)) outputChatBox('lala3 Test', 255, 255, 255, true) status = 1 end end addCommandHandler("logo", DaFvck) It works, but it dissapear in less than a second I write ./logo and it show the new image and in the same moment hide it. I hope u can help me. Thanks
undefined Posted September 15, 2014 Posted September 15, 2014 (edited) Use addEventHandler -- With onClientRender Edit: Try this. function DaFvck() if not status then status = 1 end if status == 1 then dxDrawImage(posx,posy*0.97,height,height, "img/lala.png",0,0,0,tocolor(255,255,255,255)) elseif status == 2 then dxDrawImage(posx,posy*0.97,height,height, "img/lala2.png",0,0,0,tocolor(255,255,255,255)) else dxDrawImage(posx,posy*0.97,height,height, "img/lala3.png",0,0,0,tocolor(255,255,255,255)) end end addEventHandler("onClientRender", root, DaFvck) addCommandHandler("logo", function(cmd, amount) if not amount then outputChatBox("Use /logo ", 255, 20, 0) return end amount = tonumber(amount) if type(amount) ~= "number" then outputChatBox("Amount type must be number!", 255, 20, 0) return end if amount < 1 or amount > 3 then outputChatBox("Amount must be between 1 and 3!", 255, 20, 0) return end if status == amount then outputChatBox("Your status is already "..amount.."!", 255, 20, 0) return end status = amount outputChatBox("Your new status is "..amount..".", 255, 168, 0) end) Edited September 15, 2014 by Guest
Overkillz Posted September 15, 2014 Author Posted September 15, 2014 Use addEventHandler -- With onClientRender Now it is changing every milisecond to the next image status = 1 function DaFvck() if status==1 then dxDrawImage(posx,posy*0.97,height,height, "img/lala.png",0,0,0,tocolor(255,255,255,255)) outputChatBox("lala1 Test", 255, 255, 255, true) status = 2 elseif status==2 then dxDrawImage(posx,posy*0.97,height,height, "img/lala2.png",0,0,0,tocolor(255,255,255,255)) outputChatBox("lala2 test", 255, 255, 255, true) status = 3 else dxDrawImage(posx,posy*0.97,height,height, "img/lala3.png",0,0,0,tocolor(255,255,255,255)) outputChatBox('lala3 Test', 255, 255, 255, true) status = 1 end end addEventHandler ( "onClientRender", root, DaFvck) addCommandHandler("logo", DaFvck) PS: I changed the outputChatBox
Et-win Posted September 15, 2014 Posted September 15, 2014 Use this to change the status: setTimer(function() if (status > 2) then status = 1 else status = status + 1 end end, time-in-milliseconds, 0) This will change your image every second you fill in. 'onClientRender' will be executed on every FRAME, that's why it changes way too fast. (Don't forget to remove "status = ..." out of the function)
Overkillz Posted September 15, 2014 Author Posted September 15, 2014 Use this to change the status: setTimer(function() if (status > 2) then status = 1 else status = status + 1 end end, time-in-milliseconds, 0) This will change your image every second you fill in. 'onClientRender' will be executed on every FRAME, that's why it changes way too fast. (Don't forget to remove "status = ..." out of the function) But I won't change my image every second. I want that the guys can change the image using /command and the image don't change, just if they want, can use /command That is the reason why I want to do 3 images toggeable.
Et-win Posted September 15, 2014 Posted September 15, 2014 function test(tCommand, tValue) if (tonumber(tValue) ~= nil) and (tonumber(tValue) > 0) and (tonumber(tValue) <= 3) then status = tonumber(tValue) end end addCommandHandler("logo", test) If you read wiki you would have know this.
Overkillz Posted September 15, 2014 Author Posted September 15, 2014 function test(tCommand, tValue) if (tonumber(tValue) ~= nil) and (tonumber(tValue) > 0) and (tonumber(tValue) <= 3) then status = tonumber(tValue) end end addCommandHandler("logo", test) If you read wiki you would have know this. Then i should use variables for example local status = 1 (dxdrawimage....etc) local status = 2 (dxdrawimage....etc) local status = 3 (dxdrawimage....etc) And after the code that u wrote ? Sorry for my a lot of questions, I started with script few time ago ;(
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