Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Removing Multiple Weapons (https://forums.graalonline.com/forums/showthread.php?t=134268502)

i8bit 07-21-2013 08:56 PM

Removing Multiple Weapons
 
PHP Code:

removeWeapon("Test/One");
removeWeapon("Test/Two");
removeWeapon("Test/Three"); 

Is there a way to remove all weapons starting with Test/ ?

callimuc 07-21-2013 09:02 PM

PHP Code:

for (temp.wplayer.weapons) {
  if (
temp.w.starts("Test/")) player.removeWeapon(temp.w);



Angel_Light 07-21-2013 09:02 PM

PHP Code:

for ( temp.wplayer.weapons)
{

  if ( 
temp.w.starts("Test/"))
    
player.removeWeapontemp.w);



Edit: beat me to it Callimuc

i8bit 07-22-2013 12:34 AM

Awesome. BUT what if I wanted to remove all weapons starting with Test/ except for Test/One for example? I tried this but it didn't work..

PHP Code:

for (temp.wplayer.weapons) {
  if (
temp.w.starts("Test/")) player.removeWeapon(temp.w);

sleep(0.05);
addWeapon("Test/One"); 


callimuc 07-22-2013 12:48 AM

1st: you wouldnt even need the sleep
2nd: check if the weapon is not Test/One..

PHP Code:

temp.except = {"Test/One"}; //array of weapons starting with 'Test/' which should not be removed
for (temp.wplayer.weapons) {
  if (
temp.w.starts("Test/") && !(temp.w in temp.except)) player.removeWeapon(temp.w)



cbk1994 07-22-2013 06:53 AM

temp.w is a weapon, not a string! Stop abusing your objects!

PHP Code:

temp.w.name.starts("Test/"

PHP Code:

temp.w.name in temp.except 

PHP Code:

player.removeWeapon(temp.w.name

Also, the minimum sleep value on serverside is 0.1, not 0.05, and you lose the player scope when you sleep, so player.addWeapon isn't going to work anyway.

scriptless 07-22-2013 12:39 PM

Quote:

Originally Posted by cbk1994 (Post 1720890)
temp.w is a weapon, not a string! Stop abusing your objects!

PHP Code:

temp.w.name.starts("Test/"

PHP Code:

temp.w.name in temp.except 

PHP Code:

player.removeWeapon(temp.w.name

Also, the minimum sleep value on serverside is 0.1, not 0.05, and you lose the player scope when you sleep, so player.addWeapon isn't going to work anyway.

Aww, I must spread rep before showing you some love. Great advice.


All times are GMT +2. The time now is 07:54 PM.

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