SphereCommunity
Rentable Room Script - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Rentable Room Script (/Thread-Rentable-Room-Script)



Rentable Room Script - pinku - 11-15-2013 04:24 AM

Found on downloads section:

Code:
[comment]
Add this to your innkeeper speech file:

ON=*check out*
ON=*checkout*
ON=*leave*
SRC.F_CHECKOUT <UID>

Add this to your innkeeper sell template

SELL=I_KEY_RENTAL_YEAR,{5 10}
SELL=I_KEY_RENTAL_MONTH,{5 10}
SELL=I_KEY_RENTAL_WEEK,{5 10}
SELL=I_KEY_RENTAL_DAY,{5 10}

Add the event: T_DOOR_RENTAL to the doors of all rentable rooms in the inn.

Make sure you also add a I_SIGN_CHECKOUT in each room so that if the key expires while the player is in the room, they wont be locked in.

[TYPEDEF T_DOOR_RENTAL]

[TYPEDEF T_KEY_RENTAL]
ON=@DCLICK
IF (<TAG.LINKED>==0)
    TARGETF F_RENTAL_LINK <UID>
    RETURN 1
ELSE
    RETURN 0
ENDIF

on=@DROPON_CHAR
IF (STRMATCH(*innkeeper*, <UID.<ARGO>.ID>)
    IF (<TAG.EXPIRED>==1)
        ARGO.SAY Thankyou <SRC.NAME>! Please come again.
        remove
    ENDIF
ENDIF

[ITEMDEF I_KEY_RENTAL_DAY]
ID=I_KEY_IRON
name=Rental (1 Day)
VALUE=100
TEVENTS=T_KEY_RENTAL

ON=@CREATE
TAG.EXPIRE=1*60*24
TAG.LINKED=0

[ITEMDEF I_KEY_RENTAL_WEEK]
ID=I_KEY_IRON
name=Rental (1 Week)
VALUE=500

ON=@CREATE
TAG.EXPIRE=7*60*24
TAG.LINKED=0
EVENTS=T_KEY_RENTAL

[ITEMDEF I_KEY_RENTAL_MONTH]
ID=I_KEY_IRON
name=Rental (1 Month)
VALUE=2500

ON=@CREATE
TAG.EXPIRE=30*60*24
TAG.LINKED=0
EVENTS=T_KEY_RENTAL

[ITEMDEF I_KEY_RENTAL_YEAR]
ID=I_KEY_IRON
name=Rental (1 Year)
VALUE=20000

ON=@CREATE
TAG.EXPIRE=365*60*24
TAG.LINKED=0
EVENTS=T_KEY_RENTAL

[FUNCTION F_RENTAL_LINK]

//say ARGN1= <uid.<ARGN1>.name>
//say name = <name>
//say SRC= <src.name>

IF !(<ARGO.EVENTS>==T_DOOR_RENTAL)
    SYSMESSAGE=This key does Not fit that lock!(not a rental door)
    RETURN 1
ELIF(<EVAL 0<ARGO.TAG.LINKED>>==1)
    SYSMESSAGE=This key does not fit that lock! (Door already rented out)
    RETURN 1
ELSE
    ARGO.TAG.LINKED=1
    argo.MORE1=<UID.<ARGN1>.UID>
    ARGO.MESSAGE=Linked!
    TRY UID.<ARGN1>.TAG.LINKED=1
    TRY UID.<ARGN1>.LINK=<ARGO.UID>
    TRY UID.<ARGN1>.MORE1=<UID.<ARGN1>.UID>
    TRY UID.<ARGN1>.TIMERF=<EVAL <UID.<ARGN1>.TAG.EXPIRE>> F_RENTAL_EXPIRE
    TRY UID.<ARGN1>.NAME Rental Key (<room.name>)
    TRY UID.<ARGN1>.MESSAGE=Linked!
    RETURN 1
ENDIF

[FUNCTION F_RENTAL_EXPIRE]
MESSAGE=The <name> has expired!
TAG.EXPIRED=1
SRC.CTAG.EXPIRINGKEY=<UID>
IF (<SRC.ISINRENTAL>==1)
    //SRC.SAY I'm in the Inn
    SRC.FINDINNKEEPER
    //say <src.tag.inkeeper>
    src. f_checkout <src.tag.innkeeper>
    src.tag.innkeeper=
ENDIF
LINK.TAG.LINKED=0
LINK.TYPE T_DOOR_LOCKED
LINK.MORE1=1
Return 1

[FUNCTION ISINRENTAL]
//SAY key=<uid.<CTAG.EXPIRINGKEY>.MORE1>
FORITEMS 7
    //SAY Door=<MORE1>
    IF (<MORE1>==<uid.<SRC.CTAG.EXPIRINGKEY>.MORE1>)
        RETURN 1
    ENDIF
ENDFOR


[FUNCTION FINDINNKEEPER]
//SAY I'm looking for the Innkeeper
forchars 15
    IF (STRMATCH(*innkeeper*, <ID>))
        src.tag.innkeeper=<uid>
    ENDIF
ENDFOR

[FUNCTION F_CHECKOUT]
FORCONTID i_key_rental_DAY 10
       IF (<EVAL <TAG.EXPIRED>>==1)
        TRY UID.<ARGN1>.SAY Thank you <src.name>! Please come again.
        SRC.go <UID.<ARGN1>.P>
        REMOVE
        RETURN 1
    ENDIF
ENDFOR
FORCONTID i_key_rental_week 10
       IF (<EVAL <TAG.EXPIRED>>==1)
        TRY UID.<ARGN1>.SAY Thank you <src.name>! Please come again.
        SRC.go <UID.<ARGN1>.P>
        REMOVE
        RETURN 1
    ENDIF
ENDFOR
FORCONTID i_key_rental_month 10
       IF (<EVAL <TAG.EXPIRED>>==1)
        TRY UID.<ARGN1>.SAY Thank you <src.name>! Please come again.
        SRC.go <UID.<ARGN1>.P>
        REMOVE
        RETURN 1
    ENDIF
ENDFOR
FORCONTID i_key_rental_year 10
       IF (<EVAL <TAG.EXPIRED>>==1)
        TRY UID.<ARGN1>.SAY Thank you <src.name>! Please come again.
        SRC.go <UID.<ARGN1>.P>
        REMOVE
        RETURN 1
    ENDIF
ENDFOR
    
[ITEMDEF I_SIGN_CHECKOUT]
ID=0bcf
NAME=Check Out

on=@create
ATTR=0c000

on=@dclick
forchars 10
    IF (STRMATCH(*innkeeper*, <ID>))
        src.tag.innkeeper=<uid>
    ENDIF
ENDFOR
say <src.tag.inkeeper>
src. f_checkout <src.tag.innkeeper>
Return 1

I'm trying it.. but does not work..
Before trying, I made sure I set the door event with .xevents T_DOOR_RENTAL

After that, I double click the key and link to the door.
It says "Linked" and then, does not work anymore.
Keeps saying when I try to lock the door with the key:

"The key does not fit into that lock."

Any ideas? I can't get it..


RE: Rentable Room Script - darksun84 - 11-15-2013 05:14 AM

Try this, change

PHP Code:
IF !(<ARGO.EVENTS>==T_DOOR_RENTAL

with

PHP Code:
IF !(<ARGO.isevent>==T_DOOR_RENTAL



RE: Rentable Room Script - RanXerox - 11-15-2013 05:30 AM

The syntax for isevent is more like this I think:

PHP Code:
IF !(<ARGO.isevent.T_DOOR_RENTAL>) 



RE: Rentable Room Script - pinku - 11-15-2013 07:12 AM

Now it does work, however, there is still an issue.
I can use a new key on the same door taken before.. Again, it's giving me no errors on console, so I'm pretty confused.

Seems like this checker isn't working:

ELIF(<EVAL 0<ARGO.TAG.LINKED>>==1)
SYSMESSAGE=This key does not fit that lock! (Door already rented out)
RETURN 1


RE: Rentable Room Script - x77x - 11-15-2013 02:47 PM

can you rent it by the hour?


RE: Rentable Room Script - darksun84 - 11-16-2013 01:27 AM

(11-15-2013 07:12 AM)pinku Wrote:  Now it does work, however, there is still an issue.
I can use a new key on the same door taken before.. Again, it's giving me no errors on console, so I'm pretty confused.

Seems like this checker isn't working:

ELIF(<EVAL 0<ARGO.TAG.LINKED>>==1)
SYSMESSAGE=This key does not fit that lock! (Door already rented out)
RETURN 1

Just tested, the problem is there is no blank space between ELIF and the condition Veryhappy


RE: Rentable Room Script - RanXerox - 11-16-2013 04:53 AM

PHP Code:
ELIF(<EVAL 0<ARGO.TAG.LINKED>>==1

...is unnecessarily complicated, you can do this instead:

PHP Code:
ELIF (<ARGO.TAG0.LINKED>) 

The () marks in an IF statement imply it is to be evaluated, and putting the 0 after the keyword TAG prevents an error from being thrown if the TAG does not exist. The condition will be true when the TAG has any value other than zero, so testing specifically for the value of 1 is not necessary.


RE: Rentable Room Script - pinku - 11-16-2013 04:52 PM

Well, it works very well.. until I open the door.. lol

Does anyone else have this problem? I don't think it's related to my house system, but who knows?