Home » Renegade Discussions » Mod Forum » Lua sleep()
Lua sleep() [message #450306] |
Fri, 29 July 2011 17:48 |
|
Intradox
Messages: 60 Registered: February 2011 Location: United States
Karma: 0
|
Recruit |
|
|
Hello, so I'm using the Lua Plugin v5.0 on my server, and I was wondering how/if its possible to make a sleep() function. I've found functions that do it, but they cause the entire program to sleep. So I was wondering if its possible to make one that doesn't make the entire program sleep, just the script? Or if it would be possible to achieve this with timers, because I want to wait x amount of seconds before I change the song that's being played. Like the music plugin from BRenBot.
I know this isn't DCOM's site, but the last post on there was in 2009 and my thread on there hasn't gotten a single view besides my own. So I asked here since I may get more help.
Thanks,
Intradox
Not pro enough at renegade to snipe.
[Updated on: Fri, 29 July 2011 18:08] Report message to a moderator
|
|
|
|
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: 0
|
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
|
|
|
Re: Lua sleep() [message #450327 is a reply to message #450306] |
Sat, 30 July 2011 05:43 |
iRANian
Messages: 4308 Registered: April 2011
Karma: 0
|
General (4 Stars) |
|
|
The script syntax in Lua 5.0 is different and looks like:
myscript = {}
function myscript:Created(ID, obj)
print("Created", ID, obj)
end
function myscript:Destroyed(ID, obj)
print("Destroyed", ID, obj)
end
function myscript:Killed(ID, obj, killer)
print("Killed", ID, obj, killer)
end
Register_Script("myscript", "", myscript)
Long time and well respected Renegade community member, programmer, modder and tester.
Scripts 4.0 private beta tester since May 2011.
My Renegade server plugins releases
|
|
|
Re: Lua sleep() [message #450328 is a reply to message #450327] |
Sat, 30 July 2011 06:09 |
|
sla.ro(master)
Messages: 610 Registered: September 2010 Location: Romania
Karma: 0
|
Colonel |
|
|
Intradox , your using Lua 5 or 4 ?
because your scripts look like Lua 4
iran's script is Lua 5
Creator of Mutant Co-Op
Developer of LuaTT
|
|
|
Re: Lua sleep() [message #450338 is a reply to message #450327] |
Sat, 30 July 2011 10:05 |
|
Intradox
Messages: 60 Registered: February 2011 Location: United States
Karma: 0
|
Recruit |
|
|
I'm using Lua v5.0, and the reason it looks outdated it because the an example I used was for an older version.
So I tried this:
function printf(...)
io.write(string.format(unpack(arg)))
end
function InputConsole(...)
Console_Input(string.format(unpack(arg)))
end
Players = {}
currentsong = "ammoclip.mp3"
Jukebox = {}
function Jukebox: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
function Jukebox:Destroyed(ID, obj)
if song == nil then
song = 0
end
if ID == 1 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 = Players[Get_Player_Name_By_ID(pID)]
if music == "on" then
InputConsole("musicp %d %s", pID, playlist[song])
end
end
Start_Timer(ID, obj, playlisttime[song], 1)
end
end
function Jukebox:Killed(ID, obj, killer)
end
Register_Script("Jukebox", "", Jukebox)
Object = 0
function OnChat(pID, Type, Message)
FindWords(Message)
if FirstW == "!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
if FirstW == "!music" then
if SecondW == "off" then
Players[Get_Player_Name_By_ID(pID)]="off"
InputConsole("nomusicp %d", pID)
elseif SecondW == "on" then
Players[Get_Player_Name_By_ID(pID)]="on"
InputConsole("musicp %d %s", pID, currentsong)
end
end
return 1
end
function OnPlayerJoin(pID, Nick)
Players[Get_Player_Name_By_ID(pID)]="off"
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, "Jukebox", "")
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
Still no output and it still doesn't work.
Not pro enough at renegade to snipe.
[Updated on: Sat, 30 July 2011 10:41] Report message to a moderator
|
|
|
Re: Lua sleep() [message #450339 is a reply to message #450306] |
Sat, 30 July 2011 11:10 |
iRANian
Messages: 4308 Registered: April 2011
Karma: 0
|
General (4 Stars) |
|
|
:Destroyed() gets triggered when the the script is destroyed, you need to use :Timer_Expired(). In the chat hook you need to attach and destroy the script when a player types "!music on" and "!music off" respectively. You should add some debug messages in all the major hotspots in your code so you can see what gets triggered and what does not.
Long time and well respected Renegade community member, programmer, modder and tester.
Scripts 4.0 private beta tester since May 2011.
My Renegade server plugins releases
|
|
|
Re: Lua sleep() [message #450342 is a reply to message #450339] |
Sat, 30 July 2011 11:33 |
|
Intradox
Messages: 60 Registered: February 2011 Location: United States
Karma: 0
|
Recruit |
|
|
I'm doing it as global thing, not so each player has different music playing, which sounds like what you want me to do. So I attached it to a daves arrow, and it plays the first song, but it doesn't go onto the next song.
function Jukebox:Timer_Expired()
if song == nil then
song = 0
end
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 = Players[Get_Player_Name_By_ID(pID)]
if music == "on" then
InputConsole("musicp %d %s", pID, playlist[song])
end
end
Start_Timer(ID, obj, playlisttimes[song], 1)
end
For the Start_Timer, what would I have to put for ID and obj? I think this is where its messed up.
Not pro enough at renegade to snipe.
[Updated on: Sat, 30 July 2011 11:50] Report message to a moderator
|
|
|
Re: Lua sleep() [message #450343 is a reply to message #450342] |
Sat, 30 July 2011 11:56 |
|
sla.ro(master)
Messages: 610 Registered: September 2010 Location: Romania
Karma: 0
|
Colonel |
|
|
playlisttimes[song] does return a number? try debug it with print("something",var,var2) and see if its called, if not then theres a problem, i always debug my scripts.
Creator of Mutant Co-Op
Developer of LuaTT
|
|
|
Re: Lua sleep() [message #450344 is a reply to message #450306] |
Sat, 30 July 2011 12:14 |
iRANian
Messages: 4308 Registered: April 2011
Karma: 0
|
General (4 Stars) |
|
|
What do your debug messages say about the Jukebox script?
If you play music when a guy types "!music on" you're getting timing errors with when the script starts playing music. What you can do is play something short and repetitive with "!music on" and have the script execute the "no music" command before playing new music.
Add some debug messages to Timer_Expired() and you'll see what the correct order is, that order should be fine though.
int LuaScriptManager::Lua_Start_Timer_Wrap(lua_State *L)
{
int argc = lua_gettop(L);
if(argc < 4)
{
return 0;
}
int scriptID = (int)lua_tonumber(L, 1);
int obj = (int)lua_tonumber(L, 2);
float Time = (float)lua_tonumber(L, 3);
int Number = (int)lua_tonumber(L, 4);
LuaScriptManager::Lua_Start_Timer(Commands->Find_Object(obj), scriptID, Time, Number);
return 0;
}
Long time and well respected Renegade community member, programmer, modder and tester.
Scripts 4.0 private beta tester since May 2011.
My Renegade server plugins releases
|
|
|
Re: Lua sleep() [message #450394 is a reply to message #450344] |
Sun, 31 July 2011 14:37 |
|
Intradox
Messages: 60 Registered: February 2011 Location: United States
Karma: 0
|
Recruit |
|
|
Ok I finally got it to work! Thanks for the help even though what you were suggesting was different than what I wanted.
function printf(...)
io.write(string.format(unpack(arg)))
end
function InputConsole(...)
Console_Input(string.format(unpack(arg)))
end
Players = {}
currentsong = "ammoclip.mp3"
Jukebox = {}
function Jukebox: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, 1, 1)
end
function Jukebox:Timer_Expired(ID, obj, num)
if song == nil then
song = 0
end
if num == 1 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 = players[i]
music = Players[pID]
if music == "on" then
InputConsole("musicp %d %s", pID, playlist[song])
end
end
Start_Timer(ID, obj, playlisttimes[song], 1)
end
end
function Jukebox:Destroyed(ID, obj)
end
function Jukebox:Killed(ID, obj, killer)
end
Register_Script("Jukebox", "", Jukebox)
Object = 0
function OnChat(pID, Type, Message)
FindWords(Message)
if FirstW == "!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
if FirstW == "!music" then
if SecondW == "off" then
Players[pID]="off"
InputConsole("nomusicp %d", pID)
InputConsole("ppage %d [DarkEVA]: Music has been disabled for you.", pID)
elseif SecondW == "on" then
Players[pID]="on"
InputConsole("musicp %d %s", pID, currentsong)
InputConsole("ppage %d [DarkEVA]: Music has been enabled for you.", pID)
elseif SecondW == "" then
InputConsole("ppage %d [DarkEVA]: Usage: !music <on/off>.", pID)
end
end
return 1
end
function OnPlayerJoin(pID, Nick)
Players[pID]="off"
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, "Jukebox", "")
end
function OnLevelEnded()
end
function OnConsoleOutput(Message)
end
function OnDDERecived(Message)
end
function OnObjectCreate(Object)
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
Not pro enough at renegade to snipe.
|
|
|
Re: Lua sleep() [message #450403 is a reply to message #450394] |
Sun, 31 July 2011 20:16 |
|
halo2pac
Messages: 659 Registered: December 2006 Location: Near Cleveland, Ohio
Karma: 0
|
Colonel |
|
|
As a tip ... next time try to post less redundant code.. to make reading your posts easier.
Rene-Buddy | Renegade X
Join the fight against Obsessive-Compulsive Posting Disorder. Cancel is ur friend.
*Renegade X Dev Team Member*
|
|
|
Goto Forum:
Current Time: Wed Dec 18 07:19:04 MST 2024
Total time taken to generate the page: 0.01018 seconds
|