Source (projectile.inc) | https://github.com/Agneese-Saini/SA-...projectile.inc |
Example: Throw Deagle | https://github.com/Agneese-Saini/SA-...row_deagle.pwn |
Example: M4-Grenade Launcher | https://github.com/Agneese-Saini/SA-...e_launcher.pwn |
Dependency: ColAndreas Plugin | https://sampforum.blast.hk/showthread.php?tid=586068 |
CreateProjectile(Float:x, Float:y, Float:z, Float:vx, Float:vy, Float:vz, Float:rx = 0.0, Float:ry = 0.0, Float:rz = 0.0, Float:spherecol_radius = 1.0, Float:ground_friction = 5.0, Float:collision_friction = 0.2, Float:air_resistance = 0.5, Float:gravity = 10.0, Float:playercol_radius = 0.8, bool:collide_simulation = false, Float:mass = 1.0);
Purpose:Create's a physics simulation.Returns:Simulation id. (range: MAX_PROJECTILES)Parameters:
Returns INVALID_PROJECTILE_ID if function was unsuccessful."x": initial x position
"y": initial y position
"z": initial z position
"vx": initial x velocity
"vy": initial y velocity
"vz": initial z velocity
"rx": initial x rotation (optional)
"ry": initial y rotation (optional)
"rz": initial z rotation (optional)
"spherecol_radius": simulation's collision sphere radius (optional)
"ground_friction": value of friction caused by ground (optional)
"collision_friction": value of friction caused by colliding with an object (optional)
"air_resistance": value of resistance caused by air (optional)
"gravity": value of gravity's pull (optional)
"playercol_radius": value of collision radius of a player, if set to 0.0, there will be no collision with players (optional)
"collide_simulation": true = simulation will be able to detect collision with another simulation and bounce back (optional)
"mass": mass of simulation (only useful if collide_simulation is set to true) (optional)
IsValidProjectile(projid)
Purpose:Validates a projectile's existance.Returns:true = projectile existsParameters:"projid": projectile id
false = doesn't exist
DestroyProjectile(projid)
Purpose:Destroys a projectile simulation.Returns:1 = projectile was destroyedParameters:
0 = projectile id doesn't exist"projid": projectile id
GetProjectilePoolSize()
Purpose:Returns the highest projectile currently in use of the server.Returns:The highest projectileid currently in use on the server or -1 if there are no active projectilesParameters:"This function has no parameters."
GetProjectilePos(projid, &Float:x, &Float:y, &Float:z)
Purpose:Gets projectile's current position.Returns:1 = function was successParameters:
0 = unsuccessful"projid": projectile id
"x": x position will be stored in here
"y": y position will be stored in here
"z": z position will be stored in here
GetProjectileRot(projid, &Float:rx, &Float:ry, &Float:rz)
Purpose:Gets projectile's current rotation.Returns:1 = function was successParameters:
0 = unsuccessful"projid": projectile id
"rx": x rotation will be stored in here
"ry": y rotation will be stored in here
"rz": z rotation will be stored in here
GetProjectileVel(projid, &Float:vx, &Float:vy, &Float:vz)
Purpose:Gets projectile's current velocity.Returns:1 = function was successParameters:
0 = unsuccessful"projid": projectile id
"vx": x velocity will be stored in here
"vy": y velocity will be stored in here
"vz": z velocity will be stored in here
UpdateProjectileVel(projid, Float:vx, Float:vy, Float:vz)
Purpose:callbacks:Sets projectile's current velocity to the values.Returns:1 = function was successParameters:
0 = unsuccessful"projid": projectile id
"vx": x velocity to change
"vy": y velocity to change
"vz": z velocity to change
OnProjectileUpdate(projid)
Purpose:Called every time a projectile's position/velocity is changed.Returns:This callback does not handle returnsParameters:"projid": projectile id
OnProjectileStop(projid)
Purpose:Called when a projectile has no more velocity left (i.e. 0).Returns:This callback does not handle returnsParameters:"projid": projectile id
OnProjectileCollide(projid, type, Float:x, Float:y, Float:z, extraid)
Purpose:definitions:Called when a projectile collides with something.Returns:This callback does not handle returnsParameters:"projid": projectile id
"type": type of thing the projectile collided with (checkout "definitions" for type defines)
"x": collision x position
"y": collision yposition
"z": collision z position
"extraid": id of the collided thing (PROJECTILE_COLLIDE_GROUND and PROJECTILE_COLLIDE_CIELING won't return any extraid - PROJECTILE_COLLIDE_SIMULATION will return the other simulation's id - PROJECTILE_COLLIDE_OBJECT will return the objectid - PROJECTILE_COLLIDE_PLAYER will return the player's id)
#define MAX_PROJECTILES 100
^^ Define the maximum amount of projectiles that can be created and handled at once
(user can pre-define before inclusion)
#define PROJECTILE_TIMER_INTERVAL 20
^^ Define the timer interval which will be responsible for updating projectiles' data in every timer step
(user can pre-define before inclusion)
#define INVALID_PROJECTILE_ID -1
^^ Invalid id definition of a projectile (returned by "CreateProjectile" when function is unsuccessful)
#define PROJECTILE_COLLIDE_GROUND 0
#define PROJECTILE_COLLIDE_CIELING 1
#define PROJECTILE_COLLIDE_SIMULATION 2
#define PROJECTILE_COLLIDE_OBJECT 3
#define PROJECTILE_COLLIDE_PLAYER 4
^^ Type of projectiles (used in callback: "OnProjectileCollide")
Since this is a simulation based on sphere's it doesn't matter. You can make your own rotation under OnProjectileUpdate, and use the velocity function to depict direction.
|
Also i was concerned about raycasting 3 times in a 20ms timer. That would cause lag right?
|
YOU should do the rotation BECAUSE it's a sphere based system... Take the example for example (lol), the gun should spin a little from throwing it. And balls spin.Not necessarily, unless you had like 500 objects moving at once... which I'm going to try...
|
Impressive, +REP,
still curious tho, what can be accomplished by this? I mean any ideas? |
Projectile(Float:x, Float:y, Float:z, Float:vx, Float:vy, Float:vz, Float:sphere_radius = 1.0, Float:acceleration = 0.0, Float:mass = 1.0, Float:friction = 10.0, Float:air_resistance = 0.5, Float:gravity = 4.1, bool:playercol = true);
Since this is a simulation based on sphere's it doesn't matter. You can make your own rotation under OnProjectileUpdate, and use the velocity function to depict direction.
Also i was concerned about raycasting 3 times in a 20ms timer. That would cause lag right? |
That would be great, let me know the result and are you going to use this include for testing or just raycast?
|
This include of course, I wanna see it in action!
Won't be able to until either this weekend or the week after next though. If anyone else wants to do it in the meantime that'd be great, but I'm still going to try it on my PC since it's shitty (which means the test will accommodate cheap, shitty servers too kinda). EDIT: @DRIFT_HUNTER: Well a ColAndreas raycast is a bit heavier than the position functions. It still shouldn't, but that's why people fear ColAndreas. They think it's a lot heavier than it really is. |
GetProjectileRot(projid, &Float:rx, &Float:ry, &Float:rz);
forward OnProjectileCollide(projid, type, Float:x, Float:y, Float:z, modelid);
PushProjectile(projid, Float:vx, Float:vy, Float:vz);
Are the objects in your examples supposed to hold the same altitude while they move? They also don't seem to react to objects with which they collide.
|