ID:1440517
 
(See the best response by Kaiochao.)
Code:
        if(Enemy_Level > 1 && Enemy_Level < 5)


var/obj/new_item = (if (rand (1, 7) == 1) ? pick (new/obj/books/firebolt/, \
new/obj/books/icebolt/, \
new/obj/books/lightningbolt/, \
new/obj/books/healing/, \
new/obj/books/novabolt/, \
new/obj/books/icesquirt/, \
new/obj/books/witherbolt/) : null)

if (new_item)
new_item.loc = locate(X, Y, Z)
Drop (new_item)


Problem description: if rand does not work using "?" operator? or am I missing something?

You can't use an if statement there like that.
var/num = rand(1,7)
var/obj/new_item = num==1 ? pick(/* stuff */):null
Best response
You can't use if() there, just take it out.
var/obj/new_item = rand(1, 7) == 1 ? pick(...)


I'd suggest you do this instead, though:
//  A 1-in-7 chance of
if(prob(100 / 7)) // or rand(1, 7) == 1, or !rand(6)
// choosing a random type to create
var item_type = pick(
/obj/books/firebolt,
/obj/books/icebolt,
/obj/books/lightningbolt,
/obj/books/healing,
/obj/books/novabolt,
/obj/books/icesquirt,
/obj/books/witherbolt)
Drop(new item_type (locate(X, Y, Z)))

That way, you don't create one of every item. You only need to be creating the one item that will be chosen.