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 10-08-2011, 08:54 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Client Flags Limit

The hat system on Lexia uses client flags to store your hats. This seemed fine, until the client flag stopped accepting more hats since there is a limit on how many items a client flag could contain. I now want to store it in a database NPC. Obviously, this would change most of the hat system, so does anybody have any ideas, or alternatives to using an NPC? The hat system script is below.

PHP Code:
//#CLIENTSIDE
function onCreated() {
  if (
client.hats == NULL) {
    
client.hats "hat1.png";
  }
}

function 
onPlayerChats() {
  
tokens player.chat.tokenize(" ");
  
hats client.hats.tokenize(",");
  if (
tokens[0] == "removehat") {
    
player.attr[1] = "none.png";
  }

EDIT: I have added the ability to add hats by script to staff, and it works fine. The issue is the external RC doesn't scroll far enough. The scripted RC adjusts its size to fit though, don't know why the external RC acts that way.
__________________
Reply With Quote
  #2  
Old 10-08-2011, 09:00 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
It's better to avoid to using long amounts of data in client flags because they get truncated/cut-off in external RC.

You could store them like this:

clientr.hat.Egghat = "hat2.png";

Then to display them:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  echo(
"Hats");
  for (
temp.hatgetstringkeys("clientr.hat.")) {
    
temp.hat_image clientr.hat.(@temp.hat);
    echo(
format(" - %s: %s"temp.hattemp.hat_image));
  }

Adding a hat would be easy as putting this in your player joined class:

PHP Code:
public function addHat(hat_namehat_image) {
  
clientr.hat.(@hat_name) = hat_image;

and calling:

player.addHat("Egg Hat", "hat2.png");

This is basically an item system.
__________________
Quote:
Reply With Quote
  #3  
Old 10-08-2011, 09:24 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
I already use a public function for adding hats...
PHP Code:
public function AddHat(hatnamechattext) {
  
client.hats client.hats "," hatname;
  
say2(chattext);

But wouldn't the client flags be full of the hats you have?
__________________
Reply With Quote
  #4  
Old 10-08-2011, 09:35 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
Quote:
Originally Posted by Emera View Post
I already use a public function for adding hats...
PHP Code:
public function AddHat(hatnamechattext) {
  
client.hats client.hats "," hatname;
  
say2(chattext);

But wouldn't the client flags be full of the hats you have?
Yes.

Also why aren't you just using it like a normal array:

client.hats.add(hatname);
__________________
Quote:
Reply With Quote
  #5  
Old 10-08-2011, 09:46 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by Emera View Post
But wouldn't the client flags be full of the hats you have?
That shouldn't be much of an issue. You should see the flags for a typical Era player .
__________________
Reply With Quote
  #6  
Old 10-08-2011, 09:55 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Hey, i'm not ignoring what you guys are saying, but exploring other methods. I am using a DB-NPC called HatStorage, and storing their hats in there. Here is the code.
PHP Code:
function onCreated() {
  
this.dbnpc findnpc("HatStorage");
  for (
temp.plallplayers) {
    
this.dbnpc.(@pl.account) = pl.client.hats;
  }

Is that a good method also?
__________________
Reply With Quote
  #7  
Old 10-08-2011, 10:08 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 Emera View Post
Hey, i'm not ignoring what you guys are saying, but exploring other methods. I am using a DB-NPC called HatStorage, and storing their hats in there. Here is the code.
PHP Code:
function onCreated() {
  
this.dbnpc findnpc("HatStorage");
  for (
temp.plallplayers) {
    
this.dbnpc.(@pl.account) = pl.client.hats;
  }

Is that a good method also?
No, you'll still have the issue of attribute length. Do what Jer said, that's the best way. You also don't need to use findNPC;
PHP Code:
this.dbnpc HatStorage
works fine
__________________
Reply With Quote
  #8  
Old 10-08-2011, 10:40 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
How would I detect is a player has that hat though?
__________________
Reply With Quote
  #9  
Old 10-08-2011, 10:41 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 Emera View Post
How would I detect is a player has that hat though?
PHP Code:
if (player.clientr.hat.(@ hatname) != null) { 
__________________
Reply With Quote
  #10  
Old 10-08-2011, 10:49 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
PHP Code:
if (player.clientr.hat.(@ hatname) != null) { 
I know I am asking a lot of questions here, but I am using a chat command to add the hat. How would I add this to that. I am stumped. I tried...
PHP Code:
function onPlayerChats() {
  
hatname player.chat.substring(7);
  
this.hatstring player.clientr.hat.(@hatname);
  
tokens player.chat.tokenize(" ");
  if (
tokens[0] == "sethat") {
    if (
tokens[1in this.hatstring) {
      
player.attr[1] = hatname;
    }
  }

__________________
Reply With Quote
  #11  
Old 10-08-2011, 11:23 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
I would suggest you start using ChatBar.onAction instead of onPlayerChats, preventing players from chatting commands looks better in the end.

That said, It would look something like this:

PHP Code:
//#CLIENTSIDE
function ChatBar.onAction() {
  
// Check for sethat command
  
if (ChatBar.text.starts("sethat")) {
    
// Get Hat Name
    // I use "sethat ".length() to get the position of chat starting
    // a space after the actual command and trim the result.
    
temp.hat_name ChatBar.text.substring("sethat ".length()).trim();
    
// Check if Hat Exists in Player Flags
    
if (clientr.hat.(@temp.hat_name) != "") {
      
// Set Player's Hat
      
player.attr[1] = clientr.hat.(@temp.hat_name);
    }
    
// Clear ChatBar Text (Prevents player from chatting sethat)
    
ChatBar.text "";
  }

__________________
Quote:
Reply With Quote
  #12  
Old 10-09-2011, 12:13 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Why exactly using chatbar.onaction, it's much better to use onplayerchats.

For setting flags using non-scripted RC may we could add something to prevent cutting of the values if you don't touch it.

Storing items is best done using clientr.*hatname or so and getstringkeys().
Reply With Quote
  #13  
Old 10-09-2011, 12:21 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Stefan View Post
Why exactly using chatbar.onaction, it's much better to use onplayerchats.
Why? In the end, it's the same anyway. Either use the ChatBar and set it to an empty string before it actually sends the chat, or use onPlayerChats and set the player's chat to an empty string. Doesn't really matter, does it?
Reply With Quote
  #14  
Old 10-09-2011, 12:43 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
guys, guys, guys.. hold up, why are you telling him to use a dot in the clientr flag?

don't use "clientr.hats.hatname", instead of the second dot, use a underscore!
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #15  
Old 10-09-2011, 01:02 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Deas_Voice View Post
guys, guys, guys.. hold up, why are you telling him to use a dot in the clientr flag?

don't use "clientr.hats.hatname", instead of the second dot, use a underscore!
Uhh.. why?
Reply With Quote
  #16  
Old 10-09-2011, 01:40 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Using a dot can be dangerous because certain item names can make problems, had a problem with RC login script once when "Trigger" tried to login (built-in variables and functions).
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 01:59 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.