Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-27-2011, 05:16 PM
Trakan Trakan is offline
It's all about cats!
Trakan's Avatar
Join Date: Sep 2010
Location: France
Posts: 64
Trakan is an unknown quantity at this point
[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;

Reply With Quote
  #2  
Old 06-27-2011, 05:24 PM
Trakan Trakan is offline
It's all about cats!
Trakan's Avatar
Join Date: Sep 2010
Location: France
Posts: 64
Trakan is an unknown quantity at this point
Sorry , thanks to ninja nuhamo for helped me IG
Reply With Quote
  #3  
Old 06-27-2011, 05:33 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
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();
    }
  }

__________________
Quote:
Reply With Quote
  #4  
Old 06-27-2011, 06:04 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
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];
  }

__________________
MEEP!
Reply With Quote
  #5  
Old 06-27-2011, 09:26 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by callimuc View Post
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);
  }

__________________
Reply With Quote
  #6  
Old 06-28-2011, 11:56 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by xAndrewx View Post
hmm i would do this
PHP Code:
function onPlayerChats() {
  if (
player.chat.starts("sethat")) {
    
player.attr[1] = player.chat.substring(7);
  }

Hmm oh jea
__________________
MEEP!
Reply With Quote
  #7  
Old 07-07-2011, 02:25 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
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
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #8  
Old 07-07-2011, 06:50 AM
Conqueror Conqueror is offline
Da conq
Conqueror's Avatar
Join Date: Jun 2007
Location: Ontario, Canada
Posts: 364
Conqueror is a splendid one to beholdConqueror is a splendid one to beholdConqueror is a splendid one to beholdConqueror is a splendid one to behold
Hm, you could definitely try this

//#PRETEND_UR_SMART
function
{Make hat work



.... *runs*
__________________
_________________________________________

Reply With Quote
  #9  
Old 07-07-2011, 09:19 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Astram View Post
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 View Post
*runs*
u ez
__________________
Reply With Quote
Reply


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 07:47 PM.


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