Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: PsyChO_KiLLeR on Mar 02, 2015, 01:23 PM

Title: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 02, 2015, 01:23 PM
Description:Well i have added custom weapons they are working well but i have to type /exec FindPlayer(0).SetWeapon( weaponid,ammo); i want it to change into /wep id how i change?
Title: Re: Custom Weapons
Post by: MacTavish on Mar 02, 2015, 01:28 PM
else if (cmd == "wep1" )
{
player.SetWeapon( weaponid. Ammo);
MessagePlayer("Wow You've Got Custom Weapon Its Amazing Nah",player);
}


Weaponid // put your custom weapon id here
Ammo // How much ammo you wanna give to player
Title: Re: Custom Weapons
Post by: . on Mar 02, 2015, 01:34 PM
You can use GetWeaponID(string); and pass the weapon name instead of prefixing your commands with the weapon ID. You simply have one command /wep that takes a string (the weapon name) and then use that string to get the actual weapon ID.

And example is available here (http://forum.vicecitymultiplayer.com/index.php?topic=7012.msg40484#msg40484) but for the player skins.
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 02, 2015, 01:45 PM
can i get like /wep name/id
can i add this like?
Title: Re: Custom Weapons
Post by: . on Mar 02, 2015, 01:49 PM
Quote from: PsyChO_KiLLeR on Mar 02, 2015, 01:45 PMcan i get like /wep name/id
can i add this like?

Yes, you can. You just need to do a few more checks to know when the argument is an ID or just a string. I'll be back later with an example.
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 02, 2015, 01:49 PM
ok
Title: Re: Custom Weapons
Post by: BigcaT_ on Mar 02, 2015, 01:51 PM
player.SetWeapon( IsNum(text) ? text.tointeger() : GetWeaponID( text ), ammo );
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 02, 2015, 01:52 PM
what your mean?
where i add this?
Title: Re: Custom Weapons
Post by: BigcaT_ on Mar 02, 2015, 02:01 PM
Quote from: PsyChO_KiLLeR on Mar 02, 2015, 01:52 PMwhat your mean?
where i add this?
else if ( cmd == "wep" || cmd == "buy" ) // command
{
if ( !text ) MessagePlayer( "[Syntax] - !wep <Wep Name/ID>", player );
else if ( !player.IsSpawned ) MessagePlayer("You aren't Spawned.",player); // check player if spawn
else
{
MessagePlayer( "You Bought [#ffffff]" + text , player );
player.SetWeapon( IsNum(text) ? text.tointeger() : GetWeaponID( text ),ammo );     
                        // if text is numbers ,  tointeger.        else, GetWeaponid from text
                }
}
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 02, 2015, 03:15 PM
its not working i want it for all weps inculding previous like stu and my custom weps in one cmd
Title: Re: Custom Weapons
Post by: . on Mar 02, 2015, 03:17 PM
Quote from: PsyChO_KiLLeR on Mar 02, 2015, 03:15 PMits not working i want it for all weps inculding previous like stu and my custom weps in one cmd

You mean like Player.GiveWeapon(); ? instead of Player.SetWeapon();
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 03, 2015, 03:39 AM
yes Like when i type/wep stu it come then how to add in this wep command /wep ak /wep blah blah all in one command
Title: Re: Custom Weapons
Post by: Thijn on Mar 03, 2015, 06:40 AM
You're going to need to add a function that will first try to get the weapon ID by using GetWeaponID. If that fails (For "ak", for example), you can add a switch that will go through your custom weapons and return their ID.

Try to use your brain this time and make it yourself. I've told you everything you need to know. Feel free to post when you encounter an error which you need help with, though.
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 03, 2015, 08:12 AM
well i create a cmd for these custom weapons but it give me error i cant post screenshot because its not working so error is expression expected


There is Command
  else if ( cmd == "wep" || cmd == "buy" ) // command
{
if ( !text ) MessagePlayer( "[Syntax] - !wep <Wep Name/ID>", player );
else if ( !player.IsSpawned ) MessagePlayer("You aren't Spawned.",player); // check player if spawn
if ( text.tolower() == "100" )
{
MessagePlayer( "You Bought Custom Weapon", player );
SetWeapon( 100,999);
else if ( text.tolower() == "101" )
{
MessagePlayer( "You Bought Custom Weapon", player );
SetWeapon( 101,999);
}
}
}
Title: Re: Custom Weapons
Post by: MacTavish on Mar 03, 2015, 08:42 AM
Change SetWeapon( 100,999); SetWeapon( 101,999);  to player.SetWeapon( 100,999); player.SetWeapon( 101,999);

If it not solve your problem then try else if ( cmd == "wep" || cmd == "buy" ) // command
{
if ( text )
{
if (player.IsSpawned)
{
if ( text.tointeger() == "100" )
{
MessagePlayer( "You Bought Custom Weapon", player );
player.SetWeapon( 100,999);
}
else if ( text.tointeger() == "101" )
{
MessagePlayer( "You Bought Custom Weapon", player );
player.SetWeapon( 101,999);
}
else MessagePlayer( "[Error] - ID must be in numbers", player );
}
else MessagePlayer( "[Error] - You have'nt spawned yet!", player );
}
else MessagePlayer( "[Syntax] - /wep <Wep Name/ID>", player );
}

UPDATED
Title: Re: Custom Weapons
Post by: BigcaT_ on Mar 03, 2015, 08:43 AM
and numbers can't use xx.tolower()
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 03, 2015, 09:23 AM
i add command that u give me but again error
Expresion Expected

When i remove your command server works fine
error in your cmd of expression expected
Title: Re: Custom Weapons
Post by: MacTavish on Mar 03, 2015, 09:36 AM
Quote from: Beztone on Mar 03, 2015, 08:42 AMChange SetWeapon( 100,999); SetWeapon( 101,999);  to player.SetWeapon( 100,999); player.SetWeapon( 101,999);

If it not solve your problem then try else if ( cmd == "wep" || cmd == "buy" ) // command
{
if ( text )
{
if (player.IsSpawned)
{
if ( text.tointeger() == "100" )
{
MessagePlayer( "You Bought Custom Weapon", player );
player.SetWeapon( 100,999);
}
else if ( text.tointeger() == "101" )
{
MessagePlayer( "You Bought Custom Weapon", player );
player.SetWeapon( 101,999);
}
else MessagePlayer( "[Error] - ID must be in numbers", player );
}
else MessagePlayer( "[Error] - You have'nt spawned yet!", player );
}
else MessagePlayer( "[Syntax] - /wep <Wep Name/ID>", player );
}

UPDATED


I updated code try again
Title: Re: Custom Weapons
Post by: Kratos_ on Mar 03, 2015, 10:35 AM
I'm seeing that you guys are writing something like this :-
if( text.tointeger() == "100" ) player.SetWeapon( 100,999);

Lets say you added a custom weapon named "Dragonuv" of logical id 100 in your server . Will converting "Dragonuv" to integer return 100 ? Ofcourse not . I guess , you got this idea of converting to integer from this code-section of Findplayer :-

if(IsNum(text)) FindPlayer( text.tointeger());

IsNum(9);  // will throw error [ parameter has invalid type. status : integer, expected : string ]
IsNum("9");  // will succeed [ IsNum itself expects a numeric value in double quotes ]

"Dragonuv".tointeger()     // will throw error [ Error converting the string ]
"100".to integer()     // will succeed [ will return a value of type int ]

So , you can make use of GetweaponID( string ) as S.L.C is saying .  Try to check that whether it works for custom weapon too or not .
If it works for custom weapons too then its ok otherwise make a custom function for switching the weapon ID from its name and then set him the weapon using player.SetWeapon( <id>, <ammo> ) as Thijn stated above .
Since Custom weapon XML config takes the weapon name & ID , so both the methods should work .  Do not forget to eliminate any invalid weapon id through creating conditions  .  I do not remember those condition well .  Stormeus have made such a condition in PB#3 to throw the message of invalid weapon ID  .  He released somewhere this . You can check that condition from there .
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 03, 2015, 10:45 AM
not working when i type /wep 100 or /wep 101 it say Id must be in number
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 03, 2015, 10:46 AM
so what is solution Kratos?
Title: Re: Custom Weapons
Post by: MacTavish on Mar 03, 2015, 11:19 AM
So what about this kratos :)
else if ( cmd == "wep" || cmd == "buy" ) // command
{
if ( text )
{
if (player.IsSpawned)
{if (IsNum ( text ))
{
if ( text == "100" )
{
MessagePlayer( "You Bought Custom Weapon", player );
player.SetWeapon( 100,999);
}
else if ( text == "101" )
{
MessagePlayer( "You Bought Custom Weapon", player );
player.SetWeapon( 101,999);
}
}
else MessagePlayer( "[Error] - ID must be in numbers", player );
}
else MessagePlayer( "[Error] - You have'nt spawned yet!", player );
}
else MessagePlayer( "[Syntax] - /wep <Wep Name/ID>", player );
}
Title: Re: Custom Weapons
Post by: PsyChO_KiLLeR on Mar 03, 2015, 12:21 PM
Thank u Beztone and other also for help
Problem Solve
Topic Locked