AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] If Mapname Then Give Wep + Ammo (https://forums.alliedmods.net/showthread.php?t=306996)

GoldNux 04-22-2018 06:03

[HELP] If Mapname Then Give Wep + Ammo
 
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)     } }

Relaxing 04-22-2018 06:47

Re: [HELP] If Mapname Then Give Wep + Ammo
 
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?

GoldNux 04-22-2018 07:04

Re: [HELP] If Mapname Then Give Wep + Ammo
 
Quote:

Originally Posted by Relaxing (Post 2588841)
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.

Relaxing 04-22-2018 08:11

Re: [HELP] If Mapname Then Give Wep + Ammo
 
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")

Natsheh 04-22-2018 08:17

Re: [HELP] If Mapname Then Give Wep + Ammo
 
I'm not sure if you could use strings in switch , only 1 char.

Relaxing 04-22-2018 08:54

Re: [HELP] If Mapname Then Give Wep + Ammo
 
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: }

GoldNux 04-22-2018 09:24

Re: [HELP] If Mapname Then Give Wep + Ammo
 
Quote:

Originally Posted by Relaxing (Post 2588865)
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.

Relaxing 04-22-2018 09:47

Re: [HELP] If Mapname Then Give Wep + Ammo
 
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;


All times are GMT -4. The time now is 04:44.

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