Home » Renegade Discussions » Mod Forum » Lua sleep()
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:
|
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
|
|
|
Goto Forum:
Current Time: Fri Dec 20 13:26:52 MST 2024
Total time taken to generate the page: 0.00863 seconds
|