// TMW2: Moubootaur Legends scripts. // Author: // Jesusalva // Description: // Real Estate System // Script Helpers // WARNING: They affect directly the real estate global variables! // This function reduces payment accordingly // realestate_payment ( amount ) function script realestate_payment { REAL_ESTATE_CREDITS=REAL_ESTATE_CREDITS-getarg(0); if (REAL_ESTATE_CREDITS < 0) { Zeny+=REAL_ESTATE_CREDITS; REAL_ESTATE_CREDITS=0; } return; } // Generate unique name for setcells // realestate_cellname ( estate_id, object_id ) function script realestate_cellname { return "RESObj_"+getarg(0)+"_"+getarg(1); } // Generate sell price for furniture based on original price and estate ID // realestate_sellprice ( estate_id, price ) function script realestate_sellprice { .@timeleft=$ESTATE_RENTTIME[getarg(0)]-gettimetick(2); // Number of seconds .@daysleft=.@timeleft/86400; // Number of days left of rent .@weeksleft=.@timeleft/604800; // Number of weeks left of rent //debugmes "Your contract is valid for %d weeks more - %d days", .@weeksleft, .@daysleft; //debugmes "The divisor is %d", max(1, 8-.@weeksleft); return (getarg(1)/max(1, 8-.@weeksleft)) - max(0, 60-.@daysleft); } // This will toggle if mobilia was purchased or not, in the right group // And as an added bonus, will tell the correct Script to reload NPCs // realestate_togglemobilia ( estate_id, layer_id, object_id{, npc_file} ) function script realestate_togglemobilia { switch (getarg(1)) { case 1: $ESTATE_MOBILIA_64[getarg(0)] = $ESTATE_MOBILIA_64[getarg(0)] ^ getarg(2); break; case 2: $ESTATE_MOBILIA_4[getarg(0)] = $ESTATE_MOBILIA_4[getarg(0)] ^ getarg(2); break; case 3: $ESTATE_MOBILIA_8[getarg(0)] = $ESTATE_MOBILIA_8[getarg(0)] ^ getarg(2); break; case 4: $ESTATE_MOBILIA_32[getarg(0)] = $ESTATE_MOBILIA_32[getarg(0)] ^ getarg(2); break; case 5: $ESTATE_MOBILIA_128[getarg(0)] = $ESTATE_MOBILIA_128[getarg(0)] ^ getarg(2); break; case 6: $ESTATE_MOBILIA_2[getarg(0)] = $ESTATE_MOBILIA_2[getarg(0)] ^ getarg(2); break; default: debugmes("[ERROR] [CRITICAL] [REAL ESTATE]: Object %d have Invalid Collision Type: %d (must range 1~6)", getarg(2), getarg(1)); break; } if (getarg(3, "error") != "error") { // Reload NPCs on the meanwhile donpcevent getarg(3)+"::OnReload"; } return; } // Like the previous function, but returns true if player have said mobilia // realestate_hasmobilia ( estate_id, layer_id, object_id ) function script realestate_hasmobilia { switch (getarg(1)) { case 1: return $ESTATE_MOBILIA_64[getarg(0)] & getarg(2); case 2: return $ESTATE_MOBILIA_4[getarg(0)] & getarg(2); case 3: return $ESTATE_MOBILIA_8[getarg(0)] & getarg(2); case 4: return $ESTATE_MOBILIA_32[getarg(0)] & getarg(2); case 5: return $ESTATE_MOBILIA_128[getarg(0)] & getarg(2); case 6: return $ESTATE_MOBILIA_2[getarg(0)] & getarg(2); default: debugmes("[ERROR] [CRITICAL] [REAL ESTATE]: Object %d have Invalid Collision Type: %d (must range 1~6)", getarg(2), getarg(1)); return false; } return false; } ////////////////////////////////////////////////////////////////////////////// ///////////// Dialog Helpers // "If you copy-paste the same line too often, make a function for it" // Rent_Available Label // Returns true regardless of player decision // realestate_rent ( estate_id, price, ) function script realestate_rent { .id=getarg(0); .price=getarg(1); .time=getarg(2, 2592000); // Defaults to 30 days do { mesc l("This Real Estate is available for rent for only @@ GP!", format_number(.price)); .@gp=REAL_ESTATE_CREDITS+Zeny; mesc l("You currently have: @@ GP and mobiliary credits", format_number(.@gp)); next; select rif(.@gp > .price, l("Rent it! Make it mine!")), l("Information"), l("Don't rent it"); // You want to rent if (@menu == 1) { if ($ESTATE_RENTTIME[.id] > gettimetick(2)) { mesc l("Somebody already rented it before you!"); close; } REAL_ESTATE_CREDITS=REAL_ESTATE_CREDITS-.price; if (REAL_ESTATE_CREDITS < 0) { Zeny+=REAL_ESTATE_CREDITS; REAL_ESTATE_CREDITS=0; } // Payment done, you can now acquire the house for a month $ESTATE_RENTTIME[.id]=gettimetick(2)+.time; // If you're not the previous owner // Remove previous owner furniture and reset room password if ($ESTATE_OWNER[.id] != getcharid(3)) { /* $ESTATE_MOBILIA_2[.id]=0; $ESTATE_MOBILIA_4[.id]=0; $ESTATE_MOBILIA_8[.id]=0; $ESTATE_MOBILIA_32[.id]=0; $ESTATE_MOBILIA_64[.id]=0; $ESTATE_MOBILIA_128[.id]=0; */ $ESTATE_PASSWORD$[.id]=""; $ESTATE_DOORBELL[.id]=false; } // Register your info so you can manage it $ESTATE_OWNER[.id]=getcharid(3); $ESTATE_OWNERNAME$[.id]=strcharinfo(0); mesc l("Rent successful for 30 days!"); } else if (@menu == 2) { mesc l("You can rent this house to make it yours.") + " " + l("The rent lasts 30 days."); mesc l("Then you'll be able to buy furniture and utility."); mesc l("The door is password-protected, so your friends can enter but strangers stay outside."); next; mesc l("Both rent and furniture are bought using money, however, there are mobiliary credits."); mesc l("Mobiliary Credits is a special currency which can only be used on real estate."); mesc l("It's obtained with ADMINS or by selling furniture. It is sumed to money and used first."); next; } } while (@menu == 2); return true; } // L_Manage Label // Returns true regardless of player decision // realestate_manage ( estate_id, price, ) function script realestate_manage { .id=getarg(0); .price=getarg(1); .time=getarg(2, 2592000); // Defaults to 30 days do { mesc l("@@'s Estate", strcharinfo(0)); mesc ".:: "+ l("Managment Menu") + " ::."; .@gp=REAL_ESTATE_CREDITS+Zeny; mesc l("Rent time available: @@", FuzzyTime($ESTATE_RENTTIME[.id])); mesc l("Total Credits and GP: @@", format_number(.@gp)); mes ""; mesc l("Rent Renew Price: @@ GP", format_number(.price)); mesc l("Room password: @@", $ESTATE_PASSWORD$[.id]); if ($ESTATE_DOORBELL[.id]) mesc l("Doorbell is disabled"), 1; next; select l("Leave"), l("Enable/disable doorbell"), l("Set room password"), rif(.@gp >= .price && $ESTATE_RENTTIME[.id] < gettimetick(2)+.time, l("Renew Rent")), rif($@GM_OVERRIDE, l("Destroy all mobilia")), rif($@GM_OVERRIDE, l("Expire rent time")); switch (@menu) { case 1: break; case 2: $ESTATE_DOORBELL[.id]=!$ESTATE_DOORBELL[.id]; break; case 3: mesc l("(Leave the password blank to disable)"); mesc l("Current Room password: @@", $ESTATE_PASSWORD$[.id]); mesc l("Input new password: "); input .@password$; mesc l("Repeat new password: "); input .@passwordc$; if (.@password$ == .@passwordc$) { $ESTATE_PASSWORD$[.id]=.@password$; mesc l("Password changed with success!"), 3; } else { mesc l("The passwords doesn't match."), 1; } break; case 4: // The check is performed before showing the menu option // I guess it could be hacked, but I'll probably see negative GP... REAL_ESTATE_CREDITS=REAL_ESTATE_CREDITS-.price; if (REAL_ESTATE_CREDITS < 0) { Zeny+=REAL_ESTATE_CREDITS; REAL_ESTATE_CREDITS=0; } // Payment done, you can now acquire the house for a month // If you lost the rent on the meanwhile, it'll renew // If you lost the rent and somebody else rented it, you lose the GP $ESTATE_RENTTIME[.id]+=.time; break; case 5: mesc l("Are you sure? This cannot be undone!"), 1; next; if (validatepin()) { $ESTATE_MOBILIA_2[.id]=0; $ESTATE_MOBILIA_4[.id]=0; $ESTATE_MOBILIA_8[.id]=0; $ESTATE_MOBILIA_32[.id]=0; $ESTATE_MOBILIA_64[.id]=0; $ESTATE_MOBILIA_128[.id]=0; $ESTATE_PASSWORD$[.id]=""; $ESTATE_DOORBELL[.id]=false; } case 6: mesc l("Are you sure? This cannot be undone!"), 1; next; if (validatepin()) { $ESTATE_RENTTIME[.id]=gettimetick(2); } } } while (@menu != 1); return true; }