;'Money Lender' - NPC script

If GetUserStrength(#USERID) < 15
	SendMessageToUser(#USERID,"~You are not eligable for a loan~",#MSG_TELL)
	GoTo END
EndIf

CurrentLoan = GetUserFlag(#USERID,38)
MaxLoan = Floor(GetUserStrength(#USERID) * 2000)
Interest = Floor(Floor(50-GetUserWisdom(#USERID)) * 0.005)
If Interest < 0.05
	Interest = 0.05
EndIf

Silver = GetUserSilver(#USERID)
Text=Lower(GetUserMessage(#USERID))

Line1="0"
Line2="0"
Line3="0"

If Text="loan"
	If Floor(CurrentLoan + 2000) > MaxLoan
		Line1="Cannot exceed maximum loan amount."
		Line2="Maximum Loan: "+MaxLoan
		GoTo DISPLAY
	EndIf
	
	If CurrentLoan = 0
		Timer(512,86400000,#USERID,0,0)
	EndIf
	
	CurrentLoan=CurrentLoan+2000
	Silver=Silver+2000
	SetUserFlag(#USERID,38,CurrentLoan)
	SetUserSilver(#USERID,Silver)
	Line1="Taken out loan of 2000"
	Line2="Current Loan: "+CurrentLoan
ElseIf Text="pay"
	If Floor(CurrentLoan - 2000) < 0
		SetUserFlag(#USERID,38,0)
		Line1="Loan is already payed off"
		Line2="Current Loan: "+CurrentLoan 
		GoTo DISPLAY
	EndIf
	If Floor(Silver - 2000) < 0
		Line1="Insufficient funds"
		Line2="User Silver: "+Silver 
		GoTo DISPLAY
	EndIf
	CurrentLoan=CurrentLoan-2000
	Silver=Silver-2000
	SetUserFlag(#USERID,38,CurrentLoan)
	SetUserSilver(#USERID,Silver)
	Line1="Payed off debt off by 2000 silver"
	Line2="Current Loan: "+CurrentLoan
ElseIf Text="help"
	Line1="This console allows for you to take out a loan"
	Line2="of silver. Every 24 hours, the interest of the"
	Line3="loan is charged you, until you pay it off.
Else
	Line1="Current Loan: "+CurrentLoan
	Line2="Interest Rate: "+Interest
	Line3="Maximum Loan: "+MaxLoan
EndIf

Label DISPLAY

;Display the screen
SendMessageToUser(#USERID,"--------------------------------------",#MSG_TELL)
If Line1<>"0"
	SendMessageToUser(#USERID,Line1,#MSG_TELL)
Else
	SendMessageToUser(#USERID," ",#MSG_TELL)
EndIf
If Line2<>"0"
	SendMessageToUser(#USERID,Line2,#MSG_TELL)
Else
	SendMessageToUser(#USERID," ",#MSG_TELL)
EndIf
If Line3<>"0"
	SendMessageToUser(#USERID,Line3,#MSG_TELL)
Else
	SendMessageToUser(#USERID," ",#MSG_TELL)
EndIf
SendMessageToUser(#USERID,"--------------------------------------",#MSG_TELL)
SendMessageToUser(#USERID,"[loan][pay][help][info][cancel]",#MSG_TELL)

Label END

Continue = 1