Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] Help with Custom Weapon Names

 
  • 0 Vote(s) - 0 Average
Pawn Help with Custom Weapon Names
RoBy41
Offline

Burgershot Member
Posts: 7
Threads: 3
Joined: Oct 2020
Reputation: 0
Location: România
#1
2020-10-23, 02:08 PM
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?
Awide
Offline

Burgershot Member
Posts: 62
Threads: 5
Joined: Sep 2019
Reputation: 5
#2
2020-10-24, 08:22 AM
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/functions/GetPlayerTeam



Code:
new string[128];
switch(GetPlayerTeam(playerid)) {
case 0: string = "deagle";
case 1: string = "pistol";
case 2: string = "glock";
default: string = "colt";
}
Desolation Roleplay has closed. You can download the gamemode here: https://www.burgershot.gg/showthread.php?tid=2272
Kwarde
Offline

Burgershot Member
Posts: 99
Threads: 2
Joined: Sep 2020
Reputation: 8
Location: The Netherlands
#3
2020-10-24, 09:28 AM
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.
RoBy41
Offline

Burgershot Member
Posts: 7
Threads: 3
Joined: Oct 2020
Reputation: 0
Location: România
#4
2020-10-24, 10:28 AM
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.
Expert*
Offline

Burgershot Member
Posts: 61
Threads: 2
Joined: Apr 2019
Reputation: 4
#5
2020-10-24, 10:55 AM
- 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...
RoBy41
Offline

Burgershot Member
Posts: 7
Threads: 3
Joined: Oct 2020
Reputation: 0
Location: România
#6
2020-10-24, 11:03 AM
(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.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode