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?
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
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.
can i get like /wep name/id
can i add this like?
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.
ok
player.SetWeapon( IsNum(text) ? text.tointeger() : GetWeaponID( text ), ammo );
what your mean?
where i add this?
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
}
}
its not working i want it for all weps inculding previous like stu and my custom weps in one cmd
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();
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
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.
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);
}
}
}
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
and numbers can't use xx.tolower()
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
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
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 .
not working when i type /wep 100 or /wep 101 it say Id must be in number
so what is solution Kratos?
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 );
}
Thank u Beztone and other also for help
Problem Solve
Topic Locked