Posts: 160
Threads: 31
Joined: Oct 2011
Thanks: 0
Given 0 thank(s) in 0 post(s)
11-08-2011, 11:30 AM
(This post was last modified: 11-08-2011, 11:31 AM by rs2k.)
Here's an example in cChicken.cpp
Code: if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
20% chance to drop an egg and 100% chance to drop a feather. Both can happen at the same time. After you run Pickup->Initialize( GetWorld() ); you can create the object again.
Posts: 372
Threads: 29
Joined: Mar 2011
Thanks: 1
Given 21 thank(s) in 18 post(s)
11-08-2011, 11:36 AM
(This post was last modified: 11-08-2011, 11:37 AM by ThuGie.)
Weird..
When i do 2 times without the if 2 pickup i get a error.
Edit:
Code: void cCavespider::KilledBy( cEntity* a_Killer )
{
//0 to 1 spider eye - 1.9 pre2
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_SPIDER_EYE, (rand() % 1) ) );
Pickup->Initialize( GetWorld() );
//0 to 2 string.
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_STRING, (rand() % 3) ) );
Pickup->Initialize( GetWorld() );
cMonster::KilledBy( a_Killer );
}
Like this i get a error also when i only do once pickup->init
Also not actually dropping the spider eye just a sample.
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
11-08-2011, 11:43 AM
(This post was last modified: 11-08-2011, 11:44 AM by FakeTruth.)
(rand() % 3) ranges between 0 and 2, if you want a value between 1 and 2, use (rand()%2+1)
Also, you're declaring the same variable twice (illegal)
Posts: 16
Threads: 3
Joined: Nov 2011
Thanks: 1
Given 0 thank(s) in 0 post(s)
Variable scope issues perhaps. Enclosing the individual cPickup* Pickup ensures there's no overlap.
Code: void cCavespider::KilledBy( cEntity* a_Killer )
{
{
//0 to 1 spider eye - 1.9 pre2
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_SPIDER_EYE, (rand() % 1) ) );
Pickup->Initialize( GetWorld() );
}
{
//0 to 2 string.
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_STRING, (rand() % 3) ) );
Pickup->Initialize( GetWorld() );
}
cMonster::KilledBy( a_Killer );
}
Posts: 160
Threads: 31
Joined: Oct 2011
Thanks: 0
Given 0 thank(s) in 0 post(s)
I'm compiling it now. It's been going for 10 minutes now. Not quite sure what to do after Squirrel is compiled though. lol
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
I think there's a bug in the makefile that makes it loop So I don't think it's gonna finish any time soon. Anyway, the squirrel library compiles, but try to compile SquirrelBindings.cpp in the /source folder and it should give you those errors
Posts: 160
Threads: 31
Joined: Oct 2011
Thanks: 0
Given 0 thank(s) in 0 post(s)
After changing the makefile to include squirrel_3_0_1_stable/sqplus/, I'm getting these errors:
Code: /usr/bin/g++ -msse4 -O2 -s source/cPluginManager.cpp -c -I. -Isource -Isquirrel_3_0_1_stable/ -Isquirrel_3_0_1_stable/include -Isource/md5 -IWebServer -Isource/packets -Itolua++-1.0.93/src/lib -Ilua-5.1.4/src -Izlib-1.2.5 -IiniFile -Itolua++-1.0.93/include -Ijsoncpp-src-0.5.0/include -Ijsoncpp-src-0.5.0/src/lib_json -o build/cPluginManager.o
In file included from source/cPluginManager.cpp:16:
squirrel_3_0_1_stable/sqplus/sqplus.h: In function âvoid SqPlus::createTableSetGetHandlers(SquirrelObject&)â:
squirrel_3_0_1_stable/sqplus/sqplus.h:553: error: invalid conversion from âint (*)(SQVM*)â to âSQInteger (*)(SQVM*)â
squirrel_3_0_1_stable/sqplus/sqplus.h:553: error: initializing argument 2 of âstatic SquirrelObject SquirrelVM::CreateFunction(SquirrelObject&, SQInteger (*)(SQVM*), const SQChar*, const SQChar*)â
squirrel_3_0_1_stable/sqplus/sqplus.h:554: error: invalid conversion from âint (*)(SQVM*)â to âSQInteger (*)(SQVM*)â
squirrel_3_0_1_stable/sqplus/sqplus.h:554: error: initializing argument 2 of âstatic SquirrelObject SquirrelVM::CreateFunction(SquirrelObject&, SQInteger (*)(SQVM*), const SQChar*, const SQChar*)â
squirrel_3_0_1_stable/sqplus/sqplus.h: In function âvoid SqPlus::createInstanceSetGetHandlers(SquirrelObject&)â:
squirrel_3_0_1_stable/sqplus/sqplus.h:584: error: invalid conversion from âint (*)(SQVM*)â to âSQInteger (*)(SQVM*)â
squirrel_3_0_1_stable/sqplus/sqplus.h:584: error: initializing argument 2 of âstatic SquirrelObject SquirrelVM::CreateFunction(SquirrelObject&, SQInteger (*)(SQVM*), const SQChar*, const SQChar*)â
squirrel_3_0_1_stable/sqplus/sqplus.h:585: error: invalid conversion from âint (*)(SQVM*)â to âSQInteger (*)(SQVM*)â
squirrel_3_0_1_stable/sqplus/sqplus.h:585: error: initializing argument 2 of âstatic SquirrelObject SquirrelVM::CreateFunction(SquirrelObject&, SQInteger (*)(SQVM*), const SQChar*, const SQChar*)â
In file included from squirrel_3_0_1_stable/sqplus/sqplus.h:886,
from source/cPluginManager.cpp:16:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h: In function âchar SqPlus::Get(SqPlus::TypeWrapper<char>, SQVM*, int)â:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h:60: error: cannot convert âINT*â to âSQInteger*â for argument â3â to âSQRESULT sq_getinteger(SQVM*, SQInteger, SQInteger*)â
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h: In function âunsigned char SqPlus::Get(SqPlus::TypeWrapper<unsigned char>, SQVM*, int)â:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h:61: error: cannot convert âINT*â to âSQInteger*â for argument â3â to âSQRESULT sq_getinteger(SQVM*, SQInteger, SQInteger*)â
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h: In function âshort int SqPlus::Get(SqPlus::TypeWrapper<short int>, SQVM*, int)â:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h:62: error: cannot convert âINT*â to âSQInteger*â for argument â3â to âSQRESULT sq_getinteger(SQVM*, SQInteger, SQInteger*)â
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h: In function âshort unsigned int SqPlus::Get(SqPlus::TypeWrapper<short unsigned int>, SQVM*, int)â:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h:63: error: cannot convert âINT*â to âSQInteger*â for argument â3â to âSQRESULT sq_getinteger(SQVM*, SQInteger, SQInteger*)â
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h: In function âint SqPlus::Get(SqPlus::TypeWrapper<int>, SQVM*, int)â:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h:64: error: cannot convert âINT*â to âSQInteger*â for argument â3â to âSQRESULT sq_getinteger(SQVM*, SQInteger, SQInteger*)â
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h: In function âunsigned int SqPlus::Get(SqPlus::TypeWrapper<unsigned int>, SQVM*, int)â:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h:65: error: cannot convert âINT*â to âSQInteger*â for argument â3â to âSQRESULT sq_getinteger(SQVM*, SQInteger, SQInteger*)â
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h: In function âlong int SqPlus::Get(SqPlus::TypeWrapper<long int>, SQVM*, int)â:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h:66: error: cannot convert âINT*â to âSQInteger*â for argument â3â to âSQRESULT sq_getinteger(SQVM*, SQInteger, SQInteger*)â
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h: In function âlong unsigned int SqPlus::Get(SqPlus::TypeWrapper<long unsigned int>, SQVM*, int)â:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h:67: error: cannot convert âINT*â to âSQInteger*â for argument â3â to âSQRESULT sq_getinteger(SQVM*, SQInteger, SQInteger*)â
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h: In function âbool SqPlus::Get(SqPlus::TypeWrapper<bool>, SQVM*, int)â:
squirrel_3_0_1_stable/sqplus/SqPlusFunctionCallImpl.h:80: error: cannot convert âINT*â to âSQInteger*â for argument â3â to âSQRESULT sq_getinteger(SQVM*, SQInteger, SQInteger*)â
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
Funky â's everywhere, what's up with that
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
Since this thread has pretty much derailed into discussing development of MCServer, I've moved it
Posts: 372
Threads: 29
Joined: Mar 2011
Thanks: 1
Given 21 thank(s) in 18 post(s)
Weird this code should work right ?
Code: void cCow::KilledBy( cEntity* a_Killer )
{
//1 to 3 raw beef.
int rRawBeef = rand() % 1 + 3;
if (rRawBeef != 0) {
cPickup* pRawBeef = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_RAW_BEEF, rRawBeef ) );
pRawBeef->Initialize( GetWorld() );
}
//0 to 2 leather.
int rLeather = rand() % 3;
if (rLeather != 0) {
cPickup* pLeather = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_LEATHER, rLeather ) );
pLeather->Initialize( GetWorld() );
}
cMonster::KilledBy( a_Killer );
}
Still it crashes the client when i kill a cow.
|