使用.lsl(Linden脚本语言)
写下面的脚本有问题它的目的是让一个租房者A(第一个租房者)租用这个空间并且可以出租房间用于租房者B(第二个租房者)
第一个问题是,对于承租人B,租用空间以结束快速的时间。从州活动
申请 第二个问题是租房者B应该在第一时间支付总租金A套房的至少25%,但是在支付初始价格后,租房者B不能再支付甚至支付的总金额应该是什么租房者A集。//varibles for renter A
// elapsedRentalTime = .0;
// rentalTime = 0;
// rentalName = "<No body>";
// rentalUUID = NULL_KEY;
// rentalSetPrice = 0;
// rentalSetTime = .0;
//varibles for renter B
// endName = "<No Body>";
// endUUID = NULL_KEY;
// endRentalTime = .0;
// endRentalPayd = 0;
希望somone可以帮助解决这个问题。也很遗憾可能有任何类型:)
//cant pay after the int 25% of amt / renter time for renter B ends to fast
integer chan;
list butPrice = ["0","1","2","3","4","5","6","7","8","9","Set price","Reset price"];
list butTime = ["Hour+","Hour-","Day+","Day-","Week+","Week-","Set time","Reset time"];
integer lis1;
key owner;
integer rentPrice;
float rentTime;
float dialogTime = .0;
key rentalUUID = NULL_KEY;
string rentalName = "<No body>";
float rentalTime;
float elapsedRentalTime;
integer rentalSetPrice;
float rentalSetTime;
key endUUID = NULL_KEY;
string endName = "<No body>";
float endRentalTime;
integer endRentalPayd;
float ONE_WEEK = 604800.0;
float ONE_DAY = 86400.0;
float ONE_HOUR = 3600.0;
string getTimeString(integer time){
string str;
integer week;
integer days;
integer hours;
integer minutes;
integer seconds;
week = llRound(time / 604800);
time = time % 604800;
days = (time / 86400);
time = time % 86400;
hours = (time / 3600);
time = time % 3600;
minutes = time / 60;
time = time % 60;
seconds = time;
if(week)
str += (string)week + " weeks, ";
if(days)
str += (string)days + " days, ";
if(hours)
str += (string)hours + " hours, ";
if(minutes)
str += (string)minutes + " minutes, ";
if(seconds)
str += (string)seconds + " seconds, ";
if(str != "")
str = llDeleteSubString(str,-2,-1);
if(str == "")
str = "Not Set!";
return str;
}
Dialog2(key i,string str,list but){
dialogTime += 15.;
llListenRemove(lis1);
lis1 = llListen(chan,"","","");
llDialog(i,str,but,chan);
}
EndRental(){
llSetTimerEvent(.0);
elapsedRentalTime = .0;
rentalTime = 0;
rentalName = "<No body>";
rentalUUID = NULL_KEY;
rentalSetPrice = 0;
rentalSetTime = .0;
endName = "<No Body>";
endUUID = NULL_KEY;
endRentalTime = .0;
endRentalPayd = 0;
llMessageLinked(LINK_THIS, 1, "Free space|Rate L$"+(string)rentPrice+" \ week|Max: "+getTimeString((integer)rentTime), llGetKey());
}
integer subPrice;
integer Config1(key i,string m){
if(m == "Set price"){
Dialog2(i,"Price: "+(string)subPrice+"L$",["Ok"]);
return subPrice;
}
else if(m == "Reset price")
subPrice = 0;
else
subPrice = (integer)((string)subPrice+m);
Dialog2(i,"(Set price)\n"+(string)subPrice+"L$",butPrice);
return subPrice;
}
integer subTime;
integer Config2(key i,string m){
if(m == "Hour+")
subTime += 3600;
else if(m == "Hour-")
subTime -= 3600;
else if(m == "Day+")
subTime += 86400;
else if(m == "Day-")
subTime -= 86400;
else if(m == "Week+")
subTime += 604800;
else if(m == "Week-")
subTime -= 604800;
else if(m == "Set time"){
Dialog2(i,"Time: "+(string)getTimeString(subTime),["Ok"]);
return subTime;
}
else if(m == "Reset time")
subTime = 0;
Dialog2(i,"(Set time)\n"+getTimeString((integer)subTime),butTime);
return subTime;
}
TextInfo(){
llWhisper(0,"Price: L$ "+(string)rentPrice+" / week\nMax time: "+getTimeString((integer)rentTime)+"\n---------------------\nRenter: "+rentalName+"\nEnd user: "+endName+
"\n---------------------\nPrice: L$ "+(string)rentalSetPrice+"\nTime: "+getTimeString((integer)rentalSetTime));
}
DisplayInfo(){
llMessageLinked(LINK_THIS, 1, "COST: "+(string)rentalSetPrice+"|PAID: "+(string)endRentalPayd+"|BUYER: "+endName, llGetKey());
}
default{
touch_end(integer e){
if(llDetectedKey(0) == owner){
subTime = subPrice = 0;
if(dialogTime == .0)
llSetTimerEvent(5.);
Dialog2(owner,"(Menu)",["Price","Time","Info","Activet"]);
}
}
listen(integer c,string n,key i,string m){
if(i == owner){
if(m == "Info")
TextInfo();
else if(m == "Activet"){
llMessageLinked(LINK_THIS, 1, "Free space|Rate L$"+(string)rentPrice+" \ week|Max: "+getTimeString((integer)rentTime), llGetKey());
llSetTimerEvent(.0);
state active;
}
else if(~llListFindList(butPrice,[m]) || m == "Price")
rentPrice = Config1(i,m);
else if(~llListFindList(butTime,[m]) || m == "Time")
rentTime = (float)Config2(i,m);
}
}
timer(){
float elapsedTime = llGetTime();
llResetTime();
if((dialogTime -= elapsedTime) <= .0){
dialogTime = .0;
llListenRemove(lis1);
llSetTimerEvent(.0);
}
}
run_time_permissions(integer p){
if(!(p & PERMISSION_DEBIT)){
llOwnerSay("Debit perm not set! Reseting script...");
llResetScript();
}
}
state_entry(){
owner = llGetOwner();
llRequestPermissions(owner,PERMISSION_DEBIT);
chan = (integer)llGetSubString("0x"+(string)llGetKey(),-1,-5);
}
on_rez(integer r){
llResetScript();
}
}
state active{
state_entry(){
}
touch_end(integer e){
key id = llDetectedKey(0);
if(id == rentalUUID){
Dialog2(rentalUUID,"(Renter Menu)",["Price","Time","End rental","Info"]);
}
else if(id == owner)
Dialog2(owner,"(Owner menu)",["No refund","Refund","Info"]);
else
Dialog2(id,"(Menu)",["Info"]);
}
listen(integer c,string n,key i,string m){
if(m == "Info")
TextInfo();
else if(i == rentalUUID){
if(m == "End rental")
Dialog2(rentalUUID,"(Menu)\nEnd rental with no refun?",["No ref!","Cancel"]);
else if(m == "No ref!")
EndRental();
else if(~llListFindList(butPrice,[m]) || m == "Price")
rentalSetPrice = Config1(i,m);
else if(~llListFindList(butTime,[m]) || m == "Time")
rentalSetTime = (float)Config2(i,m);
if(rentalSetTime+elapsedRentalTime > rentTime+120.){
rentalSetTime = 0;
llInstantMessage(rentalUUID,"Time set is greater then max rental time allowd");
}
DisplayInfo();
}
else if(i == owner){
if(m == "No refund")
Dialog2(owner,"(Owner menu)\nEnd rental with no refund?",["No ref!","Cancel"]);
else if(m == "Refund")
Dialog2(owner,"(Owner menu)\nEnd rental with refund?",["Ref!","Cancel"]);
else if(m == "No ref!")
EndRental();
else if(m == "Ref!"){
integer amt = (integer)(rentalTime * rentPrice / ONE_WEEK);
if(amt)
llGiveMoney(rentalUUID,amt);
EndRental();
}
}
}
timer(){
float elapsedTime = llGetTime();
llResetTime();
rentalTime -= elapsedTime;
elapsedRentalTime += elapsedTime;
endRentalTime -= elapsedTime;
dialogTime -= elapsedTime;
if(rentalTime <= .0 && rentalUUID != NULL_KEY){
llInstantMessage(rentalUUID,"Your rental time at "+llGetRegionName()+" has now ended.");
EndRental();
}
if(endRentalTime <= .0 && endUUID != NULL_KEY){
llInstantMessage(endUUID,"Your rental time at "+llGetRegionName()+" has now ended.");
endName = "<No Body>";
endUUID = NULL_KEY;
endRentalTime = .0;
endRentalPayd = 0;
DisplayInfo();
}
if(dialogTime <= .0){
dialogTime = .0;
llListenRemove(lis1);
}
}
money(key i,integer amt){
float sum;
sum = ONE_WEEK * amt / rentPrice;
if(i == rentalUUID && sum + rentalTime + elapsedRentalTime <= rentTime){
rentalTime += sum;
llInstantMessage(rentalUUID,"You have refiled for "+getTimeString((integer)sum)+"\nand your total time is "+getTimeString((integer)sum));
}
else if(rentalUUID == NULL_KEY && sum <= rentTime){
rentalUUID = i;
rentalName = llKey2Name(rentalUUID);
rentalTime = sum;
llResetTime();
llInstantMessage(rentalUUID,"Your time left is "+getTimeString((integer)sum));
llSetTimerEvent(30.);
}
else if(i == endUUID && endRentalPayd+amt <= rentalSetPrice){
endRentalTime += rentalSetTime * amt / rentalSetPrice;
endRentalPayd += amt;
llGiveMoney(rentalUUID,amt);
llInstantMessage(endUUID,"Your time left is "+getTimeString((integer)endRentalTime));
}
else if(endUUID == NULL_KEY && amt >= rentalSetPrice*25/100 && amt <= rentalSetPrice && rentalUUID != NULL_KEY){
endUUID = i;
endName = llKey2Name(endUUID);
endRentalTime = rentalSetTime * amt / rentalSetPrice;
endRentalPayd = amt;
llGiveMoney(rentalUUID,amt);
llInstantMessage(endUUID,"Your time left is "+getTimeString((integer)endRentalTime));
}
else
llGiveMoney(i,amt);
DisplayInfo();
}
}
答案 0 :(得分:0)
重新编码以使用LSL wiki / llGetUnixTime
这为代码提供了易于使用的设定时间点。
integer rental_expires = 0;
integer number_of_days_per_payment = 7;
integer secs_per_day = 86400; // ((60 * 60)*24)
add_time_to_rental()
{
integer time_to_add = (secs_per_day*number_of_days_per_payment);
if(rental_expires == 0)
{
rental_expires = llGetUnixTime() + time_to_add;
}
else
{
rental_expires = rental_expires + time_to_add;
}
}
在租约到期时获取 Unix2DateTime有点啰嗦
string timeleft()
{
integer secs_left = rental_expires - llGetUnixTime();
if(secs_left > 0)
{
integer mins_left = llFloor(secs_left / 60);
integer hours_left = llFloor(mins_left / 60);
integer days_left = llFloor(hours_left / 24);
integer weeks_left = llFloor(days_left / 7);
// correct the values
if(weeks_left > 0) days_left = days_left - (weeks_left*7);
if(days_left > 0) hours_left = hours_left - (days_left*24);
if(hours_left > 0) mins_left = mins_left - (hours_left*60);
return ""+(string)weeks_left+"weeks, "+(string)days_left+"days, "+(string)hours_left+"hours and "+(string)mins_left+"mins";
}
else return "Expired";
}
现在您可以拥有一个每60秒运行一次的计时器事件,以检查租借是否已过期
if(llGetUnixTime() > rental_expires) llOwnerSay("Rental has expired");
一旦所有这些都到位并且正常工作,您应该有更多的空白,以便您添加其他代码来处理第二个租房者。