A working hotel script!!!!
Thanks to The Doctor for helping me with the command
PHP Code:
if (temp.var.time <= 0) {
Weapon Script:
PHP Code:
function onActionServerSide(temp.cmd, acc, time, days) {
switch (temp.cmd) {
case "add":
if (clientr.coins < 500 * days) {
player.chat = "Not enough coins to rent that many days!!";
return;
}
this.i++;
temp.var = requestsql("INSERT INTO 'Hotel' (account,time,room) VALUES ('" @ acc @ "','" @ time @ "','" @ this.i @ "')", true);
PlayerControl.tabEcho("Game", acc @ " has rented room #" @ i @ "! Now has " @ clientr.coins - 500 * days @ " coins!");
player.chat = "Rented a room! I have the keys to room " @ this.i;
clientr.coins -= 500 * days;
client.room = this.i;
client.hotel = true;
break;
}
}
//#CLIENTSIDE
function onCreated() {
this.i = 0;
}
function onPlayerChats() {
if (player.level != "cor_cityhall1.nw") return;
if (player.chat.starts("/rent") && client.hotel == NULL) {
temp.token = player.chat.tokenize();
if (temp.token[1] == NULL) {
say2("Correct format: /rent <time>");
return;
}
triggerserver("gui", this.name, "add", player.account, temp.token[1] * 86400, temp.token[1]);
return;
} else if (player.chat.starts("/rent") && client.hotel == true) {
say2("Already rented a room!");
}
//DEBUG
if (player.chat == "reset hotel") {
client.hotel = "";
client.room = "";
player.chat = "Reset client.hotel and client.room!";
}
}
DB Script:
PHP Code:
function onCreated() {
onTimeOut();
}
function onTimeOut() {
requestsql("UPDATE Hotel SET time = (time - 10)", false);
temp.var = requestsql("SELECT * FROM 'Hotel'", true);
if (temp.var.rows.size() == 0) {
setTimer(10);
return;
}
if (temp.var.time <= 0) {
requestsql("DELETE FROM 'Hotel' WHERE account = '" @ temp.var.account @ "'",true);
temp.findofflineplayer = findplayer(temp.var.account);
if (temp.findofflineplayer == NULL) {
temp.pl = new TServerPlayer(@temp.var.account);
PlayerControl.tabEcho("Game","Offline Player " @ temp.var.account @ "'s hotel rent ended!");
temp.pl.client.hotel = "";
temp.pl.client.room = "";
temp.pl.saveaccount();
temp.pl.destroy();
setTimer(10);
} else if (temp.findofflineplayer != NULL) {
with(findplayer(temp.var.account)) {
client.hotel = "";
client.room = "";
PlayerControl.tabEcho("Game","Online player " @ temp.var.account @ "'s hotel rent ended!");
setTimer(10);
}
}
}
setTimer(10);
}