teh1337
Some call me the Dear Leader-most just say teh1337
Modded Guns Made Easy!
Video:
http://www.youtube.com/watch?v=8dutsBK4G9M
Features:
Allows you to treat modded guns just like a weapon, all you have to do is call:
Code:
self thread doSwitchGun(<gun name>);
Also, if that base model is already in use, it will overwrite the gun attributes that the gun currently has, with the ones that the new gun has, and if the player already has the modded gun(not just the basemodel), it will print "You Already Have This Gun!".
The code also features an ammo counter on the bottom right hand corner of the screen.
How to add this to your code:
First, build your doInitGun function modeled on my example below:
Code:
doInitGun()
{
level.tgunbase = [];//What weapon to use for the viewmodel
level.tgunammo = [];//How much ammo is max capacity
level.tgunsammo = [];//How much ammo is given by default
level.tgundelay = [];//The delay between fully automatic shots in seconds
level.tgunfunc = [];//The function that handles damage and fx of the weapon
//BTW: The Index of the array is the name of the gun!
level.tgunbase["test"] = "ray_gun";
level.tgunammo["test"] = 100;
level.tgunsammo["test"] = 50;
level.tgundelay["test"] = 1;
level.tgunfunc["test"] = ::doTestGun;
level.tgunbase["NukePistol"] = "ray_gun";
level.tgunammo["NukePistol"] = 200;
level.tgunsammo["NukePistol"] = 200;
level.tgundelay["NukePistol"] = 0.1;
level.tgunfunc["NukePistol"] = ::doTestGun;
}
As you can see, the gun builder allows for you to define the gun model, the total ammo, the starting ammo, the shots to be fired, and most importantly, the function that is called when the gun is fired.
Lets say you wanted a gun that used the defaultweapon gun model, had 50 max bullets, had a starting ammo of 25 and shot 5 bullets per second, called the function doNinjaGun, with the name "NinjaGun", you would put:
Code:
level.tgunbase["NinjaGun"] = "defaultweapon";//Use the defaultweapon model for the gun
level.tgunammo["NinjaGun"] = 50;//50 is max ammo amount
level.tgunsammo["NinjaGun"] = 25;//25 Starting ammo
level.tgundelay["NinjaGun"] = 0.2;// 1/0.2 = 5 bullets per second
level.tgunfunc["NinjaGun"] = ::doNinjaGun;//You need to add the function ninja gun
After your done building your doInitGun(), you need to add the below to your main init() function:
Code:
level thread doInitGun();
Now you can add the functions for your guns
The function doNinjaGun might look like:
Code:
doNinjaGun(location)//you need to put location as the variable, so you know where the gun shoots
{
playfx(loadfx("misc/fx_zombie_mini_nuke"), location);//We'll play that fx on the location of the bullet
RadiusDamage( location, 50, 50, 50, self );//add a damage radius 50 units wide, that causes 50 damage
}
Then, when your done making your guns, add the below function call in onPlayerSpawned:
Code:
self thread doRunGun();
Finally, add the code below at the bottom of your gsc:
Code:
doRunGun()
{
self endon("disconnect");
self thread doMonitorWeapons();
self.changing = false;
self.tgun = "N/A";
self.tgunct = [];
self.gunz = [];
self.bgunz = [];
self.otherammo = [];
self.otherguns = [];
self.moddedweapon=0;
self.gunname = self createFontString( "default", 1.4 );
self.gunname setPoint( "BOTTOMRIGHT", "BOTTOMRIGHT", -25, -40 );
self.gunname setText("N/A");
self.gunammo = self createFontString( "default", 1.5 );
self.gunammo setPoint( "BOTTOMRIGHT", "BOTTOMRIGHT", -10, -10 );
self.gunammo setText("0/0");
for(;;)
{
if(self.tgun!="N/A")
{
while(self AttackButtonPressed()&&self.tgunct[self.tgun]>0)
{
if(self getCurrentWeapon()==level.tgunbase[self.tgun])
{
self.moddedweapon=1;
vecend = self vec_scal(anglestoforward(self getPlayerAngles()),1000000);
location = BulletTrace(self getTagOrigin("j_head"), vecend, 1, self )[ "position" ];
self [[level.tgunfunc[self.tgun]]](location);
self.tgunct[self.tgun]--;
self.gunammo setText("^1"+self.tgunct[self.tgun]+"^4/^1"+level.tgunammo[self.tgun]);
self SetWeaponAmmoClip(level.tgunbase[self.tgun], 0);
self SetWeaponAmmoStock(level.tgunbase[self.tgun], 0);
wait level.tgundelay[self.tgun];
}else{
go=1;
for(i=0;i<self.bgunz.size;i++)
{
if(self getCurrentWeapon()==self.bgunz[i])
{
self thread doSwitchGun(self.gunz[i]);
go=0;
}
}
if(go==1)
{
self.tgun="N/A";
self.moddedweapon=0;
for(ix=0;ix<self.otherguns.size;ix++)
{
self SetWeaponAmmoClip(self.otherguns[ix], self.otherammo[ix][0]);
self SetWeaponAmmoStock(self.otherguns[ix], self.otherammo[ix][1]);
}
self.gunammo setText("0/0");
self.gunname setText("N/A");
break;
}
}
wait 0.01;
}
}
wait 0.01;
}
}
vec_scal(vec, scale)
{
vec = (vec[0] * scale, vec[1] * scale, vec[2] * scale);
return vec;
}
doSwitchGun(newgun)
{
self.changing = true;
self.otherguns = self GetWeaponsList();
self.gunname setText("^1"+newgun);
if(self.moddedweapon==0)
{
for(ix=0;ix<self.otherguns.size;ix++)
{
self.otherammo[ix][0] = self GetWeaponAmmoClip(self.otherguns[ix]);
self.otherammo[ix][1] = self GetWeaponAmmoStock(self.otherguns[ix]);
//self iprintlnbold("te "+self.otherammo[ix][0]);
self SetWeaponAmmoClip(self.otherguns[ix], 0);
self SetWeaponAmmoStock(self.otherguns[ix], 0);
}
}else{
for(ix=0;ix<self.otherguns.size;ix++)
{
self SetWeaponAmmoClip(self.otherguns[ix], 0);
self SetWeaponAmmoStock(self.otherguns[ix], 0);
}
}
self.moddedweapon=1;//Made by Teh1337
if(!in_array(newgun, self.gunz)||self.leetz == 1)
{
self.leetz=0;
self giveWeapon(level.tgunbase[newgun]);
self switchToWeapon(level.tgunbase[newgun]);
self.tgun = newgun;
if(!in_array(level.tgunbase[newgun], self.bgunz))
{
self.gunz[self.gunz.size] = newgun;
self.bgunz[self.bgunz.size] = level.tgunbase[newgun];
}else{
self.gunz[self pos_array(level.tgunbase[newgun],self.bgunz)] = newgun;
self.bgunz[self pos_array(level.tgunbase[newgun],self.bgunz)] = level.tgunbase[newgun];
}
if(!isDefined(self.tgunct[self.tgun]))
self.tgunct[self.tgun] = level.tgunsammo[self.tgun];
//self iprintlnbold("New Gun is: "+newgun);
self.gunammo setText("^1"+self.tgunct[self.tgun]+"^4/^1"+level.tgunammo[self.tgun]);
}else{
self iprintlnbold("You Already Have This Gun!");
}
wait 0.2;
self.changing = false;
}
doMonitorWeapons()
{
self endon("disconnect");
for(;;)
{
self waittill("weapon_change");
nom=0;
if(self.changing==false)
{
for(i=0;i<self.bgunz.size;i++)
{
if(self getCurrentWeapon()==self.bgunz[i])
{
self.leetz=1;
nom=1;
//self iprintln(self.gunz[i]);
self thread doSwitchGun(self.gunz[i]);
}
}
if(nom==0)
{
self.gunname setText("N/A");
self.moddedweapon=0;
for(ix=0;ix<self.otherguns.size;ix++)
{
self SetWeaponAmmoClip(self.otherguns[ix], self.otherammo[ix][0]);
self SetWeaponAmmoStock(self.otherguns[ix], self.otherammo[ix][1]);
}
}
}
}
}
in_array(str, array)
{
for(i=0;i<array.size;i++)
{
if(array[i]==str)
return true;
}
return false;
}
pos_array(str, array)
{
for(i=0;i<array.size;i++)
{
if(array[i]==str)
return i;
}
return false;
}
//Made by Teh1337
Congrats! Your ready to go, but if you want to give the player the NinjaGun, you have to do:
Code:
self thread doSwitchGun("NinjaGun");//Gives the player the weapon, and switches to it
Woot, now you can easily manage your weapons for waw, and even make weapon stores where you can personalize upgrades and buy new weapons with ease.
Enjoi
<3 Teh1337 <3
Full Example GSC:
Code:
#include common_scripts\utility;
#include maps\_utility;
#include maps\_hud_util;
#include maps\_music;
#include maps\_busing;
initHax()
{
level thread doInitGun();
level thread onPlayerConnect();
}
doInitGun()
{
level.tgunbase = [];//What weapon to use for the viewmodel
level.tgunammo = [];//How much ammo is max capacity
level.tgunsammo = [];//How much ammo is given by default
level.tgundelay = [];//The delay between fully automatic shots in seconds
level.tgunfunc = [];//The function that handles damage and fx of the weapon
//BTW: The Index of the array is the name of the gun!
level.tgunbase["test"] = "ray_gun";
level.tgunammo["test"] = 100;
level.tgunsammo["test"] = 50;
level.tgundelay["test"] = 1;
level.tgunfunc["test"] = ::doTestGun;
level.tgunbase["NukePistol"] = "ray_gun";
level.tgunammo["NukePistol"] = 200;
level.tgunsammo["NukePistol"] = 200;
level.tgundelay["NukePistol"] = 0.1;
level.tgunfunc["NukePistol"] = ::doTestGun;
}
onPlayerConnect()
{
for(;;)
{
level waittill( "connected", player );
player.name = player.playername;
player thread onPlayerSpawned();
}
}
onPlayerSpawned()
{
self thread doRunGun();
wait 10;
self thread doSwitchGun("test");
wait 10;
self thread doSwitchGun("NukePistol");
}
doTestGun(location)
{
playfx(loadfx("misc/fx_zombie_mini_nuke"), location);
RadiusDamage( location, 50, 50, 50, self );
}
doRunGun()
{
self endon("disconnect");
self thread doMonitorWeapons();
self.changing = false;
self.tgun = "N/A";
self.tgunct = [];
self.gunz = [];
self.bgunz = [];
self.otherammo = [];
self.otherguns = [];
self.moddedweapon=0;
self.gunname = self createFontString( "default", 1.4 );
self.gunname setPoint( "BOTTOMRIGHT", "BOTTOMRIGHT", -25, -40 );
self.gunname setText("N/A");
self.gunammo = self createFontString( "default", 1.5 );
self.gunammo setPoint( "BOTTOMRIGHT", "BOTTOMRIGHT", -10, -10 );
self.gunammo setText("0/0");
for(;;)
{
if(self.tgun!="N/A")
{
while(self AttackButtonPressed()&&self.tgunct[self.tgun]>0)
{
if(self getCurrentWeapon()==level.tgunbase[self.tgun])
{
self.moddedweapon=1;
vecend = self vec_scal(anglestoforward(self getPlayerAngles()),1000000);
location = BulletTrace(self getTagOrigin("j_head"), vecend, 1, self )[ "position" ];
self [[level.tgunfunc[self.tgun]]](location);
self.tgunct[self.tgun]--;
self.gunammo setText("^1"+self.tgunct[self.tgun]+"^4/^1"+level.tgunammo[self.tgun]);
self SetWeaponAmmoClip(level.tgunbase[self.tgun], 0);
self SetWeaponAmmoStock(level.tgunbase[self.tgun], 0);
wait level.tgundelay[self.tgun];
}else{
go=1;
for(i=0;i<self.bgunz.size;i++)
{
if(self getCurrentWeapon()==self.bgunz[i])
{
self thread doSwitchGun(self.gunz[i]);
go=0;
}
}
if(go==1)
{
self.tgun="N/A";
self.moddedweapon=0;
for(ix=0;ix<self.otherguns.size;ix++)
{
self SetWeaponAmmoClip(self.otherguns[ix], self.otherammo[ix][0]);
self SetWeaponAmmoStock(self.otherguns[ix], self.otherammo[ix][1]);
}
self.gunammo setText("0/0");
self.gunname setText("N/A");
break;
}
}
wait 0.01;
}
}
wait 0.01;
}
}
vec_scal(vec, scale)
{
vec = (vec[0] * scale, vec[1] * scale, vec[2] * scale);
return vec;
}
doSwitchGun(newgun)
{
self.changing = true;
self.otherguns = self GetWeaponsList();
self.gunname setText("^1"+newgun);
if(self.moddedweapon==0)
{
for(ix=0;ix<self.otherguns.size;ix++)
{
self.otherammo[ix][0] = self GetWeaponAmmoClip(self.otherguns[ix]);
self.otherammo[ix][1] = self GetWeaponAmmoStock(self.otherguns[ix]);
//self iprintlnbold("te "+self.otherammo[ix][0]);
self SetWeaponAmmoClip(self.otherguns[ix], 0);
self SetWeaponAmmoStock(self.otherguns[ix], 0);
}
}else{
for(ix=0;ix<self.otherguns.size;ix++)
{
self SetWeaponAmmoClip(self.otherguns[ix], 0);
self SetWeaponAmmoStock(self.otherguns[ix], 0);
}
}
self.moddedweapon=1;
if(!in_array(newgun, self.gunz)||self.leetz == 1)
{
self.leetz=0;
self giveWeapon(level.tgunbase[newgun]);
self switchToWeapon(level.tgunbase[newgun]);
self.tgun = newgun;
if(!in_array(level.tgunbase[newgun], self.bgunz))
{
self.gunz[self.gunz.size] = newgun;
self.bgunz[self.bgunz.size] = level.tgunbase[newgun];
}else{
self.gunz[self pos_array(level.tgunbase[newgun],self.bgunz)] = newgun;
self.bgunz[self pos_array(level.tgunbase[newgun],self.bgunz)] = level.tgunbase[newgun];
}
if(!isDefined(self.tgunct[self.tgun]))
self.tgunct[self.tgun] = level.tgunsammo[self.tgun];
//self iprintlnbold("New Gun is: "+newgun);
self.gunammo setText("^1"+self.tgunct[self.tgun]+"^4/^1"+level.tgunammo[self.tgun]);
}else{
self iprintlnbold("You Already Have This Gun!");
}
wait 0.2;
self.changing = false;
}
doMonitorWeapons()
{
self endon("disconnect");
for(;;)
{
self waittill("weapon_change");
nom=0;
if(self.changing==false)
{
for(i=0;i<self.bgunz.size;i++)
{
if(self getCurrentWeapon()==self.bgunz[i])
{
self.leetz=1;
nom=1;
//self iprintln(self.gunz[i]);
self thread doSwitchGun(self.gunz[i]);
}
}
if(nom==0)
{
self.gunname setText("N/A");
self.moddedweapon=0;
for(ix=0;ix<self.otherguns.size;ix++)
{
self SetWeaponAmmoClip(self.otherguns[ix], self.otherammo[ix][0]);
self SetWeaponAmmoStock(self.otherguns[ix], self.otherammo[ix][1]);
}
}
}
}
}
in_array(str, array)
{
for(i=0;i<array.size;i++)
{
if(array[i]==str)
return true;
}
return false;
}
pos_array(str, array)
{
for(i=0;i<array.size;i++)
{
if(array[i]==str)
return i;
}
return false;
}