Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 01-08-2011, 06: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
Quote:
Originally Posted by gwFCCtennis View Post
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 
__________________
Quote:
Reply With Quote
 


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:27 AM.


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