codeluaeveryday Posted September 30, 2011 Share Posted September 30, 2011 Hey guys, I am trying to create a script for race which allows me to freeze all players at once, I could use setplayerfrozen, but i'm too dumb to be able to make it apply to all players (please explain that too me). I have tried many things, like if separate from else, now i'm trying elseif, I have never used if, else, then. now it's a good time to learn. i woke up and thought maybe if getGameSpeed = 1 is wrong, maybe getGameSpeed ("1")? function freeze() if getGameSpeed = 1 local name = getPlayerName(source) setGameSpeed(0) outputChatBox(name.." has froze all players!", source, 255,0,0) elseif getGameSpeed = 0 outputChatBox("All players are already frozen!", thePlayer, 255,0,0) end end addCommandHandler("freezeall", freeze) function unfreeze() if getGameSpeed = 0 local name = getPlayerName(source) setGameSpeed(0) outputChatbox(name.." has unfroze all players!",source,0,255,0) elseif getGameSpeed = 1 outputChatBox("Players are not frozen!",thePlayer,0,255,0) end end addCommandHandler("unfreezeall", unfreeze) Link to comment
TAPL Posted September 30, 2011 Share Posted September 30, 2011 (edited) function freeze(thePlayer) if (getGameSpeed() == 1) then local name = getPlayerName(thePlayer) setGameSpeed(0) outputChatBox(name.." has froze all players!", root, 255,0,0) else outputChatBox("All players are already frozen!", thePlayer, 255,0,0) end end addCommandHandler("freezeall", freeze) function unfreeze(thePlayer) if (getGameSpeed() == 0) then local name = getPlayerName(thePlayer) setGameSpeed(1) outputChatbox(name.." has unfroze all players!",root,0,255,0) else outputChatBox("Players are not frozen!",thePlayer,0,255,0) end end addCommandHandler("unfreezeall", unfreeze) Edited October 1, 2011 by Guest Link to comment
codeluaeveryday Posted September 30, 2011 Author Share Posted September 30, 2011 Thank you TAPL, i have always been a fan of your War Panel for your basemode, excellent. The setting speed works perfectly. The outputting doesnt, when i tried outputChatbox(name.." has unfroze all players!",source,0,255,0) else outputChatBox("Players are not frozen!",thePlayer,0,255,0) i originally wanted the second output to output to the player (visibility). while the first to goto all players. but, with the new one it doesnt output at all. Maybe the way i set it out? Link to comment
Discord Moderators Zango Posted September 30, 2011 Discord Moderators Share Posted September 30, 2011 (edited) To answer your original post, TAPL was faster than me A rather fixed version of your script. setGameSpeed takes an integer between 0 and 10, no strings needed. I am sure you could've fixed this script yourself by trial and error over time, but you can save some time by looking at what each line does. For example = assigns a value, and == compares it, as you should know. Variables don't work by magic, you can't call one and expect a certain result when you haven't defined it. Perhaps you should try the Scripting Introduction. function freeze(player) if (getGameSpeed() == 1) then local name = getPlayerName(player) setGameSpeed(0) outputChatBox(name.." has froze all players!", root, 255,0,0) elseif (getGameSpeed() == 0) then outputChatBox("All players are already frozen!", player, 255,0,0) end end addCommandHandler("freezeall", freeze) function unfreeze(player) if (getGameSpeed() == 0) then local name = getPlayerName(player) setGameSpeed(1) outputChatbox(name.." has unfroze all players!", root,0,255,0) elseif (getGameSpeed() == 1) then outputChatBox("Players are not frozen!", player,0,255,0) end end addCommandHandler("unfreezeall", unfreeze) This is how I'd do it, using setElementFrozen as you mentioned. It's possible by looping through all players, and freezing/unfreezing them. local bFreeze = false function toggleFreeze (player, cmd) bFreeze = not bFreeze for i,pl in ipairs(getElementsByType('player')) do setElementFrozen (pl, bFreeze) end if bFreeze then outputChatBox (('%s has frozen all players!'):format(getPlayerName(player)), root, 255, 0, 0) else outputChatBox (('%s has unfrozen all players!'):format(getPlayerName(player)), root, 0, 255, 0) end end addCommandHandler ('freezeall', toggleFreeze) Edited September 30, 2011 by Guest Link to comment
TAPL Posted September 30, 2011 Share Posted September 30, 2011 check my post i change the code 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