• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Help with Custom Weapon Names
#1
Lately I noticed that Roleplay servers scripts allow weapons with the same ID (for example, a Deagle) to be stored in a player's inventory under different names. For example, if a player (from Grove Street Families)?has a Deagle on him, if he does /inventory (hypothetically), instead of Deagle, the weapon's name is ''Glock''. Also, let's say there is another player (from Ballas) that has a Deagle on him. But in this case, the weapon's name?(Deagle) can be another weapon name other than Glock (that the first player has), for example, when the second player does /inventory, the name of the Deagle is ''Beretta''.



How can you do that?
  Reply
#2
Are you using Teams??You can set them under SetPlayerSpawnInfo or SetPlayerTeam.?I guess you have, so you would be able to use https://www.open.mp/docs/scripting/funct...PlayerTeam







Code:
new string[128];

switch(GetPlayerTeam(playerid)) {

case 0: string = "deagle";

case 1: string = "pistol";

case 2: string = "glock";

default: string = "colt";

}
Check out Desolation Roleplay, where zombie AI and scavenging is bothered by player bandits!


  Reply
#3
There are multiple ways to do it. Personally, I would use an array holding all the desired weapon names, something like this:



Code:
enum

{

    TEAM_CIVILIAN = 1,

    TEAM_LEO, //Law Enforcment Officer (Police, army, FBI etc..)

    TEAM_GANG, //Grove street, Ballas etc

    TEAM_MISC

};



//Respecting weapon IDs, you should have an entry for every possible weapon for the script to prevent array out of bound errors.

new const weaponName[][][] =

{

    //{WEAPON_ID,           WEAPONNAME_TEAM1, WEAPONNAME_TEAM2, WEAPONNAME_TEAM3, WEAPONNAME_TEAM4},

    {0,                        "Fists", "Fists", "Fists", "Fists"},

    {WEAPON_BRASSKNUCKLE,    "Brass knuckles", "Brass knuckles", "Brass knuckles", "Brass knuckles"},

    {WEAPON_GOLFCLUB,       "Golf club", "Golf club", "Golf club", "Golf club"},

    {WEAPON_NITESTICK,      "Nightstick", "Nightstick", "Nightstick", "Nightstick"},

    {WEAPON_KNIFE,          "Kitchen knife", "Combat knife", "Stiletto", "Knife"},

    {WEAPON_BAT,            "Baseball bat", "Bat", "Bat", "Bat"},

    {WEAPON_SHOVEL,         "Shovel", "Shovel", "Digging tool", "Bat"},

    {WEAPON_POOLSTICK,      "Pool cue", "Pool cue", "Pool cue", "Pool cue"},

    {WEAPON_KATANA,         "Ninja weapon", "Katana", "Sword", "Katana"},

    {WEAPON_CHAINSAW,       "Chainsaw", "Chainsaw", "Chainsaw", "Chainsaw"}

    //etc

};



To print the name of a weapon:

Code:
weaponName[weaponid][teamid]

For example, to print "Combat knife":

Code:
weaponName[WEAPON_KNIFE][TEAM_LEO]



I find that more convenient than using switches. But go with whatever you like best, especially since some weapons may not even need custom/different names. When using this script like this you need to define names for all possible weapons and all possible teams, otherwise you will have either compile errors or runtime errors because arrays might go out of bounds.

If you would remove WEAPON_BAT in this example, using WEAPON_CHAINSAW would cause out of bounds error and WEAPON_SHOVEL to WEAPON_KATANA would print the wrong name.
  Reply
#4
Thank you both for answering. I was very confused about this matter. But I don't want the weapon name to be dependent on the player's team (I provided the GSF/Ballas info hypothetically, I meant to describe 2 different players so you would understand I want different names for the same weapon). I'll try to link the const weaponname to a command like /makeweapon, a command that only the faction that has the ability to make weapons will be able to use and see if I can get a result since I'm a newbie at scripting.
  Reply
#5
- Grove gang member gives his weapon (X) to ballas gang member.



Did that weapon name change to what ballas gang member should have ?

If yes - look at examples above.

If no - It's inventory system that is handeling weapon names ( DMG, weight, and so on ) and its not actually based on teams. It's too complicated to be explained in a single post if you want to do it in proper way.



If you can't give items and/or weapons to another player - if i had to guess, it's inventory based. Otherwise it's really cheap way to make your gun sys unique...
  Reply
#6
(2020-10-24, 10:55 AM)Expert* Wrote: - Grove gang member gives his weapon (X) to ballas gang member.



Did that weapon name change to what ballas gang member should have ?

If yes - look at examples above.

If no - It's inventory system that is handeling weapon names ( DMG, weight, and so on ) and its not actually based on teams. It's too complicated to be explained in a single post if you want to do it in proper way.



If you can't give items and/or weapons to another player - if i had to guess, it's inventory based. Otherwise it's really cheap way to make your gun sys unique...



Yes, you are right. An inventory system.?I just thought and I'll try to learn to script an inventory with custom weapon names instead, because I'm aware it's kind of complicated to get help from the others here.
  Reply


Forum Jump: