Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-09-2011, 07:12 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
Question Weapon

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

Regards
__________________

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180

Reply With Quote
  #2  
Old 05-09-2011, 07:33 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
PHP Code:
 function onActionPlayerOnline() {
 
addweapon("WEAPON NAME");

Put that at the top of your control NPC.
__________________
Reply With Quote
  #3  
Old 05-09-2011, 07:34 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
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);
  }

__________________
Quote:
Reply With Quote
  #4  
Old 05-09-2011, 09:19 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
Quote:
Originally Posted by Emera View Post
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....
__________________

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180


Last edited by mrnothersan; 05-09-2011 at 09:31 PM..
Reply With Quote
  #5  
Old 05-09-2011, 09:52 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by mrnothersan View Post
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).
Reply With Quote
  #6  
Old 05-09-2011, 09:53 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
player.addweapon? dude just copy n paste what i wrote...
__________________
Reply With Quote
  #7  
Old 05-09-2011, 09:54 PM
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 mrnothersan View Post
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 View Post
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.
__________________
Reply With Quote
  #8  
Old 05-09-2011, 09:55 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Emera View Post
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.
Reply With Quote
  #9  
Old 05-09-2011, 10:08 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
Quote:
Originally Posted by fowlplay4 View Post
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...
__________________

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180

Reply With Quote
  #10  
Old 05-09-2011, 10:25 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Ugh
__________________
Reply With Quote
  #11  
Old 05-09-2011, 10:30 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
Quote:
Originally Posted by Emera View Post
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...
__________________

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180

Reply With Quote
  #12  
Old 05-09-2011, 10:30 PM
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 mrnothersan View Post
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.
__________________
Reply With Quote
  #13  
Old 05-09-2011, 10:36 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
Quote:
Originally Posted by cbk1994 View Post
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...
__________________

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180

Reply With Quote
  #14  
Old 05-09-2011, 11:39 PM
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 mrnothersan View Post
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.
__________________
Reply With Quote
  #15  
Old 05-10-2011, 03:01 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
sorry for late reply
Quote:
Originally Posted by cbk1994 View Post
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

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

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:01 PM.


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