Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: smart weapon response

  1. #11
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    Quote Originally Posted by Tally View Post
    Build that onPlayerConnected(). Now, your giveWeapon() function will work:

    Code:
    self giveWeapon( self.weapon + response );
    Are you sure?

  2. #12
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Tally what do you mean with "Build a player array out of it"?

  3. #13
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by Ni3ls View Post
    Tally what do you mean with "Build a player array out of it"?
    I mean create an array. Basic Scripting 101 - only "self" and "level" definitions can be used throughout a script - you can pass the definition across to other functions. Otherwise, the definition would only work in a particular function. Using the word "weapon" wont carry its struct across to other functions. Hence why you were getting the "undefined" error - you created the weapon + number array in a function where and once your script left that function, the definition was dead (i.e. no longer valid).

  4. #14
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by serthy View Post
    Are you sure?
    LOL no! I'm not sure! Completely untested, but it looks right to me. Why? Do you foresee a problem with it?

  5. #15
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by Tally View Post
    I mean create an array. Basic Scripting 101 - only "self" and "level" definitions can be used throughout a script - you can pass the definition across to other functions. Otherwise, the definition would only work in a particular function. Using the word "weapon" wont carry its struct across to other functions. Hence why you were getting the "undefined" error - you created the weapon + number array in a function where and once your script left that function, the definition was dead (i.e. no longer valid).
    Oke now i feel really dumb. I had an exam today and my brain is still messed... I know how to build a player array, but I don't know why to do that and what should inside that array.

  6. #16
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by Ni3ls View Post
    Oke now i feel really dumb. I had an exam today and my brain is still messed... I know how to build a player array, but I don't know why to do that and what should inside that array.
    Try my second idea. It uses an existing array, and you wont have to create a new one.

  7. #17
    Private First Class YuriJurek's Avatar
    Join Date
    Jun 2013
    Posts
    219
    Thanks
    152
    Thanked 88 Times in 47 Posts
    Why all this hassle?

    Code:
    level.weapon = [];
    	
    	level.weapon[0] = "greasegun_mp";
    	level.weapon[1] = "mp40_mp";
    	level.weapon[2] = "pps42_mp";
    	level.weapon[3] = "ppsh_mp";
    	level.weapon[4] = "sten_mp";
    	level.weapon[5] = "thompson_mp";
    	level.weapon[6] = "mac10_mp";
    	level.weapon[7] = "ak74_mp";
    	level.weapon[8] = "mp5_mp";
    	level.weapon[9] = "ump45_mp";
    	level.weapon[10] = "p90_mp";
    	level.weapon[11] = "bar_mp";
    	level.weapon[12] = "bren_mp";
    	level.weapon[13] = "";
    	level.weapon[14] = "fg42_mp";
    	level.weapon[15] = "rpd_mp";
    	level.weapon[16] = "acr_mp";
    	level.weapon[17] = "g43_mp";
    	level.weapon[18] = "m1garand_mp";
    	level.weapon[19] = "m1carbine_mp";
    	level.weapon[20] = "mp44_mp";
    	level.weapon[21] = "svt40_mp";
    	level.weapon[22] = "r700_mp";
    	level.weapon[23] = "barret_mp";
    	level.weapon[24] = "kar98k_mp";
    	level.weapon[25] = "enfield_mp";
    	level.weapon[26] = "mosing_nagant_mp";
    	level.weapon[27] = "springfield_mp";
    	level.weapon[28] = "";
    	level.weapon[29] = "m4";
    	level.weapon[30] = "aug_mp";
    	level.weapon[31] = "sig_mp";
    	level.weapon[32] = "ak47_mp";
    	level.weapon[33] = "famas_mp";
    	level.weapon[34] = "shotgun_mp";
    	level.weapon[35] = "winchester_mp";
    	level.weapon[36] = "db_mp";
    	level.weapon[37] = "benneli_mp";
    	level.weapon[38] = "kar98k_sniper_mp";
    	level.weapon[39] = "enfield_scope_mp";
    	level.weapon[40] = "mosin_nagant_sniper_mp";
    Code:
    for(i = 0; i < level.weapon.size; i++)
    	{
    		if(int(response) == i)
    			self giveweapon(level.weapon[i]);
    	}
    You can also alter the "i" value if the response doesn't match the weapon due to an array starting with index of 0.
    Last edited by YuriJurek; 15th December 2014 at 18:11.

  8. The Following User Says Thank You to YuriJurek For This Useful Post:

    Ni3ls (15th December 2014)

  9. #18
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by YuriJurek View Post
    Why all this hassle?

    Code:
    level.weapon = [];
    	
    	level.weapon[0] = "greasegun_mp";
    	level.weapon[1] = "mp40_mp";
    	level.weapon[2] = "pps42_mp";
    	level.weapon[3] = "ppsh_mp";
    	level.weapon[4] = "sten_mp";
    	level.weapon[5] = "thompson_mp";
    	level.weapon[6] = "mac10_mp";
    	level.weapon[7] = "ak74_mp";
    	level.weapon[8] = "mp5_mp";
    	level.weapon[9] = "ump45_mp";
    	level.weapon[10] = "p90_mp";
    	level.weapon[11] = "bar_mp";
    	level.weapon[12] = "bren_mp";
    	level.weapon[13] = "";
    	level.weapon[14] = "fg42_mp";
    	level.weapon[15] = "rpd_mp";
    	level.weapon[16] = "acr_mp";
    	level.weapon[17] = "g43_mp";
    	level.weapon[18] = "m1garand_mp";
    	level.weapon[19] = "m1carbine_mp";
    	level.weapon[20] = "mp44_mp";
    	level.weapon[21] = "svt40_mp";
    	level.weapon[22] = "r700_mp";
    	level.weapon[23] = "barret_mp";
    	level.weapon[24] = "kar98k_mp";
    	level.weapon[25] = "enfield_mp";
    	level.weapon[26] = "mosing_nagant_mp";
    	level.weapon[27] = "springfield_mp";
    	level.weapon[28] = "";
    	level.weapon[29] = "m4";
    	level.weapon[30] = "aug_mp";
    	level.weapon[31] = "sig_mp";
    	level.weapon[32] = "ak47_mp";
    	level.weapon[33] = "famas_mp";
    	level.weapon[34] = "shotgun_mp";
    	level.weapon[35] = "winchester_mp";
    	level.weapon[36] = "db_mp";
    	level.weapon[37] = "benneli_mp";
    	level.weapon[38] = "kar98k_sniper_mp";
    	level.weapon[39] = "enfield_scope_mp";
    	level.weapon[40] = "mosin_nagant_sniper_mp";
    Code:
    for(i = 0; i < level.weapon[size]; i++)
    	{
    		if(int(response) == i)
    			self giveweapon(level.weapon[i]);
    	}
    You can also alter the "i" value if the response doesn't match the weapon due to an array starting with index of 0.
    You wouldn't need to cycle through them all:

    Code:
    self giveweapon( level.weapon[ int( response ) ] );

  10. The Following User Says Thank You to Tally For This Useful Post:

    Ni3ls (15th December 2014)

  11. #19
    Private First Class YuriJurek's Avatar
    Join Date
    Jun 2013
    Posts
    219
    Thanks
    152
    Thanked 88 Times in 47 Posts
    Quote Originally Posted by Tally View Post
    You wouldn't need to cycle through them all:

    Code:
    self giveweapon( level.weapon[ int( response ) ] );
    Thanks, even better
    Last edited by YuriJurek; 15th December 2014 at 18:16.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •