Raised This Month: $ Target: $400
 0% 

[Orpheu] Structs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
teh ORiON
Member
Join Date: Sep 2011
Location: Denmark
Old 09-13-2015 , 22:04   [Orpheu] Structs
Reply With Quote #1

Hi,

Im messing a bit with CBaseMonster, and I want to try and make tasks and schedules in pawn and pass them.

Im trying to make this atm as an example from CHeadCrab:

CHeadCrab


And I've got this translated to this in pawn:

Pawn


This works sort of, problem is that only the first task gets run. Is there a way I can make this work?
__________________
CTFGasGrenade :: GasThePlace(void)
teh ORiON is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 09-24-2015 , 15:13   Re: [Orpheu] Structs
Reply With Quote #2

Schedule_t struct needs contiguous array of Task structures. What you are doing is, you are making a "cell" array of "OrpheuStructure" handles and trying to pass it to Schedule_t struct. tlHCRangeAttack1 is a mere array of OrpheuStructure Handles (in fact, they are pointers to the allocated structs in memory pool) which reference to random memory segments (non contiguous).

Orpheu deals with structures good enough but lacks control for arrays of structures. So to pack these non contiguous stucts, i added a native OrpheuPackStructures to latest version of Orpheu. Use that to get pointer to packed structure array and pass it to Schedule struct, like,

PHP Code:
static OrpheuStruct:tlHCRangeAttack1[6
static 
OrpheuStruct:slHCRangeAttack1 

tlHCRangeAttack1
[0] = OrpheuCreateStruct(OrpheuStructTask)     
OrpheuSetStructMember(tlHCRangeAttack1[0], "iTask"TASK_STOP_MOVING
OrpheuSetStructMember(tlHCRangeAttack1[0], "flData"0.0)     
     
tlHCRangeAttack1[1] = OrpheuCreateStruct(OrpheuStructTask
OrpheuSetStructMember(tlHCRangeAttack1[1], "iTask"TASK_FACE_IDEAL
OrpheuSetStructMember(tlHCRangeAttack1[1], "flData"0.0
     
tlHCRangeAttack1[2] = OrpheuCreateStruct(OrpheuStructTask
OrpheuSetStructMember(tlHCRangeAttack1[2], "iTask"TASK_RANGE_ATTACK1
OrpheuSetStructMember(tlHCRangeAttack1[2], "flData"0.0
     
tlHCRangeAttack1[3] = OrpheuCreateStruct(OrpheuStructTask
OrpheuSetStructMember(tlHCRangeAttack1[3], "iTask"TASK_SET_ACTIVITY
OrpheuSetStructMember(tlHCRangeAttack1[3], "flData"1.0
     
tlHCRangeAttack1[4] = OrpheuCreateStruct(OrpheuStructTask
OrpheuSetStructMember(tlHCRangeAttack1[4], "iTask"TASK_FACE_IDEAL
OrpheuSetStructMember(tlHCRangeAttack1[4], "flData"0.0
     
tlHCRangeAttack1[5] = OrpheuCreateStruct(OrpheuStructTask
OrpheuSetStructMember(tlHCRangeAttack1[5], "iTask"TASK_WAIT_RANDOM
OrpheuSetStructMember(tlHCRangeAttack1[5], "flData"0.5

new 
OrpheuStruct:iHCPackPointer OrpheuPackStructurestlHCRangeAttack1);

slHCRangeAttack1 OrpheuCreateStruct(OrpheuStructSchedule
OrpheuSetStructMember(slHCRangeAttack1"pTasklist"iHCPackPointer
OrpheuSetStructMember(slHCRangeAttack1"cTasks"sizeof(tlHCRangeAttack1)) 
OrpheuSetStructMember(slHCRangeAttack1"iInterruptMask"bits_COND_ENEMY_OCCLUDED bits_COND_NO_AMMO_LOADED
OrpheuSetStructMember(slHCRangeAttack1"iSoundMask"0
OrpheuSetStructMember(slHCRangeAttack1"pName""HCRangeAttack1"


public 
OrpheuHookReturn:GetScheduleOfType(iMonsteriType

    switch ( 
iType 
    { 
        case 
SCHED_RANGE_ATTACK1
        { 
            
OrpheuSetReturn(slHCRangeAttack1
            return 
OrpheuOverride 
        

    } 
    return 
OrpheuIgnored 

In brief, OrpheuPackStructures will transform all the structs into a single contiguous Structure Array.

TIP: HACKY,
Now if you want to test whether all the structs passed are aligned correctly, use the handle returned with incremented offset of sizeof(tlHCRangeAttack1[1]) means sizeof(TaskStruct) = 8, like,

PHP Code:
new OrpheuStruct:taskStruct;

for( new 
i=06*8i+=)
{
    
taskStruct OrpheuGetStructFromAddress(OrpheuStructTask_:iHCPackPointer+i)
    
log_amx"%d. iHCPackPointer: %x"i_:iHCPackPointer+)
    
log_amx"iTask: %i"OrpheuGetStructMember(taskStruct"iTask") )

__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King is offline
teh ORiON
Member
Join Date: Sep 2011
Location: Denmark
Old 09-24-2015 , 15:36   Re: [Orpheu] Structs
Reply With Quote #3

Tested and works perfectly. This should probably be folded into the official orpheu, as it's useful for those who wants to, in this instance, change monster's default behavior.
__________________
CTFGasGrenade :: GasThePlace(void)

Last edited by teh ORiON; 09-24-2015 at 15:36.
teh ORiON is offline
teh ORiON
Member
Join Date: Sep 2011
Location: Denmark
Old 03-01-2016 , 08:56   Re: [Orpheu] Structs
Reply With Quote #4

Any chance of having this added to Orpheu Arkshine? If you have time ~.
__________________
CTFGasGrenade :: GasThePlace(void)
teh ORiON is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode