Home » Renegade Discussions » Mod Forum » Lua sleep()
Re: Lua sleep() [message #450319 is a reply to message #450307] |
Fri, 29 July 2011 20:35 |
|
Intradox
Messages: 60 Registered: February 2011 Location: United States
Karma:
|
Recruit |
|
|
Ok, so I tried doing this:
function printf(...)
io.write(string.format(unpack(arg)))
end
function InputConsole(...)
Console_Input(string.format(unpack(arg)))
end
function ScriptName()
return "SampleTimer"
end
function ScriptParams()
return ""
end
function Created(ID, obj)
playlist = {"ammoclip.mp3", "command&conquer.mp3", "defunkt.mp3", "in the line of fire.mp3", "level0_pt1_music.mp3", "level 0 hero.mp3", "level 0 nod base.mp3", "level 0 tank.mp3", "level 0 tiberium.mp3", "mechmansrevenge.mp3", "moveit.mp3", "onyourfeet.mp3", "raveshaw_act on instinct.mp3", "renegadejungle.mp3", "sakura battle theme.mp3", "sakura_dogfight.mp3", "sneakattack.mp3", "sniper.mp3", "stopthemagain.mp3"}
playlisttimes = {193, 175, 163, 235, 26, 31, 54, 51, 47, 227, 121, 234, 148, 141, 240, 280, 228, 196, 234}
Start_Timer(ID, obj, 193, 1)
end
local currentsong = nil
function Timer_Expired(ID, obj, num)
if song == nil then
song = 0
end
if num == 1 then
if Get_Player_Count() > 0 then
if playlist[song + 1] ~= nil then
song = song + 1
else
song = 1
end
InputConsole("msg [DarkEVA]: Now playing %s.", playlist[song])
currentsong = playlist[song]
players = Get_All_Players()
for i = 1, #players do
pID = FindPlayerName("FindID", players[i])
music = ReadINI("music.ini", "Players", Get_Player_Name_By_ID(pID))
if music == "on" then
InputConsole("musicp %d %s", pID, playlist[song])
end
end
end
Start_Timer(ID, obj, playlisttime[song], 1)
end
end
Object = 0
function OnChat(pID, Type, Message)
if Message == "!playlist" then
InputConsole("ppage %d [DarkEVA]: Playlist: ammoclip.mp3, command&conquer.mp3, defunkt.mp3, in the line of fire.mp3, level0_pt1_music.mp3, level 0 hero.mp3, level 0 nod base.mp3, level 0 tank.mp3, level 0 tiberium.mp3, mechmansrevenge.mp3, moveit.mp3, onyourfeet.mp3, raveshaw_act on instinct.mp3, renegadejungle.mp3, sakura battle theme.mp3, sakura_dogfight.mp3, sneakattack.mp3, sniper.mp3, stopthemagain.mp3", pID)
end
FindWords(Message)
if FirstW == "!music" then
if SecondW == "off" then
WriteINI("music.ini", "Players", Get_Player_Name_By_ID(pID), SecondW)
InputConsole("nomusicp %d", pID)
elseif SecondW == "on" then
WriteINI("music.ini", "Players", Get_Player_Name_By_ID(pID), SecondW)
InputConsole("musicp %d %s", pID, currentsong)
end
end
return 1
end
function OnPlayerJoin(pID, Nick)
music = ReadINI("music.ini", "Players", Get_Player_Name_By_ID(pID))
if music == nil then
WriteINI("music.ini", "Players", Get_Player_Name_By_ID(pID), "off")
end
end
function OnPlayerLeave(pID)
end
function OnHostMessage(ID, Type, Message)
end
function OnLevelLoaded()
local pos = {X = 0, Y = 0, Z = -10}
oArrow = Create_Object("Daves Arrow", pos)
Attach_Script_Once(oArrow, "SampleTimer", "")
end
function OnLevelEnded()
end
function OnConsoleOutput(Message)
end
function OnDDERecived(Message)
end
function OnObjectCreate(Object)
end
function FindPlayerName(sMethod, sName)
-- This Function Made Soley By PsuFan
-- Please Read The Following Steps/Information Carefully
-- FindPlayerName Function V0.2
-- This function finds either a players ID number, or the players full name
-- I.E. If I call FindPlayerName("FindID", "psufan513") It would return psufan513's ID number.
-- If I call FindPlayerName("FullName", "psu") It would return psufan513 if it was unique.
-- Example Command
-- if Message == "!myname" then -- This command is pointless because you already know the ID (pID) and player name, its just an example.
-- name = Get_Player_Name_By_ID(pID)
-- ID = FindPlayerName("FindID", name)
-- if ID == "None" then
-- -- The name you entered has no matches
-- elseif ID == "Many" then
-- -- The name you entered is not unique
-- end
-- end
-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- Please Do Not Edit Beyond This Point, If this function isnt working properly for you,
-- contact PsuFan to assist you. This code is to complicated for you to fix anyway.
-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CurID = 0
sReturn = ""
FoundName = ""
while CurID <= 127 and sReturn == "" do
CurID = CurID + 1
CurName = Get_Player_Name_By_ID(CurID)
if CurName ~= nil then
if string.lower(CurName) == string.lower(sName) then-- Full Match
sReturn = CurName
elseif string.find(string.lower(CurName), string.lower(sName)) ~= nil then
if FoundName == "" then
FoundName = CurName
else
sReturn = "Many"
end
end
end
end
if FoundName ~= "" and sReturn ~= "Many" then
sReturn = FoundName
end
if sMethod == "FindID" and sReturn ~= "Many" and sReturn ~= "" then
CurID = 0
FoundName = sReturn
sReturn = ""
while CurID <= 127 and sReturn == "" do
CurID = CurID + 1
CurName = Get_Player_Name_By_ID(CurID)
if CurName ~= nil then
if CurName == FoundName then
sReturn = CurID
end
end
end
end
if sReturn ~= "" and sReturn ~= nil then
return sReturn
else
return "None"
end
end
function FindWords(Text)
-- This Function Made Soley By PsuFan
-- Please Read The Following Steps/Information Carefully
-- This function finds all the words in the message you send it
-- FirstW, SecondW, SecondPlus, ThirdW, ThirdPlus, and FourthW are whats returned
-- Installation:
-- 1: Copy this sub into your luaplugin.lua at the bottom of the file
-- 2: Add this line to the top of OnChat function > FindWords(Message)
-- Thats it! You can now use FirstW, SecondW, etc in your OnChat function.
-- This function is great for commands like !ban psufan because he sucks
-- !ban <name> <reason>
-- FirstW would equal "!ban"
-- SecondW would equal "psufan" or the <name>
-- Then the reason would be ThirdPlus ("because he sucks") or the <reason>
-- Key:
-- FirstW = First Word
-- SecondW = Second Word
-- SecondPlus = Second Word Till End
-- ThirdW = Third Word
-- ThirdPlus = Third Word Till End
-- FourthW = Fourth Word
-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- Please Do Not Edit Beyond This Point, If this function isnt working properly for you,
-- contact PsuFan to assist you. This code is to complicated for you to fix anyway.
-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Found = string.find(Text, " ")
if Found ~= nil then
FirstW = string.sub(Text, 0, Found - 1)
SecondW = string.sub(Text, Found + 1)
SecondPlus = SecondW
Found = string.find(SecondW, " ")
if Found ~= nil then
ThirdW = string.sub(SecondW, Found + 1)
SecondW = string.sub(SecondW, 0, Found - 1)
ThirdPlus = ThirdW
Found = string.find(ThirdW, " ")
if Found ~= nil then
FourthW = string.sub(ThirdW, Found + 1)
ThirdW = string.sub(ThirdW, 0, Found - 1)
Found = string.find(FourthW, " ")
if Found ~= nil then
FourthW = string.sub(FourthW, 0, Found - 1)
end
else
FourthW = ""
end
else
ThirdW = ""
ThirdPlus = ""
FourthW = ""
end
else
FirstW = Text
SecondW = ""
SecondPlus = ""
ThirdW = ""
ThirdPlus = ""
FourthW = ""
end
end
function ReadINI(File, Section, KeyName)
-- This Function Made Soley By PsuFan
-- Please Read The Following Steps/Information Carefully
-- Installation:
-- 1: Place this function at the end of your luaplugin.lua
-- 2: Example code > Read = ReadINI("ssgm.ini", "Plugins", "01")
-- This would read ssgm.ini, in the [Plugins] Section, And most likly will return LuaPlugin.dll
-- 3: Example Code 2 > Read = ReadINI("LuaPlugins/readini.ini", "Source", "Keyname")
-- This would read from the LuaPlugins Directory.
-- By Default this function will return "None" if nothing is found, And "NoFile" if the file you are trying
-- to read does not exist.
-- Here are the errors that are returned if you wish to change them.
NoneError = "None" -- Didnt Find Keyname in file
FileError = "NoFile" -- No file exists
ArgError = "None" -- Passed invalid arguments to function
-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- Please Do Not Edit Beyond This Point, If this function isnt working properly for you,
-- contact PsuFan to assist you. This code is to complicated for you to fix anyway.
-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
blnSection = false
intAction = 0
strBracket = [[[]]
if File ~= nil and Section ~= nil and KeyName ~= nil then
if File ~= "" and Section ~= "" and KeyName ~= "" then
i = io.open(File, "r")
if i ~= nil then
while true do
local Line = i:read() -- Reads a line
if Line == nil or intAction ~= 0 then
break
else
if blnSection == false then
Found = string.sub(Line, 0, 1)
if Found == strBracket then -- Found Header
Header = string.sub(Line, 2, -2)
if Header == Section then
blnSection = true
end
end
else
Header = string.sub(Line, 0, 1)
if Header == strBracket then
intAction = 2
elseif Header == ";" then
-- Ignor Comments
elseif Line == "" then
-- Ignor Blank Lines
else
strFindEqual = string.find(Line, "=")
if strFindEqual ~= nil then
strKeyname = string.sub(Line, 0, strFindEqual - 1)
if strKeyname == KeyName then
intAction = 1
Value = string.sub(Line, strFindEqual + 1)
end
end
end
end
end
end
i:close()
if intAction == 1 then
return Value
elseif intAction == 2 then
return NoneError
else
return NoneError
end
else
return FileError
end
else
return ArgError
end
else
return ArgError
end
end
function WriteINI(File, Section, KeyName, Value)
-- This Function Made Soley By PsuFan
-- Please Read The Following Steps/Information Carefully
-- WriteINI Function V0.2
-- Installation:
-- 1: Place this function at the end of your luaplugin.lua
-- 2: Example code > WriteINI("ssgm.ini", "Plugins", "01", "LuaPlugin.dll")
-- This would write ssgm.ini, in the [Plugins] Section and change "01" keyname
-- 3: Example Code 2 > WriteINI("LuaPlugins/readini.ini", "Source", "Keyname", "Value")
-- This would read from the LuaPlugins Directory.
-- Here are the errors that are returned if you wish to change them.
ArgError = "None" -- Passed invalid arguments to function
-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- Please Do Not Edit Beyond This Point, If this function isnt working properly for you,
-- contact PsuFan to assist you. This code is to complicated for you to fix anyway.
-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
blnSection = false
intAction = 0
strBracket = [[[]]
strCloseBracket = [[].]]
strCloseBracket = string.sub(strCloseBracket, 1, 1)
Save = ""
if File ~= nil and Section ~= nil and KeyName ~= nil and Value ~= nil then
if File ~= "" and Section ~= "" and KeyName ~= "" and Value ~= "" then
i = io.open(File, "r")
if i ~= nil then
while true do
local Line = i:read() -- Reads a line
if Line == nil then
break
else
if intAction == 0 then
if blnSection == false then
Found = string.sub(Line, 0, 1)
if Found == strBracket then -- Found Header
Header = string.sub(Line, 2, -2)
if Header == Section then
blnSection = true
end
end
else
Header = string.sub(Line, 0, 1)
if Header == strBracket then
blnSection = false
Line = KeyName .. "=" .. Value .. "\n" .. Line
intAction = 1
elseif Header == ";" then
-- Ignor Comments
elseif Line == "" then
-- Ignor Blank Lines
else
strFindEqual = string.find(Line, "=")
if strFindEqual ~= nil then
strKeyname = string.sub(Line, 0, strFindEqual - 1)
if strKeyname == KeyName then
Line = KeyName .. "=" .. Value
intAction = 1
end
end
end
end
end
Save = Save .. Line .. "\n"
end
end
i:close()
if intAction ~= 1 then
if blnSection == false then
Save = Save .. strBracket .. Section .. strCloseBracket .. "\n" .. KeyName .. "=" .. Value
else
Save = Save .. KeyName .. "=" .. Value
end
end
i = io.open(File, "w")
i:write(Save)
i:close()
else
i = io.open(File, "w")
i:write(strBracket .. Section .. strCloseBracket .. "\n" .. KeyName .. "=" .. Value)
i:close()
end
else
return ArgError
end
else
return ArgError
end
end
But it didn't work, and I didn't get any output so I'm not sure whats wrong.
Not pro enough at renegade to snipe.
[Updated on: Fri, 29 July 2011 22:30] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Dec 20 13:38:49 MST 2024
Total time taken to generate the page: 0.00749 seconds
|