Hey guys so I am trying to make a darkrp hints script but I keep getting an odd error:
[ERROR] lua/autorun/hints.lua:5: ')' expected near ','
1. unknown - lua/autorun/hints.lua:0
[CODE]
local function GiveHint()
local hint = math.random(1, 37)
if hint == 1 then
(HUD_PRINTTALK , "Roleplay according to the Server Rules!")
elseif hint == 2 then
(HUD_PRINTTALK , "You can be arrested for buying or owning an illegal weapon!")
elseif hint == 3 then
(HUD_PRINTTALK , "Type /sleep to fall asleep. (Extra weapons will be lost!)")
elseif hint == 4 then
(HUD_PRINTTALK , "You may own a handgun, but use it only in self defence.")
elseif hint == 5 then
(HUD_PRINTTALK , "Press F2 to see server rules and view special commands.")
elseif hint == 6 then
(HUD_PRINTTALK , "All weapons are very inaccurate, unless you right click to see through the sight post.")
elseif hint == 7 then
(HUD_PRINTTALK , "If you are a cop, do your job properly or you could get demoted.")
elseif hint == 8 then
(HUD_PRINTTALK , "Type /buyshipment <Weapon name> to buy a shipment of weapons (e.g: /buyshipment ak47).")
elseif hint == 9 then
(HUD_PRINTTALK , "Type /buypistol <Pistol name> to buy a pistol, e.g: /buypistol glock.")
elseif hint == 10 then
(HUD_PRINTTALK , "Type /buyammo <Ammo type> to buy ammo. Ammo types are: [rifle | shotgun | pistol]")
elseif hint == 11 then
(HUD_PRINTTALK , "If you wish to bail a friend out of jail, go to your designated Police Department and negotiate!")
elseif hint == 12 then
(HUD_PRINTTALK , "Press F1 to see RP help.")
elseif hint == 13 then
(HUD_PRINTTALK , "This shouldn't use variables that I don't have!")
elseif hint == 14 then
(HUD_PRINTTALK , "If you are a chief or admin, type /jailpos or /addjail to set the positions of the first (and extra) jails.")
elseif hint == 15 then
(HUD_PRINTTALK , "You will be teleported to jail if you get arrested!")
elseif hint == 16 then
(HUD_PRINTTALK , "If you see someone with an illegal weapon, arrest them and confiscate it.")
elseif hint == 17 then
(HUD_PRINTTALK , "Type /sleep to fall asleep.")
elseif hint == 18 then
(HUD_PRINTTALK , "Your money and RP name are saved by the server.")
elseif hint == 19 then
(HUD_PRINTTALK , "Type /buyhealth to refil your health to 100%")
elseif hint == 20 then
(HUD_PRINTTALK , "Type /buydruglab to buy a druglab. It ")
elseif hint == 21 then
(HUD_PRINTTALK , "Press F2 to see the server rules and view special commands.")
elseif hint == 22 then
(HUD_PRINTTALK , "You will be teleported to a jail if you get arrested!")
elseif hint == 23 then
(HUD_PRINTTALK , "Type /price <Price> while looking at a Gun Lab or a Microwave to set the customer purchase price.")
elseif hint == 24 then
(HUD_PRINTTALK , "Type /warrant [Nick|SteamID|UserID] to get a search warrant for a player.")
elseif hint == 25 then
(HUD_PRINTTALK , "Type /wanted or /unwanted [Nick|SteamID|UserID] to set a player as wanted/unwanted by the Police.")
elseif hint == 26 then
(HUD_PRINTTALK , "Type /drop to drop the weapon you are holding.")
elseif hint == 27 then
(HUD_PRINTTALK , "Type /gangster to become a Gangster.")
elseif hint == 28 then
(HUD_PRINTTALK , "Type /mobboss to become a Mob Boss.")
elseif hint == 29 then
(HUD_PRINTTALK , "Type /buymicrowave to buy a Microwave Oven that spawns food.")
elseif hint == 30 then
(HUD_PRINTTALK , "Type /dropmoney <Amount> to drop a money amount.")
elseif hint == 31 then
(HUD_PRINTTALK , "Type /buymoneyprinter to buy a Money Printer. Costs ")
elseif hint == 32 then
(HUD_PRINTTALK , "Type /medic - To become a Medic.")
elseif hint == 33 then
(HUD_PRINTTALK , "Type /gundealer - To become a Gun Dealer.")
elseif hint == 34 then
(HUD_PRINTTALK , "Type /buygunlab - to buy a Gun Lab.")
elseif hint == 35 then
(HUD_PRINTTALK , "Type /cook - to become a Cook.")
elseif hint == 36 then
(HUD_PRINTTALK , "Type /cophelp to see what you need to do as a cop.")
elseif hint == 37 then
(HUD_PRINTTALK , "Type /buyfood <Type> (e.g: /buyfood melon)")
end
end
timer.Create("hints", 5, 0, GiveHint)
[/CODE]
If someone could help me fix this that'd be great! I know the code is really inefficient and not optimized but it's the best I can do.
You need to learn tables and shouldn't it be [lua]PrintMessage( HUD_PRINTTALK, msg )[/lua] ?
[QUOTE=KB;50653440]Hey guys so I am trying to make a darkrp hints script but I keep getting an odd error:
[ERROR] lua/autorun/hints.lua:5: ')' expected near ','
1. unknown - lua/autorun/hints.lua:0
~code~
If someone could help me fix this that'd be great! I know the code is really inefficient and not optimized but it's the best I can do.[/QUOTE]
It's because having an open parentheses doesn't make any sense there. You should be doing:
[CODE]
local hint = math.random(1, 37)
if hint == 1 then
for k,v in pairs(players.GetAll()) do
v:PrintMessage(HUD_PRINTTALK, "Here's a hint!")
end
elseif hint == 2 then
for k,v in pairs(players.GetAll()) do
v:PrintMessage(HUD_PRINTTALK, "Here's a hint!")
end
:
:
:
[/CODE]
But you can make this code much simpler by using a table
[CODE]
local hintslist = {
"Here's a hint!",
"Here's another hint!",
"Error messages give you lots of info about what the error is!"
}
local function GiveHint()
--#hintslist will return the length of the table hintslist, so you don't have to modify anything when you add new strings to the table
local randomhintnum = math.random(1,#hintslist)
for k,v in pairs(player.GetAll()) do
--hintslist[randomhintnum] will return the string at the randomhintnum position in the list (starting from 1)
v:PrintMessage(HUD_PRINTTALK,hintslist[randomhintnum])
end
end
timer.Create("hints",5,0,GiveHint)
[/CODE]
By the way, we have a "Questions that don't need their own thread" thread for small things like this.
[QUOTE=Apickx;50653523]It's because having an open parentheses doesn't make any sense there. You should be doing:
[CODE]
local hint = math.random(1, 37)
if hint == 1 then
for k,v in pairs(players.GetAll()) do
v:PrintMessage(HUD_PRINTTALK, "Here's a hint!")
end
elseif hint == 2 then
for k,v in pairs(players.GetAll()) do
v:PrintMessage(HUD_PRINTTALK, "Here's a hint!")
end
:
:
:
[/CODE]
But you can make this code much simpler by using a table
[CODE]
local hintslist = {
"Here's a hint!",
"Here's another hint!"
"Error messages give you lots of info about what the error is!"
}
local function GiveHint()
--#hintslist will return the length of the table hintslist, so you don't have to modify anything when you add new strings to the table
local randomhintnum = math.random(1,#hintslist)
for k,v in pairs(player.GetAll()) do
--hintslist[randomhintnum] will return the string at the randomhintnum position in the list (starting from 1)
v:PrintMessage(HUD_PRINTTALK,hintslist[randomhintnum])
end
end
timer.Create("hints",5,0,GiveHint)
[/CODE]
By the way, we have a "Questions that don't need their own thread" thread for small things like this.[/QUOTE]
Ah ok thank you very much I will also use that thread in the future.
EDIT: Sorry but for some reason I tested it in game and it gives 2 hints at once.
[QUOTE=KB;50653534]Ah ok thank you very much I will also use that thread in the future.
EDIT: Sorry but for some reason I tested it in game and it gives 2 hints at once.[/QUOTE]
How many people are on your server when you run this?
[QUOTE=Matsumoto;50653598]How many people are on your server when you run this?[/QUOTE]
just me it's a test server at the moment, it could be the custom chat box though.
you should store things in a table... like this
[code]
thehinttable = {
"hint1",
"hint2"
}
randomhint = math.random(1, #thehinttable)
print("Hint: "..thehinttable[randomhint])
[/code]
Very simple explaination...
[QUOTE=XxLMM13xXx;50653886]you should store things in a table... like this
[code]
thehinttable = {
"hint1",
"hint2"
}
randomhint = math.random(1, #thehinttable)
print("Hint: "..thehinttable[randomhint])
[/code]
Very simple explaination...[/QUOTE]
why would you literally do the same the guy 4 posts above you did and you even did it worse...
Sorry, you need to Log In to post a reply to this thread.