Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Client Flags Limit (https://forums.graalonline.com/forums/showthread.php?t=134264744)

Emera 10-08-2011 08:54 PM

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.

fowlplay4 10-08-2011 09:00 PM

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.

Emera 10-08-2011 09:24 PM

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?

fowlplay4 10-08-2011 09:35 PM

Quote:

Originally Posted by Emera (Post 1670352)
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);

salesman 10-08-2011 09:46 PM

Quote:

Originally Posted by Emera (Post 1670352)
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 :p.

Emera 10-08-2011 09:55 PM

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?

cbk1994 10-08-2011 10:08 PM

Quote:

Originally Posted by Emera (Post 1670356)
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

Emera 10-08-2011 10:40 PM

How would I detect is a player has that hat though?

cbk1994 10-08-2011 10:41 PM

Quote:

Originally Posted by Emera (Post 1670363)
How would I detect is a player has that hat though?

PHP Code:

if (player.clientr.hat.(@ hatname) != null) { 


Emera 10-08-2011 10:49 PM

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;
    }
  }



fowlplay4 10-08-2011 11:23 PM

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 "";
  }



Admins 10-09-2011 12:13 PM

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().

Crow 10-09-2011 12:21 PM

Quote:

Originally Posted by Stefan (Post 1670394)
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?

Deas_Voice 10-09-2011 12:43 PM

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!

Crow 10-09-2011 01:02 PM

Quote:

Originally Posted by Deas_Voice (Post 1670398)
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?

Admins 10-09-2011 01:40 PM

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).


All times are GMT +2. The time now is 03:14 PM.

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