Forum

Coding a scripting language in QC

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Postby Error » Sun Jun 29, 2008 9:13 am

any update on this?
User avatar
Error
InsideQC Staff
 
Posts: 865
Joined: Fri Nov 05, 2004 5:15 am
Location: VA, USA

Postby GiffE » Mon Jun 30, 2008 2:01 am

Error wrote:any update on this?

Well I did one aswell, to make my weapon's scripted (i finished it a few days ago):
Code: Select all
entity LoadWeapon(string weapon_file)
{
   local float f,count,i;
   local string ln,key,value;
   entity weap;
   weap = spawn();
   f = fopen(weapon_file, FILE_READ);
   if(f != -1)
   {
      ln = fgets(f);
      while(ln != string_null)
      {
         tokenizebyseparator(ln,"=");
         key = argv(0);
         value = argv(1);
         if(key == "name")
            weap.w_name = strzone(strireplace("_", " ", value));
         else if(key == "viewmodel")
            weap.v_model = strzone(value);
         else if(key == "model")
            weap.w_model = strzone(value);
         else if(key == "type")
            weap.w_type = stof(value);
         else if(key == "clips")
            weap.w_clips = stof(value);
         else if(key == "clipsize")
            weap.w_clipsize = stof(value);
         else if(key == "firedelay")
            weap.w_firedelay = stof(value);
         else if(key == "weapondamage")
            weap.w_weapdmg = stof(value);
         else if(key == "fps_firestart")
            weap.fps_firestart = stof(value);
         else if(key == "fps_fireend")
            weap.fps_fireend = stof(value);
         else if(key == "fps_reloadstart")
            weap.fps_reloadstart = stof(value);
         else if(key == "fps_reloadend")
            weap.fps_reloadend = stof(value);
         else if(key == "maxleft")
            weap.w_maxyaw_left = stof(value);
         else if(key == "maxright")
            weap.w_maxyaw_right = stof(value);
         else if(key == "semiauto")
            weap.w_semiauto = TRUE;
         else if(key == "firesound")
            weap.w_firesound = strzone(value);
         else if(key == "reloadsound")
            weap.w_reloadsound = strzone(value);
         else if(key == "speedmult")
            weap.w_speedmult = stof(value);
         else if(key == "spreadmult")
            weap.w_spreadmult = stov(value);
         ln = fgets(f);
      }
   }
   if(weap.w_semiauto != TRUE)
      weap.w_semiauto = FALSE;
      
   return weap;
}

basically it loads all of the info from a script file and puts it onto an entity. Then when a player switches weapons, it just copys all the info from that entity to the player.
Scripts are loaded on Map load so it will only effect load time rather than lag.

Heres an example of what the script looks like. I made it more INI style cause its easier to parse.
Code: Select all
name=Berreta_M9
viewmodel=models/weapons2/mk23/mk23_1st.md3
model=models/weapons2/mk23/mk23.md3
type=1
clips=3
clipsize=7
firedelay=0.2
semiauto
ammotype=pistol
weapondamage=40
speedmult=1.1
spreadmult=10 10 -14
maxleft=5
maxright=-10
firesound=sound/weapons/mk23/fire.wav
reloadsound=sound/weapons/mk23/reload.wav
fps_firestart=1
fps_fireend=2
fps_reloadstart=3
fps_reloadend=24


I had a ton of data for each weapon, names are pretty explanitory. ( vid here to see some of the weapon stuff in action )

-Gif
GiffE
 
Posts: 170
Joined: Sun Oct 08, 2006 3:39 pm
Location: USA, CT

Postby Error » Mon Jun 30, 2008 9:21 am

thanks, just learned how to use tokens :P
User avatar
Error
InsideQC Staff
 
Posts: 865
Joined: Fri Nov 05, 2004 5:15 am
Location: VA, USA

Previous

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest