Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   [Help]Hat weapon (https://forums.graalonline.com/forums/showthread.php?t=134263679)

Trakan 06-27-2011 05:16 PM

[Help]Hat weapon
 
Hello everybody , i'm new to GS2 and i try to make simple scripts for my server. I have started a hat weapon but it not work :/
Who can re-make it?
PHP Code:

// Scripted by *Trakan

//#CLIENTSIDE
function onWeaponFired() {
player.attr[1] = mattsmask1.png;



Trakan 06-27-2011 05:24 PM

Sorry , thanks to ninja nuhamo for helped me IG

fowlplay4 06-27-2011 05:33 PM

I guess you solved your problem but for thread completion sake...

In GS2 you have to use double-quotes on strings (text). I.e:

player.attr[1] = "mattsmask1.png";

You should also get in the habit of indenting your scripts. I.e:

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  
player.attr[1] = "mattsmask1.png";


It'll help down the line when you start using if statements, and the like. It also improves readability and makes your code easier to maintain. I.e:

PHP Code:

function onCreated() {
  if (
whatever) {
    
dowhatever();
    if (
areusure) {
      
yep();
    } else {
      
nope();
    }
  }



callimuc 06-27-2011 06:04 PM

Since a lot of people have problems with sethat and so on, here is a script for the sethat command. Ik this is not your request but maybe it will help people in the future:
PHP Code:

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



xAndrewx 06-27-2011 09:26 PM

Quote:

Originally Posted by callimuc (Post 1656403)
Since a lot of people have problems with sethat and so on, here is a script for the sethat command. Ik this is not your request but maybe it will help people in the future:
PHP Code:

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



hmm i would do this
PHP Code:

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



callimuc 06-28-2011 11:56 PM

Quote:

Originally Posted by xAndrewx (Post 1656464)
hmm i would do this
PHP Code:

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



Hmm oh jea :blush:

Astram 07-07-2011 02:25 AM

You can also like add some funk to the hat adding script.
PHP Code:

//#CLIENTSIDE
function onWeaponFired()
  {
  
this.hat "hat1.png";
  if (
clientr.lasthat != this.hat)
    {
    
player.attr[1] = this.hat;
    
clientr.lasthat player.attr[1];
    
setAni("Equiphat",NULL);
    }
  else
    {
    
setAni("Removehat",NULL);
    
player.attr[1] = "no-hat.png";
    
clientr.lasthat player.attr[1];
    }
  } 

In the gani make the "hat" image ATTR1
and
make this.hat in a script be the hats imagename.
If you want it as a class for easy use just ask me ;)

Conqueror 07-07-2011 06:50 AM

Hm, you could definitely try this

//#PRETEND_UR_SMART
function
{Make hat work



.... *runs*

cbk1994 07-07-2011 09:19 AM

Quote:

Originally Posted by Astram (Post 1657699)
You can also like add some funk to the hat adding script.
PHP Code:

//#CLIENTSIDE
function onWeaponFired()
  {
  
this.hat "hat1.png";
  if (
clientr.lasthat != this.hat)
    {
    
player.attr[1] = this.hat;
    
clientr.lasthat player.attr[1];
    
setAni("Equiphat",NULL);
    }
  else
    {
    
setAni("Removehat",NULL);
    
player.attr[1] = "no-hat.png";
    
clientr.lasthat player.attr[1];
    }
  } 

In the gani make the "hat" image ATTR1
and
make this.hat in a script be the hats imagename.
If you want it as a class for easy use just ask me ;)

That script could be rewritten as:

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  
this.hat "hat1.png";
  
  if (
player.attr[1] == this.hat) {
    
player.attr[1] = "";
    
setAni("removehat"null);
  } else {
    
player.attr[1] = this.hat;
    
setAni("equiphat"null);
  }


Keep in mind you can't change clientr variables on clientside. Also, work on your styling, it's really important in scripting.

Quote:

Originally Posted by Conqueror (Post 1657738)
*runs*

u ez


All times are GMT +2. The time now is 08:44 PM.

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