Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help How to pick a random weapon
#1
how do I give myself a random weapon at spawn from a list that I decide.
and how can I make my own texture for a custom entry in a .gdt
Dont wanna overwrite the existing L96A1 texture with my custom L94-Duck texture but I want the regular L96 to have the default texture and my custom L96 to have its own texture (Not camo)
Reply

#2
Create an array of your choice of weapons and use the 'randomInt' function to get a random index for a random weapon. Something like:

PHP Code:
weaps strTok"weapon1,weapon2,weapon3" "," ); // Creates an array of weapons. To add more, write the weapon names as the first argument and separate them by a comma

weapToGive weapsrandomIntweaps.size ) ];
self giveWeapon(weapToGive); 
Reply

#3
whats strTok
that gave me an error
Uninitialized variable weaps or something
Reply

#4
In a for-Loop:

Code:
for(i=1;;i++)
{
if(abuttonpressed)
{
if(i==1){giveWep...}
if(i==2){giveWep...}
...
}
if(=="weaponnumber" ){i=1}

wait .01;
}
Reply

#5
(07-21-2011, 12:11)johamort Wrote: whats strTok
that gave me an error
Uninitialized variable weaps or something

"strTok( string, delimiter )" is a function that tokenizes the string by it's delimiters and returns an array of strings. In the example above, it would generate an array called 'weaps' with 3 values, weapon1, weapon2 and weapon3. Change these to the weapon names of your choice. I don't know why you would get an error though :S
Reply

#6
(07-21-2011, 12:51)Phl3x_ Wrote:
(07-21-2011, 12:11)johamort Wrote: whats strTok
that gave me an error
Uninitialized variable weaps or something

"strTok( string, delimiter )" is a function that tokenizes the string by it's delimiters and returns an array of strings. In the example above, it would generate an array called 'weaps' with 3 values, weapon1, weapon2 and weapon3. Change these to the weapon names of your choice. I don't know why you would get an error though :S

uhm, can you try this yourself?
Reply

#7
I have mate, on many occasions.

PHP Code:
self.weaps strTok"cpgun_mp|bowie_knife_zm|frag_grenade_mp|knife_ballistic_mp""|"); 

This for example, splits the string of weapons up between the '|' and puts them into an array.

If you're still getting the error, post a bit more code
Reply

#8
or you do this

C++ Code
  1. v = [];
  2. v[0] = "ak47_mp";
  3. v[1] = "mp5k_mp";
  4. v[2] = "ak74u_mp";
  5. v[3] = "famas_mp";
  6. v[4] = "fnfal_mp";
  7.  
  8. weapon = v[ randomInt( v.size ) ];
(08-10-2011, 12:58)Pozzuh Wrote:
Se7en Wrote:Stealed, from cod4 mod ...
look who's talking

[Release] Old School Mod v2.2
[Release] Scroll menu

Reply

#9
If I were you I'd use iAegle solution , less confusing when you have alot of codes

iAegle btw is this how you need to use it?

self giveweapon ( weapon )

v = [];
v[0] = "ak47_mp";
v[1] = "mp5k_mp";
v[2] = "ak74u_mp";
v[3] = "famas_mp";
v[4] = "fnfal_mp";

weapon = v[ randomInt( v.size ) ];
Reply

#10
how can I make my own texture for a custom entry in a .gdt
Dont wanna overwrite the existing L96A1 texture with my custom L94-Duck texture but I want the regular L96 to have the default texture and my custom L96 to have its own texture (Not camo)
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Release] [SOURCE] Random Weapons. [HARD] Tony. 1 4,106 11-08-2013, 11:11
Last Post: Nekochan
  Help source random weapons [HARD] Tony. 4 4,708 11-08-2013, 05:25
Last Post: [HARD] Tony.
Question Help Mw2 weapon skin question FroxIVx4 1 2,952 10-13-2013, 16:54
Last Post: hmann
Question Help Weapon Name iRoNinja 8 6,589 10-08-2013, 08:31
Last Post: iRoNinja
  Mw2 weapon porting? Cuddlyedits 3 4,736 09-15-2013, 16:43
Last Post: DidUknowiPwn
  Help choose 2 random players?(1 each team) 26hz 6 4,651 09-12-2013, 17:32
Last Post: Yamato
Rainbow [Release] MW3: Random Weapon Plugin V1 Nekochan 50 33,295 09-11-2013, 15:11
Last Post: EnVi Sweden Rocks
Exclamation [Request] Random Weapon At Spawn Scripts18 3 4,739 07-27-2013, 23:53
Last Post: DidUknowiPwn
  Help Receiving a random primary & secondary DidUknowiPwn 5 4,406 07-22-2013, 09:47
Last Post: Yamato
  Help Mw2 weapon skin question FroxIVx4 1 2,922 07-06-2013, 19:22
Last Post: surtek

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.