Raised This Month: $32 Target: $400
 8% 

[HELP] If Mapname Then Give Wep + Ammo


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-22-2018 , 06:03   [HELP] If Mapname Then Give Wep + Ammo
Reply With Quote #1

I'm trying to make a plugin that does the following:
Gives ammo to killer. (Not sure if it is correctly done)
Gives weapon + ammo when you spawn, weapon and ammo is different depending on mapname.
Is it correct to check mapname in plugin init?

Thank you very much.

I'm getting these errors:
Quote:
ERROR [28]: array index out of bounds (variable "mapname")
ERROR [30]: array index out of bounds (variable "weapon")
ERROR [31]: array index out of bounds (variable "ammo")

Also you can carry two primary weapons.
And if it is possible I would like to remove the weapons that are dropped to reduce CPU usage.
Code:
new mapname[31] new weapon[31] new ammo[31] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1)     register_event("DeathMsg", "AmmoOnKill", "a")     register_cvar("gn_impulse", "0")     checkMapName() } public checkMapName() {     get_mapname(mapname,31)     if (mapname[31] == "aim_map_tmp")     {         weapon[31] = "weapon_tmp"         ammo[31] = "ammo_9mm"     }     else     {         weapon[31] = "weapon_ak47"         ammo[31] = "CSW_SCOUT"     } } public fwHamPlayerSpawnPost(id) {     if (!get_cvar_num("gn_impulse"))     {         if (mapname[31] == "aim_map_usp" && is_user_alive(id))         {             client_cmd(id, "lastinv")         }         else if (is_user_alive(id))         {             giveWeapons(id)         }     }     return PLUGIN_CONTINUE } public giveWeapons(id) {     cs_set_user_armor(id, 100, CS_ARMOR_KEVLAR)     give_item(id, weapon[31])     cs_set_user_bpammo(id, ammo[31], 90) } public AmmoOnKill() {     new killer = read_data( 1 ), szWp[5];     read_data(4, szWp, charsmax(szWp))     if (killer > 0 && killer != read_data(2) && equal(szWp, "usp", 3))     {         cs_set_weapon_ammo(find_ent_by_owner(-1,"weapon_usp",killer),12)     }     if (killer > 0 && killer != read_data(2) && equal(szWp, "ak47", 3))     {         cs_set_weapon_ammo(find_ent_by_owner(-1,"weapon_ak47",killer),30)     } }
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 04-22-2018 at 06:09.
GoldNux is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 04-22-2018 , 06:47   Re: [HELP] If Mapname Then Give Wep + Ammo
Reply With Quote #2

Code:
new mapnahme[32] new bool: thebool public plugin_init(){     get_mapname(mapnahme, charsmax(mapnahme))     if (equali(mapnahme, "the_mapname")         thebool = true; } public client_death(id){     if (thebool)         server_print("something");     else         server_print("else"); }
Can you understand what I've done here?
__________________
Relaxing is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-22-2018 , 07:04   Re: [HELP] If Mapname Then Give Wep + Ammo
Reply With Quote #3

Quote:
Originally Posted by Relaxing View Post
Code:
new mapnahme[32] new bool: thebool public plugin_init(){     get_mapname(mapnahme, charsmax(mapnahme))     if (equali(mapnahme, "the_mapname")         thebool = true; } public client_death(id){     if (thebool)         server_print("something");     else         server_print("else"); }
Can you understand what I've done here?
If I understood correctly I will need separate bools for each map.
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 04-22-2018 at 07:09.
GoldNux is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 04-22-2018 , 08:11   Re: [HELP] If Mapname Then Give Wep + Ammo
Reply With Quote #4

You can use an integer and give a value for each map
Code:
new map_integer new mapname[32]; get_mapname(mapname, charsmax(mapname)) switch (mapname){     case "de_dust2" : map_integer = 1;     case "de_inferno" : map_integer = 2; } if (map_integer == 1)     server_print("playing on de dust 2")
__________________
Relaxing is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-22-2018 , 08:17   Re: [HELP] If Mapname Then Give Wep + Ammo
Reply With Quote #5

I'm not sure if you could use strings in switch , only 1 char.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 04-22-2018 , 08:54   Re: [HELP] If Mapname Then Give Wep + Ammo
Reply With Quote #6

Try this:
Code:
new LoadFile[128], DataDir[64]; get_datadir(DataDir, charsmax(DataDir)); format(LoadFile, charsmax(LoadFile), "%s/map_data.dat", DataDir); stock add_map(mapname[], value){     new Save[64];     format(Save, charsmax(Save), "^"%s^" %d", mapname, value);     new FileOpen = fopen(LoadFile, "rt"):     if(FileOpen)         write_file(LoadFile, Save);     fclose(FileOpen); } stock get_value_from_data(mapname[]){     new Line[64], Argue1[32], Argue2[10], ReturnValue;     new FileOpen = fopen(LoadFile, "rt");     while(!feof(FileOpen)){         fgets(FileOpen, Line, charsmax(Line));         trim(Line);         parse(Line, Argue1, charsmax(Argue1), Argue2, charsmax(Argue2));         if(equali(Argue1, mapname){             ReturnValue = str_to_num(Argue2);             break;         }     }     fclose(FileOpen);     return ReturnValue: }
__________________

Last edited by Relaxing; 04-22-2018 at 09:12.
Relaxing is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-22-2018 , 09:24   Re: [HELP] If Mapname Then Give Wep + Ammo
Reply With Quote #7

Quote:
Originally Posted by Relaxing View Post
Try this:
Code:
new LoadFile[128], DataDir[64]; get_datadir(DataDir, charsmax(DataDir)); format(LoadFile, charsmax(LoadFile), "%s/map_data.dat", DataDir); stock add_map(mapname[], value){     new Save[64];     format(Save, charsmax(Save), "^"%s^" %d", mapname, value);     new FileOpen = fopen(LoadFile, "rt"):     if(FileOpen)         write_file(LoadFile, Save);     fclose(FileOpen); } stock get_value_from_data(mapname[]){     new Line[64], Argue1[32], Argue2[10], ReturnValue;     new FileOpen = fopen(LoadFile, "rt");     while(!feof(FileOpen)){         fgets(FileOpen, Line, charsmax(Line));         trim(Line);         parse(Line, Argue1, charsmax(Argue1), Argue2, charsmax(Argue2));         if(equali(Argue1, mapname){             ReturnValue = str_to_num(Argue2);             break;         }     }     fclose(FileOpen);     return ReturnValue: }
Looks very nice and surely works great.
But I'm sorry to say this is way too advanced for me.
I would love to understand, seems very complex.
I'm not sure how to integrate this.

Thanks.
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 04-22-2018 at 09:24.
GoldNux is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 04-22-2018 , 09:47   Re: [HELP] If Mapname Then Give Wep + Ammo
Reply With Quote #8

Basically this stock returns a value depending on it searches. So we are looking for a value of a map, lets say: get_value_from_data("de_dust")
The stock will quickly look up at the file & get it's value, only if the map is on the file.
Code:
new map_int = get_value_from_data("de_dust2") if (map_int == 1)     server_print("playing on dust 2") else if (map_int == 0)     server_print("map not listed on the file")
map_data.dat examples
"de_dust2" 1
"de_dust" 2
"de_inferno" 3
"cs_assault" 4

You can get rid of add_map. You can manually configure them on the file.

Reminder: Don't set a map's value 0, the 0 is the default value of an undefined integer. The stock get's an number from a map, if the map doesn't exists then the integer won't have a call. (you can get rid of it if you set it on "-1". ReturnValue = -1;
__________________
Relaxing is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode