Raised This Month: $51 Target: $400
 12% 

Extension Help [CS:S PlayerDeath]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ajaxx
Senior Member
Join Date: Oct 2009
Old 02-19-2014 , 18:43   Extension Help [CS:S PlayerDeath]
Reply With Quote #1

I have a method in my SM extension that I would like executed on the PlayerDeath event. I would like to return multiple values, a bool a string and an int, to my SM plugin from this call. Would this be a Forward or a Native?

I’m having a little difficulty with the structure for my extension. I’m using the example from the SDK. I seem to have some disconnect about whether the plugin calls the extension or the extension calls the plugin. Can someone give me an example of what should be in extension.h, extension.cpp, sample.inc, and sample.sp for the above to work?
Ajaxx is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 02-20-2014 , 11:25   Re: Extension Help [CS:S PlayerDeath]
Reply With Quote #2

Wrong section...
WildCard65 is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 02-20-2014 , 12:32   Re: Extension Help [CS:S PlayerDeath]
Reply With Quote #3

My apologies, thanks for pointing this out. Which section do you suggest is the appropriate home for a post like this? SourceMod/General?
Ajaxx is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 02-20-2014 , 13:29   Re: Extension Help [CS:S PlayerDeath]
Reply With Quote #4

Scripting section under sourcemod possibly or some other one.

Last edited by WildCard65; 02-20-2014 at 13:30.
WildCard65 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-20-2014 , 14:11   Re: Extension Help [CS:S PlayerDeath]
Reply With Quote #5

The MM:S C++ Coding forum is probably the best place for extension help. I'll move it there now.

Anyways, natives are functions that your extension can implement that can be called by plugins. Forwards are for calling plugin functions from the extension.

More info on these can be found at https://wiki.alliedmods.net/Writing_Extensions
psychonic is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 02-27-2014 , 00:13   Re: Extension Help [CS:S PlayerDeath]
Reply With Quote #6

I have a native that I'm trying to call from my plugin. The plugin is failing with

Code:
Load error: Native "OnPlayerDeath" was not found
I feel like I'm missing something simple. Can someone point me in the right direction please?


ultra.sp:
Code:
#include <sourcemod>
#include <ultra>
 
public Plugin:myinfo =
{
	name = "",
	author = "Ajaxx",
	description = "SourceMod Plugin",
	version = "1.0",
	url = ""
};
 
public OnPluginStart()
{
	HookEvent("player_death", Event_PlayerDeath)
}

public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
	new String:weapon[64]
	GetEventString(event, "weapon", weapon, sizeof(weapon))

	new victim_id = GetEventInt(event, "userid")
	new attacker_id = GetEventInt(event, "attacker")
 
	new victim = GetClientOfUserId(victim_id)
	new attacker = GetClientOfUserId(attacker_id)

	new String:message[6];
	new result = OnPlayerDeath(message);
 
	if(result)
	{
		PrintToChat(attacker, message);
	}
}

ultra.inc:
Code:
native bool:OnPlayerDeath(String:text[]);

extension.cpp:
Code:
#include "extension.h"

Ultra g_Ultra;

SMEXT_LINK(&g_Ultra);

cell_t Native_OnPlayerDeath(IPluginContext *pContext, const cell_t *params)
{
	char* text;
	pContext->LocalToString(params[1], &text);

	text = "Stuff";

	return true;
}

const sp_nativeinfo_t ultra_natives[] =
{
	{ "OnPlayerDeath", Native_OnPlayerDeath },
	{ NULL, NULL },
};

void Ultra::SDK_OnAllLoaded()
{
	sharesys->AddNatives(myself, ultra_natives);
}
Ajaxx is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-27-2014 , 10:21   Re: Extension Help [CS:S PlayerDeath]
Reply With Quote #7

Have you verified with "sm exts list" that the extension is getting loaded?

For it to automatically get loaded when a plugin that uses it is loaded, you'll need to add the Extension struct to your inc file. Example from SDKTools:
Code:
public Extension:__ext_sdktools = 
{
    name = "SDKTools",
    file = "sdktools.ext",
#if defined AUTOLOAD_EXTENSIONS
    autoload = 1,
#else
    autoload = 0,
#endif
#if defined REQUIRE_EXTENSIONS
    required = 1,
#else
    required = 0,
#endif
};
That said, you can post-hook events directly in extensions pretty easily by adding an event listener with the IGameEventsManager2 interface in the sdk.
psychonic is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 02-28-2014 , 15:52   Re: Extension Help [CS:S PlayerDeath]
Reply With Quote #8

I added the struct, thanks for that. When I list the extensions “sm exts list” I get:

Code:
<FAILED > file “ultra.ext.dll”: Extension version is too new to load (7, max is 5)
It seems like a pretty straight forward message, but I can’t figure it out. In smsdk_config.h SMEXT_CONF_VERSION = "1.0.0.0". I’m using SourceMod version 1.5.3 and MetaMod version 1.10.1. Where is this version mismatch coming from?
Ajaxx is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-28-2014 , 16:01   Re: Extension Help [CS:S PlayerDeath]
Reply With Quote #9

Quote:
Originally Posted by Ajaxx View Post
I added the struct, thanks for that. When I list the extensions “sm exts list” I get:

Code:
<FAILED > file “ultra.ext.dll”: Extension version is too new to load (7, max is 5)
It seems like a pretty straight forward message, but I can’t figure it out. In smsdk_config.h SMEXT_CONF_VERSION = "1.0.0.0". I’m using SourceMod version 1.5.3 and MetaMod version 1.10.1. Where is this version mismatch coming from?
You're getting that because you're compiling against sourcemod_central and then trying to run it on SourceMod 1.5.x. SourceMod uses a newer extension version in SourceMod 1.6 (which is what Central is).

The fix is to compile it against releases/sourcemod-1.5 instead.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 02-28-2014 at 16:02.
Powerlord is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 02-28-2014 , 16:25   Re: Extension Help [CS:S PlayerDeath]
Reply With Quote #10

That was exactly it, thank you.
Ajaxx 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:56.


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