Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Staff/SetAni (https://forums.graalonline.com/forums/showthread.php?t=134270163)

defaultaccount 02-06-2016 10:26 PM

Staff/SetAni
 
this script isn't working at all for me. I'm trying to make it so it sets animations for example : /ani PB_Gun21-Idle.gani

but its not working. Any help?

PHP Code:

function ChatBar.onAction() {
  
tokens ChatBar.text.tokenize();
 
  if (
tokens[0] == "/ani") {
    if (
tokens[1] == "idle") {
      
client.gani_idle tokens[2];
    } elseif (
tokens[1] == "walk") {
      
client.gani_walk tokens[2];
    }
  }



xenow 02-07-2016 09:17 AM

From what i have read online, these functions exist:

setani(str aniname, str aniparams) //Sets the gani of a player.

replaceani(str defaultaniname, str newaniname) //replaces the player's default ani with the new ani.

What you ofcourse can try to do, to narrow down your problem, is to use debugging logs with: echo(tokens);

Note: i haven't scripted for this game in a while, hope you figure it out.

callimuc 02-07-2016 11:16 AM

- What you want to do is: just set a random gani (probably to check if it's alright?)
- What your script does (or what the main goal from the original source was): replace certain ganis (idle, walk, grab, ...) for a (most likely) custom movement

Considering you stuck with the default movement and just want the animation to be seen on your player and not have it replace any other ganis (walk, grab, ...) you would first need to trigger the function. You probably want it to be done via the chat, so there are two options you've got:

1. Using onPlayerChats() and player.chat
2. Using ChatBar.onAction() and ChatBar.text

An example with the first option (which is the most common) would look like this:
PHP Code:

//#CLIENTSIDE
function onPlayerChats() {
  echo(
player.chat);


This would log your players chat into the f2 console.

Next thing you might want to do is to check if your player is saying a command. That could be done like
PHP Code:

if (player.chat.starts("/ani ")) {
  echo(
player.chat);


So whenever your players chat starts with '/ani ', the f2 console would display your players chat.

So now, you might want to pull the file name of your gani out of your players chat (example: '/ani walkslow.gani'). This means, we still need to check the players chat BUT ignore the '/ani ' part. To do so, you could use the substring() function. It works like this:
PHP Code:

echo(player.chat.substring(5)); 

This would display 'walkslow.gani' for example, if that is the gani you want to set. How the substring works? Here's a small description:
Quote:

Originally Posted by wiki.graal.net
obj.substring(index[,length]) - returns the string starting at the index and ending after the length specified

As an alternative you could also replace the index with
PHP Code:

("/ani ").length() 

So now we know how to check the players chat, if the player is about to say a simple command including further "parameters", all we need to do is set the players ani, which can be done like setAni(gani, parameters), simple as that. As an alternative you could also use player.ani = "gani"
PHP Code:

setAni("ganiName"parameters);
//or
player.ani "ganiName"


Now you can go ahead, play around with those examples and put together the script. I didn't post the full script on purpose. If you want to add scripts, you should understand what you're doing ;)


All times are GMT +2. The time now is 09:03 AM.

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