Script Continued
PHP Code:
function onCreated () {
setimg("door.png");
setshape (1,32,32);
this.open = off;
}
//#CLIENTSIDE
function onPlayerChats () {
if (player.chat.starts == "/open" && clientr.staff == 1) {
this.timeOpen = player.chat.substring(6).trim();
this.show();
this.open = on;
this.chat = "Open for "@this.timeOpen@" seconds";
sleep(this.timeOpen);
this.hide();
this.open = off;
this.chat = "";
}
}
function onPlayerGrabs () {
if (this.open == "on") {
setlevel2 ("level_name.nw", 30, 30);
}
}
Last edited by iMask; 01-14-2015 at 02:49 PM.
Hi, A few things to take into consideration.
Would be a string so it should bePHP Code:
this.open = off;
And because you did not put the apostrophes to signal it is a string you can not use an if statement asking if it is certain string.PHP Code:
this.open = "off";
Good job none the less, that is all I noticed from a first glance I'll check the whole thing another time!
Noof was here.
Weird, because the code below is tested, and it works (tested on the testbed server)
Spawn Staff Blocks
IN THE CLASS:PHP Code:
//Coded by iMask
findplayer("id").addWeapon(name);
function onActionServerSide () {
putnpc2 (player.x + 0.5, player.y + 0.5, "join \"imask_block\");");
}
//#CLIENTSIDE
function onCreated () {
this.on = false;
}
function onPlayerChats () {
if (player.chat == "/block on") {
this.on = true;
player.chat = "On! Press 5 to spawn blocks!";
}
if (player.chat = "/block off") {
this.on = false;
player.chat = "Off!";
}
}
function onKeyPressed (code,key) {
if (this.on == true && temp.key == 5) {
player.chat = "Spawned! Slash to destroy!";
triggerserver ("gui", this.name, NULL);
}
}
PHP Code:
function onCreated () {
setimg ("block.png");
setshape (1,32,32);
}
function onWa**** () { //function onWas-Hit, Era Go censored it
this.destroy();
}
Jail script
PHP Code:
//Coded by iMask
findplayer("id").addweapon(name);
function onActionServerSide () {
if (pl.account == player.jail) {
setlevel2 ("jail.nw", 30, 30);
}
}
//#CLIENTSIDE
function onPlayerChats () {
if (player.chat.starts == "/jail");
player.jail = player.chat.substring(5).trim();
triggerserver("gui", this.name, player.jail);
}
}
Since I have not updated this thread in ages, I'll post a fully functional lottery script. I still have to add a timer, but other than that, I'm happy with the results.
Lottery Script
PHP Code:
//Coded by iMask
function onPlayerLogin(temp.pl) {
temp.pl.addweapon(this.name);
}
function onActionServerSide(temp.cmd) {
switch(temp.cmd) {
case"one":
if (clientr.coins < 25) {
player.chat = "I don't have enough to buy a lottery ticket!";
return;
}
if (clientr.coins >= 25) {
clientr.coins -= 25;
this.jackpot += 20;
player.chat = "Bought one ticket! Coins: " @ clientr.coins;
this.winners.add(player.account);
}
break;
case"reset":
echo("Lottery: " @ player.account @ " has ended the lottery!");
sleep(5);
echo("Lottery: " @ this.winners.size() @ " tickets were sold");
this.winner = int(random(0,this.winners.size()));
sleep(5);
if (findplayer(this.winners[this.winner]) == NULL) {
temp.pl = new TServerPlayer(@this.winners[this.winner]);
temp.pl.clientr.coins += this.jackpot;
serverr.lastlotterywon = temp.pl.account;
echo("Lottery Winner: Offline player " @ temp.pl.account @ " ("@temp.pl.nick@") has won!");
temp.pl.saveaccount();
temp.pl.destroy();
} else {
player.chat = "I have won the lottery!";
clientr.coins += this.jackpot;
serverr.lastlotterywon = this.winners[this.winner];
echo("Lottery Winner: Online Winner " @ this.winners[this.winner] @ ". He won " @ this.jackpot @ " coins.");
}
player.chat = this.winners[this.winner] @ " has won!";
this.winners = {};
this.jackpot = 0;
echo("Lottery: Lottery reset!");
break;
case"onlotcheck":
player.chat = this.winners.size() @ " tickets have been sold";
break;
}
}
//#CLIENTSIDE
function onCreated() {
this.winners = {};
}
function onPlayerChats() {
if (player.chat == "/lottery") {
Buy_1.visible = true;
Close.visible = true;
Timer.visible = true;
showGui();
}
if (player.chat == "/endlottery" && player.account == "Graal762515") {
triggerserver("gui",this.name,"reset");
}
if (player.chat == "/showlottery" && clientr.isStaff) {
triggerserver("gui",this.name,"onlotcheck");
}
}
function showGui() {
new GuiButtonCtrl("Buy_1") {
profile = GuiBlueButtonProfile;
x = 600;
y = 200;
width = 250;
height = 30;
text = "Buy lottery ticket (25 coins for 1 ticket)";
}
new GuiButtonCtrl("Close") {
profile = GuiBlueButtonProfile;
x = 600;
y = 230;
width = 250;
height = 30;
text = "Close";
}
new GuiTextCtrl("Timer") {
profile = GuiBlueTextProfile;
x = 1150;
y = 220;
text = this.timer;
}
}
function Buy_1.onAction() {
triggerserver("gui",this.name,"one");
}
function Close.onAction() {
Buy_1.visible = false;
Close.visible = false;
Timer.visible = false;
}
Scripts look so complicated and confusing.