Sign in to follow this  
Viking

Return an array

Recommended Posts

Hey guys,

 

i am currently playing around with the plugins and try to write one myself.

(Warning c/c++ language noob xD)

 

Can you tell me how to return an array created inside a plugin to cod4?

Like in gsc sth like...

array = [];
array = plugin_function_name();

 

And inside the plugin (e.g.)

void plugin_function_name()
{
	int integer_array[999];
	
	//array filled with values
	integer_array[0] = 0;
	integer_array[1] = 1;
	//and so on

	//and how do i return that to cod4 now?
	Plugin_Scr_Add...
}

 

 

Thanks in advance.

Share this post


Link to post
Share on other sites
Plugin_Scr_MakeArray(); // init the array

for( i = 0; i < integer_array_size; i++ )
{
	Plugin_Scr_AddInt( integer_array[i] ); // add the value
	Plugin_Scr_AddArray(); // push onto the array
}

Should be like that IIRC. example

Share this post


Link to post
Share on other sites

Quite old topic, but it's still about this.

 

How would the example look like, when i have an array inside an array?

E.g. a simple list holding the spawns. (not sure if this example is accurate, but i think you get what i need)

struct spawns
{
	float origin[3];
	short id;
	char type[1024];
};

The origin would be a "subarray" of the array spawns, but how can i send that to cod4 now?

Plugin_Scr_MakeArray(); // init the array

for( i = 0; i < spawns_array_size; i++ )
{
	Plugin_Scr_Add????( spawns_array[i] ); // add the value
	Plugin_Scr_AddArray(); // push onto the array
}

These array functions are really hard to understand :D

I also found Plugin_Scr_AddArrayKeys but couldn't find an explanation for it.

 

Share this post


Link to post
Share on other sites
Plugin_Scr_MakeArray(); // init the array

for( i = 0; i < array_size; i++ )
{
	Plugin_Scr_MakeArray() // init the subarray
	ADD_XXX( value1 ); // add the value 1
	Plugin_Scr_AddArray(); // push the value 1 onto the subarray
	ADD_XXX( value2 ); // add the value 2
	Plugin_Scr_AddArray(); // push the value 2 onto the subarray 
	...
	Plugin_Scr_AddArray(); // push the subarray onto the array 
}

Where the ADD_XXX is one of these.

 

If you want a string index instead of a number you must use

Plugin_Scr_AddArrayStringIndexed( Plugin_Scr_AllocString( name ) ); // name -> const char*

instead of Plugin_Scr_AddArray().

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this