Graal Forums

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

mrnothersan 05-09-2011 07:12 PM

Weapon
 
I know not to ask for scripts but i'm sure this will be just a short 3 line script...:p Can anybody tell me the script to give a certain tool to every player?:confused:
It will be a great help :)

Regards

Emera 05-09-2011 07:33 PM

PHP Code:

 function onActionPlayerOnline() {
 
addweapon("WEAPON NAME");


Put that at the top of your control NPC.

fowlplay4 05-09-2011 07:34 PM

A lot of servers use a script like this in Control-NPC.

In Control-NPC:

PHP Code:

function onActionPlayerOnline() {
  
// Array of weapons to add to the player.
  
temp.weps = {
    
"-System""OtherWeapon""Example"
  
};
  
// Loops through each weapon in the array and adds it to the player.
  
for (temp.weptemp.weps) {
    
player.addweapon(temp.wep);
  }



mrnothersan 05-09-2011 09:19 PM

Quote:

Originally Posted by Emera (Post 1648600)
PHP Code:

 function onActionPlayerOnline() {
 
addweapon("WEAPON NAME");


Put that at the top of your control NPC.

Right... so my NPC script currently looks like this:
PHP Code:

function onActionPlayerOnline() { 
  
player.addWeapon("testgui","Tailor"); 


(from a previous script and i just add
PHP Code:

,"Tailor" 

... will it still work if i remove
PHP Code:

player

?


EDIT: I removed player. and applied... entered game and it 1.Removed all my tools. 2.Didn't give me testgui or Tailor....

WhiteDragon 05-09-2011 09:52 PM

Quote:

Originally Posted by mrnothersan (Post 1648614)
Right... so my NPC script currently looks like this:
PHP Code:

function onActionPlayerOnline() { 
  
player.addWeapon("testgui","Tailor"); 


(from a previous script and i just add
PHP Code:

,"Tailor" 

... will it still work if i remove
PHP Code:

player

?


EDIT: I removed player. and applied... entered game and it 1.Removed all my tools. 2.Didn't give me testgui or Tailor....

It seems like you have some critical misunderstandings of GS2. Adding more parameters to a function, like you just did with addWeapon, does not call it twice.

Look at what Fowlplay posted if you want to add multiple items. He uses the proper structure to do this (an array).

Emera 05-09-2011 09:53 PM

player.addweapon? dude just copy n paste what i wrote...

cbk1994 05-09-2011 09:54 PM

Quote:

Originally Posted by mrnothersan (Post 1648614)
Right... so my NPC script currently looks like this:
PHP Code:

function onActionPlayerOnline() { 
  
player.addWeapon("testgui","Tailor"); 


(from a previous script and i just add
PHP Code:

,"Tailor" 

... will it still work if i remove
PHP Code:

player

?


EDIT: I removed player. and applied... entered game and it 1.Removed all my tools. 2.Didn't give me testgui or Tailor....

Don't remove the prefix. The code Jer posted was perfect:

Quote:

Originally Posted by fowlplay4 (Post 1648601)
PHP Code:

function onActionPlayerOnline() {
  
// Array of weapons to add to the player.
  
temp.weps = {
    
"-System""OtherWeapon""Example"
  
};
  
// Loops through each weapon in the array and adds it to the player.
  
for (temp.weptemp.weps) {
    
player.addweapon(temp.wep);
  }



TServerPlayer.addWeapon(str) only accepts one parameter (the weapon name). To add multiple weapons, you have to call it multiple times.

PHP Code:

function onActionPlayerOnline() {
  
player.addWeapon("-System");
  
player.addWeapon("-Tailor");
  
// etc


Jer's example (which I quoted above) does the same thing in a much nicer way using loops and arrays.

WhiteDragon 05-09-2011 09:55 PM

Quote:

Originally Posted by Emera (Post 1648626)
player.addweapon? dude just copy n paste what i wrote...

player.addweapon(string) is the correct way to call it. Without the player. works, but it is not as clear what it does.

mrnothersan 05-09-2011 10:08 PM

Quote:

Originally Posted by fowlplay4 (Post 1648601)
A lot of servers use a script like this in Control-NPC.

In Control-NPC:

PHP Code:

function onActionPlayerOnline() {
  
// Array of weapons to add to the player.
  
temp.weps = {
    
"-System""OtherWeapon""Example"
  
};
  
// Loops through each weapon in the array and adds it to the player.
  
for (temp.weptemp.weps) {
    
player.addweapon(temp.wep);
  }



Just tried
PHP Code:

function onActionPlayerOnline() {
  
// Array of weapons to add to the player.
  
temp.weps = {
    
"testgui""Tailor"
  
};
  
// Loops through each weapon in the array and adds it to the player.
  
for (temp.weptemp.weps) {
    
player.addweapon(temp.wep);
  }


... Played as a Guest on my server and spawned with no weapons at all...

Emera 05-09-2011 10:25 PM

Ugh

mrnothersan 05-09-2011 10:30 PM

Quote:

Originally Posted by Emera (Post 1648640)
Ugh

-.- i tried yours too:
PHP Code:

function onActionPlayerOnline() {
 
addweapon("Tailor");


and again:
Quote:

Played as a Guest on my server and spawned with no weapons at all...

cbk1994 05-09-2011 10:30 PM

Quote:

Originally Posted by mrnothersan (Post 1648633)
Just tried
PHP Code:

function onActionPlayerOnline() {
  
// Array of weapons to add to the player.
  
temp.weps = {
    
"testgui""Tailor"
  
};
  
// Loops through each weapon in the array and adds it to the player.
  
for (temp.weptemp.weps) {
    
player.addweapon(temp.wep);
  }


... Played as a Guest on my server and spawned with no weapons at all...

Where did you put the script? Try adding an echo in that function to see if it's being called.

mrnothersan 05-09-2011 10:36 PM

Quote:

Originally Posted by cbk1994 (Post 1648642)
Where did you put the script? Try adding an echo in that function to see if it's being called.

The script is in the NPC-Control...
And if you look at all the Treads and Posts i've made you will have probably noticed im completely new to all this... so... how would i do that... :)

cbk1994 05-09-2011 11:39 PM

Quote:

Originally Posted by mrnothersan (Post 1648647)
The script is in the NPC-Control...
And if you look at all the Treads and Posts i've made you will have probably noticed im completely new to all this... so... how would i do that... :)

It should be in the script of the DBNPC named Control-NPC, not NPC-Control. Is it?

add
PHP Code:

echo("it works!"); 

to anywhere you want to test.

mrnothersan 05-10-2011 03:01 PM

sorry for late reply:\
Quote:

Originally Posted by cbk1994 (Post 1648670)
It should be in the script of the DBNPC named Control-NPC, not NPC-Control. Is it?

add
PHP Code:

echo("it works!"); 

to anywhere you want to test.

yeah i mean Control-NPC
and i put
PHP Code:

echo("it works!"); 

in the script and got "it works" writen in RC chat... so its working... still have the problem though :cry:

EDIT: oh sorry... i just tried playing as a Guest and it worked :):D
you can close this thread:cool:


All times are GMT +2. The time now is 11:37 PM.

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