Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Sethat with image :HELP (https://forums.graalonline.com/forums/showthread.php?t=134261607)

Twaina 01-08-2011 04:14 PM

Sethat with image :HELP
 
So my server need a normaly system when the playes chat sethat the image
so the player set the hat? I scripted and scripted my problem is when i chat sethat the image nothing comes!
pls help who can gice me so a script please?
-Twaina
______________
:noob:

cyan3 01-08-2011 04:32 PM

Try something like this:

PHP Code:

function onPlayerChats() {
  
  if (
player.chat.starts(":sethat")) {
    
player.attr[1] = player.chat.substring(8);
 }



Twaina 01-08-2011 04:44 PM

Dont working if i chat sethat or :sethat the image of hat with png/gif
i dont see a hat

cyan3 01-08-2011 04:50 PM

Quote:

Originally Posted by Twaina (Post 1621305)
Dont working if i chat sethat or :sethat the image of hat with png/gif
i dont see a hat

My mistake, I used player.attr[0] instead of player.attr[1].

I edited the script and it should be working now.

Twaina 01-08-2011 05:04 PM

īThanks

Twaina 01-08-2011 05:05 PM

Dont working if i chat sethat or :sethat the image of hat with png/gif
i dont see a hat again :/

gwFCCtennis 01-08-2011 05:23 PM

Quote:

Originally Posted by Twaina (Post 1621314)
Dont working if i chat sethat or :sethat the image of hat with png/gif
i dont see a hat again :/

Have you uploaded the image into levels/images or possibly levels/hats?

This should work, but the script Cyan posted should work.
PHP Code:

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("sethat")) {
    
player.attr[1] = client.ishat player.chat.tokenize()[1];
  }



Twaina 01-08-2011 05:43 PM

nope

gwFCCtennis 01-08-2011 05:57 PM

Quote:

Originally Posted by Twaina (Post 1621319)
nope

Have you given yourself the weapon?

Deas_Voice 01-08-2011 05:58 PM

try saying /find imagename on rc, and see if it's "downloadable" (also post your result )

fowlplay4 01-08-2011 06:23 PM

Quote:

Originally Posted by gwFCCtennis (Post 1621315)
Have you uploaded the image into levels/images or possibly levels/hats?

This should work, but the script Cyan posted should work.
PHP Code:

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("sethat")) {
    
player.attr[1] = client.ishat player.chat.tokenize()[1];
  }



Tokenize isn't good for single-parameter commands, it just ends up requiring players to use "quotes" down the line.

onPlayerChats is also a "deprecated" (imo) way of checking for chat commands on the client-side considering we can access the ChatBar directly.

Here's a pretty generic "sethat" using the ChatBar method.

PHP Code:

//#CLIENTSIDE

// This event is called when the player presses enter with the ChatBar
// open. Which basically happens every time the player chats.
function ChatBar.onAction() {
  
// Define the Command to check for
  
temp.cmd "sethat ";
  
// Check if Text in ChatBar starts with the command
  
if (ChatBar.text.starts(temp.cmd)) {
    
// Determine the Command's Parameter
    
temp.param ChatBar.text.substring(temp.cmd.length()).trim();
    
// Make sure Hat name ends with .png, .gif, or .mng
    
if (checkHat(temp.param)) {
      
// Set the Player's Hat to the Passed Parameter
      
player.attr[1] = temp.param;
    }
    
// Reset ChatBar text to prevent the player from saying the command in chat
    
ChatBar.text "";
  }
}

function 
checkHat(hatimg) {
  if (
hatimg.ends(".png") || hatimg.ends(".gif") || hatimg.ends(".mng")) {
    return 
true;
  } else {
    return 
false;
  }


Quick demo of substring, and trim.

PHP Code:

function onCreated() {
  
// string_variable.substring(start_position, length)
  // start_position is the letter it starts with first. Like arrays this is 
  // also zero-based. So in our example start_position 2 is "l"
  // If you don't specify length it just uses everything after it.
  // Note: When you're using this in commands you want the starting
  // position to be after the space in your command.
  
temp.str "Hello World";
  echo(
temp.str.substring(6)); // echos "World"
  
echo(temp.str.substring(05)); // echos "Hello"
  
  // string_variable.trim()
  // Trims off spaces in the front and back of a string, useful for commands.
  
temp.str "  HELLO WORLD!  ";
  echo(
temp.str.trim()); // echos "HELLO WORLD!"

  // Due to the fact that both trim and substring return strings you can
  // use them in a chain like I did in my sethat example. I.e:
  
temp.str "sethat averystupidhat.png  ";
  echo(
temp.str.substring(7).trim()); // echos "averystupidhat.png"


If your hats still don't work, you're probably not giving the right folder access (button on the top-right corner next to server flags) to your server.

It'll need these lines added to it if you're uploading to levels/hats:

PHP Code:

file  hats/*.png
file  hats/*.gif
file  hats/*.mng 


Twaina 01-08-2011 07:21 PM

a normaly hat system :/ not that no thanks

fowlplay4 01-08-2011 07:57 PM

Quote:

Originally Posted by Twaina (Post 1621337)
a normaly hat system :/ not that no thanks

You've been given more than enough information to create your own from the posts above.

If you aren't here to learn and only to beg for scripts please leave.

cbk1994 01-08-2011 08:26 PM

Quote:

Originally Posted by Twaina (Post 1621337)
a normaly hat system :/ not that no thanks

His hat system did exactly what you wanted it to do. If you're just looking for scripts and not even trying to learn please **** off. See you guys in another 3 months...

Deas_Voice 01-08-2011 09:48 PM

Quote:

Originally Posted by fowlplay4 (Post 1621341)
If you aren't here to learn and only to beg for scripts please leave.

Quote:

Originally Posted by cbk1994 (Post 1621348)
If you're just looking for scripts and not even trying to learn please **** off.

what they said.


All times are GMT +2. The time now is 01:28 AM.

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