mirror of
https://github.com/Ragora/T2-CPP.git
synced 2026-07-16 10:14:33 +00:00
Added sprintf
This commit is contained in:
parent
2f163fdd59
commit
09c3e57b6d
4 changed files with 42 additions and 16 deletions
|
|
@ -17,3 +17,9 @@ This function did not exist before in Torque Script, it returns whether or not t
|
||||||
|
|
||||||
#### Player.isJumping()
|
#### Player.isJumping()
|
||||||
This function did not exist before in Torque Script, it returns whether or not the Player is currently jumping.
|
This function did not exist before in Torque Script, it returns whether or not the Player is currently jumping.
|
||||||
|
|
||||||
|
#### sprintf(format, ...)
|
||||||
|
This function did not exist before in Torque Script. It returns a formatted string according to format with all variable
|
||||||
|
arguments up to a total of twenty filled in. Refer to C's sprintf for more information.
|
||||||
|
|
||||||
|
Note: Only %s should be used in the format as Torque Script passes all data around as strings.
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ bool conPlayerGetJettingState(SimObject *obj, S32 argc, const char* argv[]);
|
||||||
const char* conGrenadeProjectileGetPosition(SimObject *obj, S32 argc, const char* argv[]);
|
const char* conGrenadeProjectileGetPosition(SimObject *obj, S32 argc, const char* argv[]);
|
||||||
const char* conGrenadeProjectileGetVelocity(SimObject *obj, S32 argc, const char* argv[]);
|
const char* conGrenadeProjectileGetVelocity(SimObject *obj, S32 argc, const char* argv[]);
|
||||||
|
|
||||||
// Projectile explode
|
// Projectile explode -------------------------------
|
||||||
bool conProjectileExplode(SimObject *obj, S32 argc, const char* argv[]);
|
bool conProjectileExplode(SimObject *obj, S32 argc, const char* argv[]);
|
||||||
|
|
||||||
// Tests Position Z
|
// General Commands ---------------------------------
|
||||||
const char *conPlayerSetZ(SimObject *obj, S32 argc, const char *argv[]);
|
const char* conSprintf(SimObject *obj, S32 argc, const char* argv[]);
|
||||||
|
|
@ -18,5 +18,7 @@ extern "C"
|
||||||
|
|
||||||
Con::addMethodS("GrenadeProjectile", "getposition", &conGrenadeProjectileGetPosition,"Accurately gets the position of the GrenadeProjectile", 2, 2);
|
Con::addMethodS("GrenadeProjectile", "getposition", &conGrenadeProjectileGetPosition,"Accurately gets the position of the GrenadeProjectile", 2, 2);
|
||||||
Con::addMethodS("GrenadeProjectile", "getvelocity", &conGrenadeProjectileGetVelocity,"Gets the velocity of the GrenadeProjectile", 2, 2);
|
Con::addMethodS("GrenadeProjectile", "getvelocity", &conGrenadeProjectileGetVelocity,"Gets the velocity of the GrenadeProjectile", 2, 2);
|
||||||
|
|
||||||
|
Con::addMethodS(NULL, "sprintf", &conSprintf,"Formats a string. See the C sprintf.", 2, 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,18 +13,6 @@ const char *conGetAddress(SimObject *obj, S32 argc, const char *argv[])
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *conPlayerSetZ(SimObject *obj, S32 argc, const char *argv[])
|
|
||||||
{
|
|
||||||
DX::Player test = DX::GetPlayerPointer(obj);
|
|
||||||
test.position_y = 100;
|
|
||||||
test.position_z = 300;
|
|
||||||
test.position_x = 500;
|
|
||||||
|
|
||||||
char result[256];
|
|
||||||
sprintf(result, "LOL");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool conPlayerGetJumpingState(SimObject *obj, S32 argc, const char* argv[])
|
bool conPlayerGetJumpingState(SimObject *obj, S32 argc, const char* argv[])
|
||||||
{
|
{
|
||||||
DX::Player operand = DX::GetPlayerPointer(obj);
|
DX::Player operand = DX::GetPlayerPointer(obj);
|
||||||
|
|
@ -74,3 +62,33 @@ const char* conGrenadeProjectileGetVelocity(SimObject *obj, S32 argc, const char
|
||||||
sprintf_s<256>(result, "%f %f %f", grenade.velocity_x, grenade.velocity_y, grenade.velocity_z);
|
sprintf_s<256>(result, "%f %f %f", grenade.velocity_x, grenade.velocity_y, grenade.velocity_z);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// General Commands ---------------------------------
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <vector>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define _crt_va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
|
||||||
|
#define _crt_va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
|
||||||
|
#define _crt_va_end(ap) ( ap = (va_list)0 )
|
||||||
|
|
||||||
|
#define va_start _crt_va_start
|
||||||
|
#define va_arg _crt_va_arg
|
||||||
|
#define va_end _crt_va_end
|
||||||
|
const char* conSprintf(SimObject *obj, S32 argc, const char* argv[])
|
||||||
|
{
|
||||||
|
std::vector<const char*> input;
|
||||||
|
for (unsigned int i = 2; i < argc; i++)
|
||||||
|
input.push_back(argv[i]);
|
||||||
|
|
||||||
|
char result[256];
|
||||||
|
|
||||||
|
va_list variable_args = reinterpret_cast<va_list>(input.data());
|
||||||
|
//variable_args = (va_list)_ADDRESSOF(variable_args) + _INTSIZEOF(input.size() * 4);
|
||||||
|
vsprintf(result, argv[1], variable_args);
|
||||||
|
//va_end(variable_args);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue