so needing a break from my current heavy project i wrote this up, has fast pay, checks price, gives change, and if someone over the age limit it refuses service and refunds their money
CODE
//<--------------------------------------------------------------------------------------->//
//<------------------------------ Age checking basic 1 item vendor ----------------------->//
//<--------------------------------------------------------------------------------------->//
//Setup
integer age = 91; // Chceks with a GMT timestamp
integer price = 10; // Sets the sale price
string item_name = "object"; // must be inside of "" and exactly the same...
//as the item name inside the vending prim
//End Setup
key user_key;
key owner_key;
integer paid;
string check_age(string data)
{
float av_total_days = do_math(data);
data = llGetDate();
float td_total_days = do_math(data);
data = (string)llRound((td_total_days - av_total_days) * 365);
return data;
}
float do_math(string data)
{
float data =(
((float)llGetSubString(data,5,6)/12)+
((float)llGetSubString(data,8,9)/365)+
((float)llGetSubString(data,0,3))
);
return data;
}
default //Starts things off by asking you for debit permissions
// later on this lets the object take money from you incase of mispayment or change
{
// I use number values 2 is the same as PERMISSION_DEBIT, habbit ...
state_entry()
{
llSetPayPrice(PAY_HIDE,[price,PAY_HIDE,PAY_HIDE,PAY_HIDE]);
llRequestPermissions(llGetOwner(),2);
}
run_time_permissions(integer perm)
{
if (perm & 2) state online;
else
{
llOwnerSay("please grant the permission to continue");
llRequestPermissions(llGetOwner(),2);
}
}
}
state online
{
on_rez(integer r) {llResetScript();}
money(key id, integer amount)
{
user_key = id;
paid = amount;
state no_money;
}
}
state no_money //Blocks out money while info is processed
{
on_rez(integer r) {llResetScript();}
state_entry(){llRequestAgentData(user_key,DATA_BORN);}
dataserver(key kQueryid, string data)
{
data = check_age(data);
if ((integer)data <= age)
{
if (paid == price) llGiveInventory(user_key,item_name);
else if (paid > price)
{
llGiveMoney(user_key,paid - price);
llGiveInventory(user_key,item_name);
}
else
{
llGiveMoney(user_key,paid);
llInstantMessage(user_key,
"you gave me "+(string)paid+"L$, but the item cost "+(string)price+"L$");
}
}
else
{
llInstantMessage(user_key, "im sorry but you are too old");
llGiveMoney(user_key,paid);
}
state online;
}
}