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

Store string in array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SaBBa
Member
Join Date: Dec 2012
Old 09-18-2020 , 05:19   Store string in array
Reply With Quote #1

Hi, I am very new at scripting, I want to know how to write and read string from array, like assign string to player id and retrieve it.
I had this:

Code:
new playerSaved[33]
playerSaved[id] = "weapon_m4a1"

if(playerSaved[id] == "weapon_m4a1") {
   // do some stuff
}

EDIT:

First error was that I must gave specified length on the string stored in array like
Code:
new playerSaved[33][64]
and secondly, if condition was wrong, turns out I had to use equali
Code:
if(equali(playerSaved[id], "weapon_m4a1"))
I know it's poorly coded, but it is as expected
I am using this plugin with simplemenu: https://forums.alliedmods.net/showthread.php?t=284324
and in simplemenu's settings, calling do.func(buymenu_helper.amxx, get_weapon_ak47) on item selection and it works like a charm

1. New Guns (amx_buy_new)
2. Previous Guns (do.func(buymenu_helper.amxx, getPreviousGuns))
3. Previous Guns & Save (do.func(buymenu_helper.amxx, getPreviousGunsDisable))


Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <fun>

new playerSelection[33]
new playerSaved[33][64]

public plugin_init() {
	register_plugin("[CSO] Buymenu Helper", "1.0", "Nevermind23")
	register_clcmd("amx_buy_open", "oldOrNew")

	register_clcmd("say /guns", "enableMenu")
	register_clcmd("say guns", "enableMenu")
	register_clcmd("team_say /guns", "enableMenu")
	register_clcmd("team_say guns", "enableMenu")
}

public oldOrNew(id) {
	if(equali(playerSaved[id], "empty") || equali(playerSaved[id], "")) {
		client_cmd(id, "amx_buy_new")
		return 1
	}
	if(playerSelection[id] == 0) {
		client_cmd(id, "amx_buy_selection")
		return 1
	}
	getPreviousGuns(id)
	return 1
}

public getPreviousGuns(id) {
	client_cmd(id, playerSaved[id])
	return 1
}

public getPreviousGunsDisable(id) {
	getPreviousGuns(id)
	playerSelection[id] = 1
	return 1
}

public enableMenu(id) {
	if(playerSelection[id] == 0) {
		client_print(id, print_chat, "[CSO] Gun selection is already enabled")
		return 0
	}
	client_print(id, print_chat, "[CSO] Gun selection has been enabled")
	client_cmd(id, "amx_buy_new")
	playerSelection[id] = 0
	return 1
}

public client_connet(id) {
	playerSelection[id] = 0
	playerSaved[id] = "empty"
	return 1
}

public client_disconnected(id) {
	playerSelection[id] = 0
	playerSaved[id] = "empty"
	return 1
}

public get_weapon_ak47(id) {
	client_cmd(id, "get_weapon_ak47")
	playerSaved[id] = "get_weapon_ak47"
	return 1
}

...

public get_weapon_m4a1(id) {
	client_cmd(id, "get_weapon_m4a1")
	playerSaved[id] = "get_weapon_m4a1"
	return 1
}

Last edited by SaBBa; 09-19-2020 at 04:42.
SaBBa is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-18-2020 , 23:47   Re: Store string in array
Reply With Quote #2

Generally, if you solve your own problem you should post the solution and/or links that help you figure it out and then create a new thread for your new topic. The other benefit to posting a new thread is that people who have already seen this thread will actually see the new thread as new (they won't see this thread again until someone else posts a reply).

FYI.

I'm quite sure there is a bunch of information on this forum about unlimited ammo. The Scripting Help forum is for writing or editing plugins not for asking for links to plugins.
__________________
fysiks is offline
SaBBa
Member
Join Date: Dec 2012
Old 09-19-2020 , 04:33   Re: Store string in array
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Generally, if you solve your own problem you should post the solution and/or links that help you figure it out and then create a new thread for your new topic. The other benefit to posting a new thread is that people who have already seen this thread will actually see the new thread as new (they won't see this thread again until someone else posts a reply).

FYI.

I'm quite sure there is a bunch of information on this forum about unlimited ammo. The Scripting Help forum is for writing or editing plugins not for asking for links to plugins.
Sorry about that, I just don't wanted to bother community with my stupid question, I have posted solution with plugin.

P.S. about unlimited ammo, yeah, there are lots of plugins, but I want unlimited backpack ammo plugin, couldn't find anything is approved plugins section, tried several but none was working

Last edited by SaBBa; 09-19-2020 at 04:36.
SaBBa is offline
SaBBa
Member
Join Date: Dec 2012
Old 09-20-2020 , 07:38   Re: Store string in array
Reply With Quote #4

btw, any idea how to make it more portable, like instead of doing new function for each weapon, pass name as a 3rd parameter from simplemenu plugin and process it in one default function for all guns
SaBBa is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-20-2020 , 11:48   Re: Store string in array
Reply With Quote #5

It would be best to store the CSW_ weapon ID in the array instead of weapon name. Doing this, you can build an array to store info for each weapon, though you can get away with using the weapon name by using the get_weaponid() native. Keep in mind that the array must be built so that the weapon ID corresponds to the appropriate slot in the array, as outlined below.

PHP Code:

#include <amxmodx>

enum AmmoType
{
    
MaxClipAmmo,
    
MaxBPAmmo
}

new const 
WeaponAmmo[][ AmmoType ] = 
{
    { 
0},    //CSW_NONE            0
    
2525 },    //CSW_P228            1
    
2525 },    //CSW_GLOCK           2  
    
2525 },    //CSW_SCOUT           3
    
1},    //CSW_HEGRENADE       4
    
2525 },    //CSW_XM1014          5
    
0},    //CSW_C4              6
    
2525 },    //CSW_MAC10           7
    
2525 },    //CSW_AUG             8
    
1},    //CSW_SMOKEGRENADE    9
    
2525 },    //CSW_ELITE           10
    
2525 },    //CSW_FIVESEVEN       11
    
2525 },    //CSW_UMP45           12
    
2525 },    //CSW_SG550           13
    
2525 },    //CSW_GALIL           14
    
2525 },    //CSW_FAMAS           15
    
2525 },    //CSW_USP             16
    
2525 },    //CSW_GLOCK18         17
    
2525 },    //CSW_AWP             18
    
2525 },    //CSW_MP5NAVY         19
    
2525 },    //CSW_M249            20
    
2525 },    //CSW_M3              21
    
2525 },    //CSW_M4A1            22
    
2525 },    //CSW_TMP             23
    
2525 },    //CSW_G3SG1           24
    
1},    //CSW_FLASHBANG       25
    
2525 },    //CSW_DEAGLE          26
    
2525 },    //CSW_SG552           27
    
2530 },    //CSW_AK47            28
    
0},    //CSW_KNIFE           29
    
2525 }    //CSW_P90             30    
};

public 
plugin_init()
{
    new 
iAmmo get_maxammo"weapon_ak47" MaxClipAmmo );
    
    new 
iBPAmmo get_maxammo"weapon_ak47" MaxBPAmmo );
}
    
get_maxammo( const WeaponName[] , AmmoType:atType )
{
    return 
WeaponAmmoget_weaponidWeaponName ) ][ atType ];

__________________

Last edited by Bugsy; 09-20-2020 at 12:04.
Bugsy is offline
Reply



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 00:15.


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