Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: Razor. on Aug 01, 2021, 05:58 AM

Title: [Beta] Individual Gravity system
Post by: Razor. on Aug 01, 2021, 05:58 AM
Individual Gravity system v0.2b

VC:MP itself has the possibility to change the gravity, however this function when used affects the gravity of all players, but today I bring a practical way to solve this.


Here's a video showing how it works for someone who wants to see it before testing the code: https://www.youtube.com/watch?v=-Jg6U0nmjNs&feature=youtu.be



Repository (v0.2b)
https://github.com/Razorn7/Individual-Gravity-VCMP


Install:
function onPlayerJoin(player) {
CGravity.join(player);
}

function onPlayerMove(player, lastX, lastY, lastZ, newX, newY, newZ) {
CGravity.processMove(player);
}


How to use:
Added functions: player.SetGravity(number gravity)
player.GetGravity(void)

Example:
[spoiler]function onPlayerCommand(player, cmd, text)
{
if ( cmd == "setgravity" ) {
if (!text) PrivMessage(player, "Use: /" + cmd + " <player/ID> <value>");
else {
local plr = FindPlayer(GetTok(text, " ", 1));
if (!plr) PrivMessage(player, "Invalid player.");
else {
local value = GetTok(text, " ", 2);
if (value == null) PrivMessage(player, "You must input a value.");
else if (!IsNum(value)) PrivMessage(player, "The value type must be integer|float.");
else {
plr.SetGravity(value.tointeger());
PrivMessage(player, "You've set " + plr.Name + "'s gravity to: " + value.tointeger() + ".");
}
}
}
}
}

/* GetTok() by KAKAN
   https://pastebin.com/fLTXmNb6 */

function GetTok(string, separator, n, m = 0) {
n = n - 1;
m = m > 0 ? m : n + 1;
local tokenized = split(string, separator),
text = "";
if(n > tokenized.len() || n < 0 || m > tokenized.len()) return null;
tokenized = tokenized.slice(n, m);
return tokenized.reduce( function(prev, next) { return (prev + separator + next) });
}
[/spoiler]


Notes:


Thanks to S.L.C for clarifying a doubt so that the player.SetGravity() return would work the way I wanted.
Title: Re: [Beta] Individual Gravity system
Post by: ℛḝξ☂ on Aug 01, 2021, 12:14 PM
Wow it's such an amazing snippet, I cannot wait to have a try
Title: Re: [Beta] Individual Gravity system
Post by: Luis_Labarca on Nov 23, 2023, 02:04 AM
hello friend link dead