

itemID = #PARAM1

X = 5
Y = 11

num = random(0,2)
if num = 0
	X = 4
	Y = 10
else if num = 1
	X = 6
	Y = 11
else 
	X = 4
	Y = 12
endif

CreateEffect(1,500,0,#DIR_RIGHT,1,4,10,0,1,0)
CreateEffect(1,500,0,#DIR_RIGHT,1,6,11,0,1,0)
CreateEffect(1,500,0,#DIR_RIGHT,1,4,12,0,1,0)


;Remove the old item
if itemID > 0
	RemoveItem(1, itemID)
	RemoveItemAtXY(1, 4, 10)
	RemoveItemAtXY(1, 6, 11)
	RemoveItemAtXY(1, 4, 12)
endif

;increment
itemID = itemID + 1

if itemID > 767
	itemID = 1
	SendMessageToMap(1,"The item list looped back around.",#MSG_SERVER)
endIf

;check if the new item has a name
while GetItemName(itemID)=""
	if itemID > 767
		itemID = 0
		SendMessageToMap(1,"The item list looped back around.",#MSG_SERVER)
	endIf

	;loop around if needed
	itemID = itemID + 1
wend

if Random(0,3) = 0
	userID = GetUserAtXY(1,5,11)
	if userID > 0
		if GetUserAccess(userID) < 6
			DamageUser(userID,7777)
			SendMessageToMap(1,GetUserName(userID)+" was killed because Comrade was bored.",#MSG_CRITICAL)
		endIf
	endif
endif

;Kill any campers.
userID = GetUserAtXY(1,4,10)
if userID > 0
	if GetUserAccess(userID) < 6
		DamageUser(userID,7777)
		SendMessageToMap(1,GetUserName(userID)+" was killed for camping the items.",#MSG_CRITICAL)
	endIf
endif

userID = GetUserAtXY(1,6,11)
if userID > 0
	if GetUserAccess(userID) < 6
		DamageUser(userID,7777)
		SendMessageToMap(1,GetUserName(userID)+" was killed for camping the items.",#MSG_CRITICAL)
	endIf
endif

userID = GetUserAtXY(1,4,12)
if userID > 0
	if GetUserAccess(userID) < 6
		DamageUser(userID,7777)
		SendMessageToMap(1,GetUserName(userID)+" was killed for camping the items.",#MSG_CRITICAL)
	endIf
endif

;Spawn the new item
SpawnItem(1, itemID, X, Y)
SendMessageToMap(1,"A "+GetItemName(itemID)+" appeared. (Item #"+itemID+" of 768)",#MSG_SERVER)

timer(1, 15000, itemID, 0, 0)

Continue = 1