Graal Forums

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

JkWhoSaysNi 09-12-2006 05:24 PM

Change active NPC?
 
Hello, how can I change the active (the one that gets used when you press D) weapon npc through code? I guess it could be done through a trigger, but i dont know the name of it.

thanks for any help :)

Luigi203 09-12-2006 06:19 PM

wtf are you talking about? If you're talking about just changing the selected weapon, here.


PHP Code:


for (0weaponscounti++) { //loop through the weapons
  
if (strequals(#w(i),WEAPONNAME)) {  //check to see if the weapons index i is equal to what you want to change the weapon to
   
selectedweapon i//change the selected weapon
   
break; //end the loop
  
}



projectigi 09-12-2006 06:22 PM

hrm i think selectedweapon is the id of the current weapon
you could loop through the player.weapons array and use weapon.name to get the name
like
NPC Code:

function onCreated(){
for(i=0;i<=player.weapons.size();i++){
if(player.weapons[i]=="weaponname")
selectedweapon=i;
}
}



edit: damn too slow

JkWhoSaysNi 09-12-2006 06:28 PM

Quote:

Originally Posted by Luigi203
wtf are you talking about? If you're talking about just changing the selected weapon, here.


PHP Code:


for (0weaponscounti++) { //loop through the weapons
  
if (strequals(#w(i),WEAPONNAME)) {  //check to see if the weapons index i is equal to what you want to change the weapon to
   
selectedweapon i//change the selected weapon
   
break; //end the loop
  
}



yes, thats all i wanted to do. Thanks :)

Luigi203 09-12-2006 06:29 PM

Quote:

Originally Posted by projectigi
hrm i think selectedweapon is the id of the current weapon
you could loop through the player.weapons array and use weapon.name to get the name
like
NPC Code:

function onCreated(){
for(i=0;i<=player.weapons.size();i++){
if(player.weapons[i]=="weaponname")
selectedweapon=i;
}
}



Okay, you just did the same exact thing I did. Selectedweapon is the current weapon, its writable.

projectigi 09-12-2006 06:30 PM

but yours is gs1 =(

JkWhoSaysNi 09-12-2006 06:43 PM

actually, i found a better way.

PHP Code:

player.weapon findweapon("Weapon Name"); 

However, it doesnt update the icon in the interface or make it selected in the Q menu.

projectigi 09-12-2006 07:41 PM

well at wiki it says player.weapon is read only

Admins 09-13-2006 01:14 AM

May be selectedweapon = player.weapons.index(findweapon(weaponname)) ?


All times are GMT +2. The time now is 06:44 AM.

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