setupboat()
{
player = self;
watertrig = getent("can_transform_into_boat_trig","targetname"); // The trigger the player needs to be in to transform into boat
landtrig = getentarray("landtrigger","targetname"); // The trigger that stops the boat from going on the land
can_be_boat = 1;
for(a=0;a<landtrig.size;a++)
{
if(player isTouching(landtrig[a]) || !player isTouching(watertrig))
{
player iprintlnbold("Please go further into the water");
player.form = "player";
can_be_boat = 0;
}
}
if(can_be_boat == 1)
{
spawnorig = (player.origin[0],player.origin[1],32); // X and Y stay the same, Height is different.
player.boat = spawn("script_model",spawnorig - (0,0,150)); // Makes the boat spawn under the player
level.modelcount++;
player iprintlnbold("Hold the Attack button (Fire) to go forward");
player thread checkforplayerdeath();
player.forcebounce = 0;
player thread forcebounce();
player disableweapon(); // We don't want him to shoot do we, also if he shoots the boat stops moving upwards because the forward movement will cancel the upwards one.
wait .1;
player.boat setmodel("xmodel/v_br_sea_sicily1_fishingboat");
player linkto(player.boat);
player.boat moveto(spawnorig,2);
playfx(level.fx_boat_spawn,player.boat.origin);
player.boat playsound("boat_spawn");
// level.testboat = spawn("script_model",spawnorig + (0,500,0));
// level.testboat setmodel("xmodel/v_br_sea_sicily1_fishingboat");
// level.testboat.health = 100;
player.kill = 0; // Tells script if player should be killed on thread sink() --> 1 = yes 0 = no
wait 2;
player thread moveboat(player.boat); // Makes the boat move
player thread hitdetection(); // Makes the boat somewhat detect other boats
player setclientcvar("cg_thirdperson","1");
player setclientcvar("cg_thirdpersonrange","300");
player.origin = player.boat.origin;
player detachall();
player setmodel("xmodel/blankmodel"); // Server would crash if i did setmodel(""); so i made a blank xmodel
player setclientcvar("com_maxfps","20"); // This makes the boat move INCREDIBLY smooth.
player.health = 100;
player.boat.speed = 10;
// player.boat.playsound = "move"; // I quickly tried playing moving sounds, but i failed. Might try again some time
}
}
moveboat(boat)
{
player = self;
landtrig = getentarray("landtrigger","targetname");
islandtrig = getent("cant_go_on_island_trig","targetname");
player endon("crashed");
player endon("boat sunk");
while(1)
{
wait 0.05;
boat.angles = player.angles;
for(a=0;a<landtrig.size;a++)
{
if(player isTouching(landtrig[a]))
{
if(!isDefined(player.pers["savedmodel"]))
maps\mp\gametypes\_teams::model();
else
player maps\mp\_utility::loadModel(player.pers["savedmodel"]);
player iprintlnbold("Silly you, boats can't go on land");
player.land = 1;
player thread sink();
a = landtrig.size-1;
break;
}
}
if(player isTouching(islandtrig))
{
player iprintlnbold("Please use the wooden thing to go on this island");
player.kill = 1;
player thread sink();
break;
}
if(player attackbuttonpressed())
{
// if(state == "idle")
// {
// player.boat stoploopsound();
// player.boat playloopsound("boat_engine_moving");
// state = "moving";
// iprintlnbold("moving");
// }
if(boat.speed >= 0 && boat.speed < 1500)
{
boat.speed += 10;
}
if(boat.speed >= 1500)
boat.speed = 1500;
}
else
{
// if(state == "moving")
// {
// player.boat stoploopsound();
// player.boat playloopsound("boat_engine_idle");
// state = "idle";
// iprintlnbold("idle");
// }
if(boat.speed > 0)
boat.speed -= 10;
if(boat.speed <= 0)
{
boat.speed = 0;
continue;
}
}
// iprintln(boat.speed);
if(boat.speed > 0) // I think it's always greater than zero
{
goto = boat.origin + maps\mp\_utility::vectorScale(anglestoforward(boat.angles),500); // To where he is looking + 500 units
time = calcspeed(boat.speed, boat.origin, goto); // Calcspeed thread can be found below
boat moveto(goto,time);
}
}
}
hitdetection()
{
player = self;
bouncetrig = getent("boat_bouncetrig","targetname");
wait 0.1; // allow stuff to update
player endon("boat sunk");
while(1)
{
players = getentarray("player","classname");
for(i=0;i<players.size;i++)
{
if(player.forcebounce != 1)
{
if(!isDefined(players[i]))
continue;
if(!isAlive(players[i]))
continue;
if(players[i] == player)
continue;
}
if(player.forcebounce == 1 || distance(player.radius_centre_1, players[i].origin) < 150 || distance(player.radius_centre_2, players[i].origin) < 152 || distance(player.radius_centre_3, players[i].origin) < 185 || distance(player.radius_centre_4, players[i].origin) < 168 || distance(player.radius_centre_5, players[i].origin) < 195)
{
player notify("crashed");
player playsound("boats_collide");
if(player.boat.speed < 125) // I don't want very, VERY small damage
player.health -= 5;
else if(player.boat.speed >= 125)
{
player.health -= player.boat.speed / 25;
if(player.forcebounce != 1)
{
damage = player.boat.speed / 30;
dir = vectortoangles(player.origin - players[i].origin);
dir = ((dir[0] / 360), (dir[1] / 360), (dir[2] / 360));
players[i] FinishPlayerDamage( player, player, damage, 1, "MOD_PROJECTILE", "binoculars_mp", player.origin, dir, "none");
player iprintln("^1You inflicted ^3" + damage + "^1 Damage on ^7" + players[i].name);
}
}
player.forcebounce = 0;
if(player.health > 0) // && players[i].form == "boat")
{
if(player.boat.speed < 250) // I don't want the boats to get stuck in eachother (They do without this)
player.boat.speed = 250;
while(player.boat.speed > 10) // Makes the boat bounce back
{
wait 0.05;
player.boat.angles = player.angles;
goto = player.boat.origin + maps\mp\_utility::vectorScale(anglestoforward(player.boat.angles),-500);
time = calcspeed(player.boat.speed, player.boat.origin, goto);
player.boat moveto(goto,time);
player.boat.speed -= 20;
}
}
else if(player.health <= 0) // if the collision killed him, he should really get killed
player.kill = 1;
player.boat.speed = 10;
player thread moveboat(player.boat); // Give the player control over the boat again
}
}
wait 0.05;
}
}
sink() // To be called with player
{
player = self;
player notify("boat sunk");
player notify("crashed");
player.boat.speed = 0;
player.boat moveto(player.boat.origin,0.05);
player.boat setmodel("xmodel/v_br_sea_fishing-boat_dmg");
playfx(level.fx_boat_fire,player.boat.origin);
player.boat.origin = player.boat.origin + maps\mp\_utility::vectorScale(anglestoforward(player.boat.angles),52); // The models their origins are one different places
player.origin = player.boat.origin;
player unlink();
player.boat.origin -= (0,0,40);
player.boat moveto(player.boat.origin - (0,0,150),2);
playfx(level.fx_boat_after,player.boat.origin);
player.boat playsound("boat_sink");
if(player.kill == 1)
player suicide();
else
{
player.kill = 0;
player enableweapon();
}
player.form = "player";
player setclientcvar("cg_thirdperson","0");
player setclientcvar("cg_thirdpersonrange","120");
player setclientcvar("com_maxfps","125");
wait 4;
player.boat delete();
level.modelcount--;
player.staticwaittime = 15;
player.waittime = player.staticwaittime; // else waittime would keep getting less, also in the for loop.
for(a=0;a<player.staticwaittime;a++)
{
wait 1;
player.waittime--;
}
}
checkforplayerdeath()
{
player = self;
player endon("boat sunk");
while(1)
{
wait 0.05;
if(!isAlive(player))
{
// iprintlnbold("Player.health < 0!!! oshit sinking boat!");
if(player.kill != 1)
player.kill = 0;
player thread sink();
break;
}
else // This is where i set the "boundaries" (if thats a word) of the boat, if another boat gets anywhere near these it'll detect as a collision
{
player.radius_centre_1 = player.boat.origin + maps\mp\_utility::vectorScale(anglestoforward(player.boat.angles),128);
player.radius_centre_2 = player.boat.origin + maps\mp\_utility::vectorScale(anglestoforward(player.boat.angles),64);
player.radius_centre_3 = player.boat.origin;
player.radius_centre_4 = player.boat.origin + maps\mp\_utility::vectorScale(anglestoforward(player.boat.angles),-64);
player.radius_centre_5 = player.boat.origin + maps\mp\_utility::vectorScale(anglestoforward(player.boat.angles),-128);
}
}
}
forcebounce()
{
trig = getent("boat_bouncetrig","targetname");
while(1)
{
trig waittill("trigger",player);
player.forcebounce = 1;
wait 1;
}
}
calcspeed(speed, origin1, moveto)
{
dist = distance(origin1, moveto);
time = (dist / speed);
return time;
}