Liberty Unleashed
Scripting => Script Help => Topic started by: Shadow. on July 13, 2012, 10:35:25 pm
-
I've been trying and thinking on how to make a module that messages "hello world" ingame to all players, but I obviously fail at it, here is my C file ( as the headers and other requested files are included )
NOTE: 1. I've been seeking help on IRC but it seems I am too annoying for this comunity with my obvious annoying PMs.
2. I know this is not a place to request C++ Help.
#include "SQFuncs.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
#include <sqstdaux.h>
#include <sqstdio.h>
#ifdef SQUNICODE
#define scvprintf vwprintf
#else
#define scvprintf vprintf
#endif
extern SQAPI sq;
//_SQUIRRELDEF( MessagePeople )
//{
/*SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);*/
// char phat [] = "hello world";
//sq->pushstring( v, _SC(" Message(phat) "), -1 );
//sq->call( v, _SC("Message(phat) "), true, true );
//sq->call( v, _SC("Message(phat); "), true, true );
// return SQ_OK;
//}
_SQUIRRELDEF( HelloSquirrel )
{
sq->pushstring( v, _SC( "Hello Squirrel Module!" ), -1 );
return 1; /* return 0 indicates the Squirrel function does not return a value, 1 returns a value */
}
_SQUIRRELDEF( Sum )
{
SQInteger iArgCount = sq->gettop( v ); /* Get the argument count */
if ( iArgCount == 3 ) /* Argument count = 2 arguments + root table = 3 */
{
SQInteger i1 = 0, i2 = 0;
sq->getinteger( v, 2, &i1 ); /* Get argument 1 in slot 2 to 'i1' */
sq->getinteger( v, 3, &i2 ); /* Get argument 2 in slot 3 to 'i2' */
sq->pushinteger( v, i1 + i2 ); /* Return the sum of these two numbers */
return 1;
}
sq->pushbool( v, SQFalse );
return 1;
}
void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
{
va_list arglist;
va_start(arglist, s);
scvprintf(s, arglist);
va_end(arglist);
}
void call_Message(HSQUIRRELVM v, const SQChar *s)
{
int top = sq->gettop(v); //saves the stack size before the call
sq->pushroottable(v); //pushes the global table
sq->pushstring(v,_SC("Message"),-1);
if(SQ_SUCCEEDED(sq->get(v,-2))) { //gets the field 'foo' from the global table
sq->pushroottable(v); //push the 'this' (in this case is the global table)
sq->pushstring(v,s,-1);
sq->call(v,2,0,0); //calls the function
}
sq->settop(v,top); //restores the original stack size
}
int main(int argc, char* argv[])
{
HSQUIRRELVM v;
v = sq->open(1024); // creates a VM with initial stack size 1024
// sq->seterrorhandlers(v);
sq->setprintfunc(v, printfunc, NULL); //sets the print function
sq->pushroottable(v); //push the root table(were the globals of the script will be stored)
// if(SQ_SUCCEEDED(sq->dofile(v, _SC("SRPGv0.1.nut"), 0, 1))) // also prints syntax errors if any
// {
call_Message(v,_SC("teststring"));
// }
sq->pop(v,1); //pops the root table
sq->close(v);
return 0;
}
SQInteger RegisterSquirrelFunc( HSQUIRRELVM v, SQFUNCTION f, const SQChar* fname, unsigned char ucParams, const SQChar* szParams )
{
char szNewParams[ 32 ];
sq->pushroottable( v );
sq->pushstring( v, fname, -1 );
sq->newclosure( v, f, 0 ); /* create a new function */
if ( ucParams > 0 )
{
ucParams++; /* This is to compensate for the root table */
sprintf( szNewParams, "t%s", szParams );
sq->setparamscheck( v, ucParams, szNewParams ); /* Add a param type check */
}
sq->setnativeclosurename( v, -1, fname );
sq->newslot( v, -3, SQFalse );
sq->pop( v, 1 ); /* pops the root table */
return 0;
}
void RegisterFuncs( HSQUIRRELVM v )
{
/* Add your Squirrel functions here */
RegisterSquirrelFunc( v, HelloSquirrel, "Hello", 0, 0 );
RegisterSquirrelFunc( v, Sum, "Sum", 2, "ii" );
//RegisterSquirrelFunc( v, MessagePeople, "MessagePeople", NULL, NULL );
}
-
Why make it so complicated?
Why use C++ to have it work with SQ? That seems like too many extra steps.
Jest make a simple script snippet thatll do this for you and other users as they join and add it to your main.nut file.
It much easier & less work.
-
I want to learn from it, but it seems no one knows C++ in this comunity ( or does not want to answer ) ::)
-
hola yo si se de C++ y te puedo ayudar en esos problemas
pero tu me ayudas en el script que eso no se
-
I want to learn from it, but it seems no one knows C++ in this comunity ( or does not want to answer ) ::)
There are people here that know C++. LU itself is coded in it. ;)
-
I want to learn from it, but it seems no one knows C++ in this comunity ( or does not want to answer ) ::)
There are people here that know C++. LU itself is coded in it. ;)
Why bump a topic from "July 13, 2012, 07:35:25" ? I already solved it, like, 5 mins after my last post ?
-
I want to learn from it, but it seems no one knows C++ in this comunity ( or does not want to answer ) ::)
There are people here that know C++. LU itself is coded in it. ;)
Why bump a topic from "July 13, 2012, 07:35:25" ? I already solved it, like, 5 mins after my last post ?
Look at the date of the post before me.
-
WHY BUMP IT? I didn't post before you, get your facts right and stop making non-logical excuses.
-
WHY BUMP IT? I didn't post before you, get your facts right and stop making non-logical excuses.
Look at the post above SugarD, lol...
Sure, He might've quoted your post. But he wasn't the one who started bumping..
-
WHY BUMP IT? I didn't post before you, get your facts right and stop making non-logical excuses.
If you keep up the negative attitude, you will be forum banned. I have warned you several times already to stop picking fights with people.