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 07-07-2008, 11:57 PM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
removeweapon()

Well, there's something weird about it..

lets see

Graal Script Code:
function onActionPlayerOnline() {
  
temp.weps player.weapons;
  
temp.0;
  for(
temp.wep weps) {
    echo(++ 
i SPC wep.name);
  }

(In this case it echoed 28 weapons)

This echoes all the player's weapons on login. However.. If I try to remove all weapons on login, something weird happens..

Graal Script Code:
function onActionPlayerOnline() {
  
temp.weps player.weapons;
  
temp.0;
  for(
temp.wep weps) {
    
removeweapon(wep.name);
    echo(++ 
i SPC wep.name);
  }

It only echoes 14 weapons and removes those that were echoed..

So to get all weapons removed you have to reconnect like.. >5 times o.o;;

Why is this? Anyone knows?
__________________

Last edited by Chompy; 07-08-2008 at 12:13 AM.. Reason: fixed typo
Reply With Quote
  #2  
Old 07-08-2008, 12:06 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
Happened on Utopia too, is very annoying.
__________________
Reply With Quote
  #3  
Old 07-08-2008, 12:11 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
There are a lot of weapons that are hidden that are given to the player by the client... stuff like the server list, player list, client RC. I dunno if this is what you're talking about, I'm having a hard time understanding your post.

I don't think they can be removed.

Also, your second loop isn't accurate. You should run a loop that removes weapons, then run a separate loop that echos the weapons.
Reply With Quote
  #4  
Old 07-08-2008, 12:13 AM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by DustyPorViva View Post
There are a lot of weapons that are hidden that are given to the player by the client... stuff like the server list, player list, client RC. I dunno if this is what you're talking about, I'm having a hard time understanding your post.

I don't think they can be removed.

Also, your second loop isn't accurate. You should run a loop that removes weapons, then run a separate loop that echos the weapons.
I want to remove all weapons the player has in "Weapons" when I open their attributes :o (Oh, and edited post to add a missing word xD)
__________________
Reply With Quote
  #5  
Old 07-08-2008, 12:15 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
When you call player.removeweapon() then its modifying player.weapons[], that's why the loop is only removing 14. Possible solution would be

Graal Script Code:
for (i=player.weapons.size()-1i>=0i--)
  
player.removeweapon(player.weapons[i].name); 
(might be confusing but player.weapons is a special intelligent object which lets you print the player weapon list as string even when there are weapons which don't really exist, and by using weapons[] you can still directly access the weapon npc)
Reply With Quote
  #6  
Old 07-08-2008, 01:32 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
I do it like this on Mythic, work's like a charm:

Graal Script Code:
  temp.wsize player.weapons.size();
  for (
temp.0temp.temp.wsizetemp.i++) {
    if (
player.weapons[i].name != name) {
      
removeweapon(player.weapons[i].name);
      if (
temp.wsize != player.weapons.size()) {
        
i--;
        
temp.wsize player.weapons.size();
      }
    }
  } 
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #7  
Old 07-08-2008, 03:24 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Wouldn't this work?
Graal Script Code:
for (temp.i=0temp.i<player.weapons.size(); temp.i++)
  
player.removeweapon(player.weapons[0].name); 
Reply With Quote
  #8  
Old 07-10-2008, 01:38 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by DrakilorP2P View Post
Wouldn't this work?
Graal Script Code:
for (temp.i=0temp.i<player.weapons.size(); temp.i++)
  
player.removeweapon(player.weapons[0].name); 
Skipping over Stefan's posts usually isn't a smart thing to do. If you don't understand it then just think really hard about how arrays work.
__________________
Reply With Quote
  #9  
Old 07-10-2008, 03:02 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by Inverness View Post
Skipping over Stefan's posts usually isn't a smart thing to do. If you don't understand it then just think really hard about how arrays work.
Just noticed my previous post is a really misleading way of deleting half the list.

Anyway, similar method, different language but guaranteed to work:
Graal Script Code:
>>> foo = [1"bar"False, ["baz""crux"], 9]
>>> 
cruux len(foo)
>>> for 
i in range(cruux):
...     print 
"Foo: " str(foo[0])
...     
foo.remove(foo[0])
... 
Foo1
Foo
bar
Foo
False
Foo
: ['baz''crux']
Foo9
>>> foo
[]
>>> 
All assuming the precise functioning of this "special intelligent object" did not elude me.
Reply With Quote
  #10  
Old 07-10-2008, 03:23 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by DrakilorP2P View Post
Anyway, similar method, different language but guaranteed to work:
No it wouldn't.

If you want to delete stuff in an array part by part you need to start at the end so when you delete the element and the array shrinks in size you're not missing anything. When you're deleting a part from an array everything after it is decreasing in index so the for loop misses the element that replaced the one it just deleted while it moves on to the next highest index.

Also in your Python code the 'cruux' variable is unnecessary. You're taking the length from the 'foo' array and creating a new array from it but not actually using variable 'i', so you should just do for i in foo:

Edit:
Quote:
Originally Posted by DrakilorP2P
Just noticed my previous post is a really misleading way of deleting half the list.
It appears I was the one who was mislead when reading your post. Since I just noticed it was only deleting index 0 and not index i. If done like that it should work fine I guess.
__________________
Reply With Quote
  #11  
Old 07-10-2008, 01:03 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Drakilors method would work too. He's using [0], not [temp.i], so it would just delete all first weapons in the list untill nothing's left.
__________________
Reply With Quote
  #12  
Old 07-10-2008, 07:28 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Dan View Post
Drakilors method would work too. He's using [0], not [temp.i], so it would just delete all first weapons in the list untill nothing's left.
But like Stefan said, player.weapons is a special object in that it can give you a string list which could include weapons that don't actually exist. If you try to removeweapon() a weapon in that list that isn't an actual weapon, the weapon won't be removed from the list thus causing an infinite loop.
__________________
Do it with a DON!
Reply With Quote
  #13  
Old 07-10-2008, 09:52 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Quote:
Originally Posted by zokemon View Post
But like Stefan said, player.weapons is a special object in that it can give you a string list which could include weapons that don't actually exist. If you try to removeweapon() a weapon in that list that isn't an actual weapon, the weapon won't be removed from the list thus causing an infinite loop.
Indeed you're right. Perhaps there should come some built in check to see if a weapon in someone's weaponlist still exists.
__________________
Reply With Quote
  #14  
Old 07-11-2008, 12:55 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Dan View Post
Indeed you're right. Perhaps there should come some built in check to see if a weapon in someone's weaponlist still exists.
player.weapons.index() ?
__________________
Reply With Quote
  #15  
Old 07-11-2008, 06:23 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Inverness View Post
player.weapons.index() ?
Fairly costly to be doing array searching on each iteration.
__________________
Do it with a DON!
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 05:40 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.