Graal Forums

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

defaultaccount 06-18-2013 05:11 AM

Removing weapons
 
Hey I'm just trying to make a weapon add and remove itself from my inventory, I can use addweapon(); and removeweapon() on levels but it doesn't work inside the weapons scripts. When I put them two commands in f2 it says its a unrecognized command. thank you and sorry for posting another noob topic

also im wondering how to drop a animation for a clip gani when the gun reloads so it stays on the ground

NPC Code:


//#CLIENTSIDE

function GraalControl.onKeyDown(code, key, scan) {
if (key == "t") {
freezeplayer(this.equip);
removeweapon("Weapon/BMP");
addweapon("Weapon/BMP2");
}


Cubical 06-18-2013 12:21 PM

Should be dogging that clientside and then do the adding and remodeling serverside.

defaultaccount 06-18-2013 06:50 PM

I didn't post the whole script but it is clientside can you explain to me what you mean give me an example of how it should be because right now it just freezes my player and puts in f2 on scripts that it's an unrecognized command the removeweapon(); , but it works fine in the levels npcs

I tried adding it server side but it still didn't work

cbk1994 06-18-2013 08:46 PM

It's possible to remove weapons clientside (this.destroy() in the weapon—DO NOT DO THIS SERVERSIDE, IT WILL DELETE THE WEAPON FROM THE SERVER) but to add weapons you need to use player.addWeapon(weapon_name) and that must be done serverside. To remove weapons from a player serverside, use player.removeWeapon(weapon_name).

defaultaccount 06-18-2013 10:52 PM

Quote:

Originally Posted by cbk1994 (Post 1719389)
It's possible to remove weapons clientside (this.destroy() in the weapon—DO NOT DO THIS SERVERSIDE, IT WILL DELETE THE WEAPON FROM THE SERVER) but to add weapons you need to use player.addWeapon(weapon_name) and that must be done serverside. To remove weapons from a player serverside, use player.removeWeapon(weapon_name).

i'm trying to make it a key pressed but I don't know how to do that for serverside would it be

NPC Code:

function onKeyPressed(code, key) {
if (key == "t") {
player.addWeapon(weapon_name);
player.removeWeapon(weapon_name);




or how could I make it a function that the client side does and plays the serverside function

like this

NPC Code:

function onTierUp() {
player.addWeapon(weapon_name);
player.removeWeapon(weapon_name);

//#CLIENTSIDE

function onKeyPressed(code, key) {
if (key == "t") {
onTierUp():
}
}





I tried doing that before but it couldn't read the function

cbk1994 06-19-2013 12:33 AM

You need to use triggers to communicate between clientside and serverside. See these posts:
http://forums.graalonline.com/forums...84&postcount=6
http://forums.graalonline.com/forums...17&postcount=4

defaultaccount 06-19-2013 01:08 AM

I read it but im still having trouble doing it

NPC Code:

function onActionServerSide() {
player.addWeapon(weapon/BMPTier1);
player.removeWeapon(weapon/BMP);
}
//#CLIENTSIDE
function GraalControl.onKeyDown(code, key, scan) {
if (key == "t") {
triggerServer("gui", weapon/bmp, null);



its all in the same script I put the action above my clientside and its still not working ingame

cbk1994 06-19-2013 01:34 AM

String literals (stuff like "weapon/bmp") should be in quotes.

defaultaccount 06-19-2013 01:48 AM

is it proper otherwise? i'll try adding quotes I forgot to add them above ill add the quotes and see if that helps but other than that it should trigger the weapon change?

edit: I got it working, it added the gun but it didn't remove it ill test it out more later but it triggered the server side weapons change thank you cbk youre very helpful here on the forums

I cant get it to remove the weapon I have it set up like this

Quote:

function onActionServerSide() {
player.addWeapon("weapon/BMPTier1");
player.removeWeapon("weapon/BMP");
}
//#CLIENTSIDE
function GraalControl.onKeyDown(code, key, scan) {
if (key == "t") {
triggerServer("gui", this.name, null);

im going to try to do it with destroy clientside

I got it working with destroy(weapon/bmp); thanks cbk uve been very helpful

now i'm trying to make it so it can go down in level how would I be able to do that, I have it right now like it shows above but I want to make a trigger for a key to make it add the previous gun

NPC Code:
 
function onActionServerSide() {
player.addWeapon("Weapon/BMPTier3");
}
function onActionServerSide() {
player.addWeapon("Weapon/BMPTier1");
}
//#CLIENTSIDE
function GraalControl.onKeyDown(code, key, scan) {
if (key == "t") {
freezeplayer(this.equip);
triggerServer("gui", this.name, null);
destroy(Weapon/BMPTier2);
}
if (key == "g") {
freezeplayer(this.equip);
triggerServer("gui", this.name, null);
destroy(Weapon/BMPTier2);
}
}



basicly im wondering how to make it so it has two sever side triggers, I can currently can only make it have one serverside trigger I don't know how make it work...

cbk1994 06-19-2013 05:04 AM

When you post code, wrap it in [PHP] tags instead of [CODE] tags.

destroy() doesn't take any parameters, so you should just write this.destroy() instead of this.destroy(Weapon/BMPTier2);

Your first code looks fine; my guess is that your capitalization of the weapon name is off. I'm not certain but I'd guess player.removeWeapon might be case-sensitive. If it's not working, make sure you have the weapon name entered exactly as it should be (in some examples you use weapon/BMP and in others you use Weapon/BMP). You can also use this.name to refer to the current weapon name.

If you want to handle multiple possible actions serverside, send a parameter instead of null in your trigger. The parameter will be passed to the onActionServerSide event.

Something like this:

PHP Code:

function onActionServerSide(temp.cmd) {
  if (
temp.cmd == "levelUp") {
    
player.addWeapon("Weapon/BMPTier3");
    
player.removeWeapon(this.name);
  } else if (
temp.cmd == "levelDown") {
    
player.addWeapon("Weapon/BMPTier1");
    
player.removeWeapon(this.name);
  }
}

//#CLIENTSIDE
function GraalControl.onKeyDown(codekeyscan) {
  if (
key == "t") {
    
freezeplayer(this.equip);
    
triggerServer("gui"this.name"levelUp");
  } else if (
key == "g") {
    
freezeplayer(this.equip);
    
triggerServer("gui"this.name"levelDown");
  }



Cubical 06-19-2013 02:30 PM

Quote:

Originally Posted by Cubical (Post 1719381)
Should be dogging that clientside and then do the adding and remodeling serverside.

Auto correct for my phone was all over the place on that one.

defaultaccount 06-19-2013 07:09 PM

Works perfectly now, thank you for the help. I managed to make an entire gunscript that works the way I need it to for my weapons.


All times are GMT +2. The time now is 09:22 AM.

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