Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-19-2011, 10:35 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Send a message via Skype™ to Gunderak
Lottery NPC

Basically i got the idea from xXAndrewXx.
But i noticed somthing with his script.
The information isn't stored properly, meaning if the npc server were restarted or someone updated the level all the data would disappear.
so i set off to script it from scratch.
here is my problem, i cant figure out how to make serverr.winner be the winner.
here is what i would like it to do, if any player has clientr.Ticket=1 there a potential candidate for the winner flag.
here is my script so far.

Graal Script Code:
function onCreated(){
  
onUpdateText();
}
function 
onPlayertouchsme(){
  
say2("To Buy A Lottery Ticket Say #b''/Buy Ticket'' It Cost 20 Gralats!#bThe Lottery Is Drawn At Random#bIf You Are Chosen At Random#bYoul Win The Jackpot!");
}
function 
onUpdateText(){
  if(
serverr.jackpot == 0){
    
this.chat "The Current Jackpot Is 0 Gralats.";
    return;
  }
  
this.chat "The Current Jackpot Is "@serverr.jackpot@" Gralats.";
}
function 
onPlayerchats(){
  if(
player.chat == "/Buy Ticket"){
    if(
clientr.Ticket == 1){
      
player.chat "I Have Already Purchased A Ticket!";
      return;
    }
    if(
player.rupees 20){
      
player.chat "I Dont Have Enough Money!";
    }
    if(
player.rupees 19){
      
clientr.Ticket=1;
      
player.chat "I Brought A Lottery Ticket!";
      
player.rupees -= 20;
      
serverr.jackpot += 20;
      
onUpdateText();
    }
  }
  if(
player.chat == "/Draw Lottery"){
    if(
clientr.isStaff){
      
onAwardWinner();
    }
  }
}
function 
onAwardWinner(){
  for (
temp.pl allplayers){
    
findplayer(temp.pl).clientr.Ticket=0;
  }
  echo(
"Lottery: "@serverr.winner@" Has Won The Lottery! They Won: "@serverr.jackpot@" Gralats!");
  
findplayer(serverr.winner).rupees += serverr.jackpot;
  
serverr.jackpot 0;
  
onUpdateText();

__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 08-19-2011, 01:13 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
1. Would be best if you post the original link. Lottery System

2.
Quote:
Originally Posted by Gunderak View Post
The information isn't stored properly, meaning if the npc server were restarted or someone updated the level all the data would disappear.
Did you make it a class/level NPC or as a DB-NPC? I think the one from Andrew needs to be a DB-NPC
__________________
MEEP!
Reply With Quote
  #3  
Old 08-19-2011, 01:54 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Send a message via Skype™ to Gunderak
Mine i made as a level npc.
how would i accomplish the same thing without using a db npc do you know?
thanks btw.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 08-19-2011 at 03:34 PM..
Reply With Quote
  #4  
Old 08-19-2011, 09:14 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
I don┤t think you can store stuff without using a DB. Only way would be to store the players in server flags OR to save them in a text file where you read it from.
__________________
MEEP!
Reply With Quote
  #5  
Old 08-19-2011, 09:27 PM
PowerProNL PowerProNL is offline
Retired Zone Manager
PowerProNL's Avatar
Join Date: Feb 2008
Location: Holland
Posts: 266
PowerProNL can only hope to improve
Send a message via AIM to PowerProNL
I'd prefer making it databased, but nice work
__________________
Graal Mail: [email protected]
McPowerProNL, I'm loving it
Reply With Quote
  #6  
Old 08-19-2011, 09:32 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You can use a DB to store the people who entered the lottery like this:

DB-NPC: Lottery

Graal Script Code:
// Adds account to the list of lottery entries
public function addAccount(acct) {
  if (
inLottery(acct)) {
    
// Already in lottery
    
return false;
  } else {
    
// Add to lottery
    
this.lottery.add(acct);
    
this.trigger("update"); // Force-saves DB
    
return true;
  }
}

// Checks if acct is entered in the lottery
public function inLottery(acct) {
  return (
acct in this.lottery);
}

// Clears accounts entered in the lottery
public function clearAccounts() {
  
this.lottery "";
}

// Picks a random person entered in the lottery.
public function pickLotteryWinner() {
  return 
this.lottery[int(random(0this.lottery.size()))];

To add a player to the lottery use:
Lottery.addAccount(player.account);

To check if a player is in the lottery use:
if (Lottery.inLottery(player.account))

To pick a winner use:
temp.winner = Lottery.pickLotteryWinner();

To clear the lottery entries:
Lottery.clearAccounts();

You don't have to store any information in the player's or server flags, you can also expand upon this and add/update/store the "Jackpot" amount in it as well but I'm not going to do everything for you.
__________________
Quote:

Last edited by fowlplay4; 08-19-2011 at 09:45 PM..
Reply With Quote
  #7  
Old 08-19-2011, 10:31 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
Graal Script Code:
function onAwardWinner(){
  for (
temp.pl allplayers){
    
findplayer(temp.pl).clientr.Ticket=0;
  } 
In addition to what Jer said, the above code is incorrect, although it technically works. allPlayers is an array of player objects, not accounts. That means you could just do this:

Graal Script Code:
for (temp.pl allplayers) {
  
temp.pl.clientr.Ticket=0;

For comparison, using findPlayer like you did would be equivalent to doing

Graal Script Code:
findPlayer(player).client.Ticket=0
The reason it works even though temp.pl is not an account is that the object is coerced into a string, which just happens to be the player's account (since temp.pl.name would equal temp.pl.account).

Thanks for taking the time to either style your code or run it through Jer's beautifier before posting it.
__________________
Reply With Quote
  #8  
Old 08-19-2011, 10:41 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Another thing to note is your usage of serverr variables. Judging by your script you really only need to use server (only one r) variables because you aren't accessing them on the client-side and are instead using player chat to display it.

serverr variables are stored on the server-side and synced with the client-side.
server variables are just stored on the server-side.
__________________
Quote:
Reply With Quote
  #9  
Old 08-20-2011, 03:40 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Send a message via Skype™ to Gunderak
Talking

Thanks fowlplay for explaining it clearly how to use database npcs
without your help id probably be stuck for the next week
and cbk1994 i copied it into the offline level editor inside a npc and clicked style.
@Everyone thanks for your help
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 08-20-2011 at 03:52 AM..
Reply With Quote
  #10  
Old 08-20-2011, 03:44 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Send a message via Skype™ to Gunderak
I forgot to ask, when rewarding the players the jackpot would this work?
Graal Script Code:
findplayer(temp.winner).rupees += server.jackpot;
server.jackpot 0
would that work even if they are offline?
thats another problem im likely to face.
and thanks fowlplay server variables work for this.
so serverr variables are accesible clientside?
and server variables are acessible serverside?
can they both be written server and clientside?
thanks
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 08-20-2011 at 03:55 AM..
Reply With Quote
  #11  
Old 08-20-2011, 03:52 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
DB-NPC's script, I labeled it as such.

and no, it returns the account of the player not the object. That's when you would use findplayer. I.e:

findplayer(temp.winner).rupees += jackpot;

Rather than having your script award them directly, you could just have the NPC pick a winner and hand out the amount yourself.

There is a way to add to people who are offline though but you should fix your scripts existing problems before you introduce more.

Use my beautifier instead of the level editor, it does a lot more than indenting. Link: http://fp4.ca/gs2beautifier
__________________
Quote:
Reply With Quote
  #12  
Old 08-20-2011, 04:34 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Send a message via Skype™ to Gunderak
Ah ok, i think il do the awarding my self and then later if i can be bothered make it automatic, il make it send the winner to rc maybe.
also nice work with the styler, did the makers of the original one give you the source code? or is it publicly avaliable?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #13  
Old 08-20-2011, 04:41 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Gunderak View Post
also nice work with the styler, did the makers of the original one give you the source code? or is it publicly avaliable?
The source code for the original project is publicly available here:
http://github.com/einars/js-beautify
__________________
Quote:
Reply With Quote
  #14  
Old 08-20-2011, 09:35 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Send a message via Skype™ to Gunderak
Graal Script Code:
public function pickLotteryWinner() {
  return 
this.lottery[int(random(0this.lottery.size()))];

@Fowlplay this picks the first person who entered the lottery. X_X
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #15  
Old 08-20-2011, 10:14 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
@Fowlplay this picks the first person who entered the lottery. X_X
Have you tried debugging it? What steps did you take to debug it? Did you make sure there were multiple people in the array when you ran it?

At the very least, post your whole script. It's very hard to help you when you don't provide any information besides "it's not working X_X!".
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:17 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.