I made a gravity type of thing for one of my games.
You used a "gravlifter" to move crates and slam them into the ground, smashing rats.

Anyway heres the relevent function
Code:

function gravGunMain(){
var myTemp;
sfxBuzz = ent_playloop(gravEnt,gravBuzz,600); //start buzzing noise at gravEnt
sfxElectroHumm = snd_loop(electroHumm,25,0); //start underlying electric humm
while(effectCount < 6){
ent_create("magma_tirc.bmp",gravEnt.x,gravFx); //create effects
effectCount += 1;
}
while(gravSwitch == 1){
phent_setdamping(gravEnt,90,30); //set linear damping high to help control
//- slam gravEnt to ground
if(mouse_right){
if(myTemp == 0){
myTemp = 1;
phent_addvelcentral(gravEnt,vector(0,0,-1500));
// phent_addvellocal(gravEnt,vector(1000,0,0),vector(0,0,0));

}
}
else{ //return to hover position
myTemp = 0;
}
gravPointEnt.z = max(-350,min(gravPointEnt.z,-200)); //lock z range of gravPointEnt

//- set and adjust final movement vector
vec_lerp(gravForce,gravPointEnt.x,gravEnt.x,0.5);
vec_sub(gravForce,gravEnt.x);

//- add physics force to gravEnt
phent_addvelcentral(gravEnt,gravForce);
wait(1);
}
snd_stop(sfxBuzz); //stop buzzing
snd_stop(sfxElectroHumm); //stop humming
phent_setdamping(gravEnt,10,30); //return to low damping for better free flight
}



gravPointEnt is an invisible entity that is controled with the mouse, this entity marks where the gravEnt should be.
gravEnt is the entity affected by gravity.
gravSwitch is the toggle, == 1 gravity gun is on, == 0 freeflight


Making guns illegal will save as many lives as making murder illegal.