Show Posts
|
Pages: 1 ... 8 9 [10]
|
136
|
Scripting / Script Help / [C++] I need some help regarding C++ -> SQ modules
|
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 ); }
|
|
|
138
|
Scripting / Script Help / Re: Error.. error.. error..
|
on: July 04, 2012, 10:30:56 am
|
Well simple, I moved the code by the beginning of the callback and changed all sqlite_column_data(sqlite_query(database,"SELECT BLAH FROM LAG WHERE NAME='"+player.Name.toupper()"' "),0); sqlite_column_data(sqlite_query(database,"SELECT BLAH1 FROM LAG WHERE NAME='"+player.Name.toupper()"' "),0); sqlite_column_data(sqlite_query(database,"SELECT BLAH2 FROM LAG WHERE NAME='"+player.Name.toupper()"' "),0);
to local q = sqlite_query(database,SELECT BLAH, BLAH1, BLAH2 FROM LAG WHERE NAME='"+player.Name.toupper()+"' LIMIT 1");
local blah1 = sqlite_column_data( q, 0 ); local blah2 = sqlite_column_data( q, 1 ); local blah3 = sqlite_column_data( q, 2 );
|
|
|
139
|
Scripting / Script Help / Re: Error.. error.. error..
|
on: July 03, 2012, 09:49:07 pm
|
Player.Pos = string. Why do you even use "type of" if it's already working with the simple one!...? And then arguing about that!
I wonder if you ever know what you are talking Also, I solved it. NVM, put it on top of the script then changed 30 queries into 10 :p
|
|
|
140
|
Scripting / Script Help / Re: Error.. error.. error..
|
on: July 03, 2012, 07:38:58 pm
|
1st : print( typeof( player ) ); = Player 2nd : print( typeof( player.Pos ) ); = string
EDIT 1st: if I /exec the 2nd, it returns Vector. lol... EDIT 2nd: I printed player.Pos at onplayerspawn, it prints " Pos " LOL
|
|
|
142
|
Scripting / Script Help / Re: Error.. error.. error..
|
on: July 03, 2012, 05:19:00 pm
|
Also, Your usage of sqlite is the worst I've ever seen. Querying the database for every x,y,z is as bad as it can get... Just query once, and get all the data you need from it...
@ Thijn: Hey mr obvious, it is not. It's the SINGLE query that is supposed to return a float, and there is not a point to put it in a class, because ( obvious ) I use it just once. passwords, admin level, LCPD Sub-divisions level & other things are obviously stored in a class. But, of course you just come on and spit it, no point to actually ask. @VRocker: tried, same thing @VetalYA: tried, same thing Thanks for the help, I will try few tweaks to see if I can do it.
|
|
|
143
|
Scripting / Script Help / Re: Error.. error.. error..
|
on: July 02, 2012, 11:11:06 pm
|
Look at the code and the pic local x = sqlite_column_data(sqlite_query(database, "SELECT X FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0); local y = sqlite_column_data(sqlite_query(database, "SELECT Y FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0); local z = sqlite_column_data(sqlite_query(database, "SELECT Z FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0); //local hp = sqlite_column_data(sqlite_query(database, "SELECT Health FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' "),0); //local ar = sqlite_column_data(sqlite_query(database, "SELECT Armour FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' "),0); //player.Health = hp.tointeger(); //player.Armour = ar.tointeger(); print( "Vector(" + x + "," + y + "," + z + ");" ); player.Pos = Vector( x, y, z );
|
|
|
145
|
Scripting / Script Help / Error.. error.. error..
|
on: July 02, 2012, 06:24:15 pm
|
So, I have been thinking about this system that loads up previous player position from SQLite database, and sets you there, but I encounter an error.
function PrecachePosition(player) { player.Skin = sqlite_column_data(sqlite_query(database, "SELECT Skin FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0); /* local x = sqlite_column_data(sqlite_query(database, "SELECT * FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),1); local y = sqlite_column_data(sqlite_query(database, "SELECT * FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),2); local z = sqlite_column_data(sqlite_query(database, "SELECT * FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),3);*/ local wep = sqlite_column_data(sqlite_query(database, "SELECT Wep FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0); local ammo = sqlite_column_data(sqlite_query(database, "SELECT Ammo FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0); player.SetWeapon( wep, ammo ); player.Frozen = false; player.Pos = Vector( sqlite_column_data(sqlite_query(database, "SELECT X FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Y FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Z FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0) ); }
1.YES the data exists 2.YES the data is in FLOAT format 3.YES the data is valid 4.YES the data is in NUMERIC.NUMERIC format ( FLOAT ) 5.YES the data is saved at onPlayerPart(player,partreason) 6.YES I tried to get the exact data and put '.tofloat()' after it 7.The line with the error is surprisingly
player.Pos = Vector( sqlite_column_data(sqlite_query(database, "SELECT X FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Y FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0), sqlite_column_data(sqlite_query(database, "SELECT Z FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0) );
Yes I also tried this code
local x = sqlite_column_data(sqlite_query(database, "SELECT X FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0); local y = sqlite_column_data(sqlite_query(database, "SELECT Y FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0); local z = sqlite_column_data(sqlite_query(database, "SELECT Z FROM LASTLOGIN WHERE Name='"+player.Name.toupper()+"' " ),0); player.Pos = Vector( x.tofloat(), y.tofloat(), z.tofloat() );
also, when I make a class and default all the datas to null, then try to set them to 1, I receive a '' trying to set 'null ''
DO NOT COPY THIS CODE PLEASE
|
|
|
146
|
Servers / Advertise your server! / Kyprix Project Server
|
on: June 25, 2012, 04:22:19 pm
|
Information
IP: 94.23.157.172:2322 Host: VRocker's Machines Location: France, EU Gamemode: Roleplay
Current scripting team Head Developer [VU]Shadow (me)
Developers
Vortrex X_94 a.k.a Nexus
|
|
|
|