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

Function Calling API assistance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ibanezez
SourceMod Donor
Join Date: Aug 2014
Location: Earth
Old 10-04-2014 , 11:41   Function Calling API assistance
Reply With Quote #1

I'm not entirely understanding the Function Calling API area of sourcemod.
If I had a plugin like this:
PHP Code:
#include <sourcemod>

public OnPluginStart()
{
    
RegAdminCmd("sm_hello"commandHelloADMFLAG_GENERIC"Print to Chat Hello!);
}

public OnClientPutInServer(client)
{
    public Action:commandHello(client, args)
    {
        PrintToChat(client, "
Hello!");
        return Plugin_Handled;
    }

How could I make the:
public OnClientPutInServer(client)
{
public Action:commandhello(client, args)
}
be possible?
I tried using the alliedmods wiki, but with no success. Could someone explain to me how this works, and give an example of what it would look like in this plugin? ^^^^^^^^^^

(I may be wrong about what Function Calling API does, if so, please let me know. )
__________________
Hello
Ibanezez is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 10-04-2014 , 19:14   Re: Function Calling API assistance
Reply With Quote #2

Code:
#include <sourcemod> 

public OnPluginStart() 
{ 
    RegAdminCmd("sm_hello", commandHello, ADMFLAG_GENERIC, "Print to Chat Hello!); 
} 

public OnClientPutInServer(client) 
{ 
	SayHello(client);
}

public Action:commandHello(client, args)
{
	SayHello(client);
	return Plugin_Handled;
}

SayHello(client)
{
	ReplyToCommand(client, "Hello!");
}
I'm assuming you're referring to a stock function so.
Drixevel is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 10-04-2014 , 19:38   Re: Function Calling API assistance
Reply With Quote #3

From what you were trying to do inside the original post, I believe this is what you are looking for.

PHP Code:
#include <sourcemod>

public OnPluginStart()
{
    
RegAdminCmd("sm_hello"Command_Hello0"Greets the client.");
}

public 
OnClientPutInServer(iClient)
{
    
Command_Hello(iClient0);
}

public 
Action:Command_Hello(iClientiArgs)
{
    
PrintToChat(iClient"Hello %N!"iClient);

    return 
Plugin_Handled;

Marcus_Brown001 is offline
Ibanezez
SourceMod Donor
Join Date: Aug 2014
Location: Earth
Old 10-04-2014 , 19:53   Re: Function Calling API assistance
Reply With Quote #4

A bit more complicated, but how would I do it with something like this:
PHP Code:
#include <sourcemod>

public Action:OnEnteredProtectedZone(zoneclient, const String:prefix[])
{
    static 
Handle:ShowZones   INVALID_HANDLE;
    if (!
ShowZonesShowZones FindConVar("sm_zones_show_messages");

    if (
<= client <= MaxClients)
    {
        
decl String:m_iName[MAX_NAME_LENGTH*2];
        
GetEntPropString(zoneProp_Data"m_iName"m_iNamesizeof(m_iName));

        if (
StrEqual(m_iName[8], "test"false))
        {
            if (
GetConVarBool(ShowZones))
            {
                
PrintToChat(client"%sYou have entered \"%s\" zone."prefixm_iName[8]);
                
//////////////////////////////////////////////////////////////////////////////////// I WANT THE "public OnClientPutInServer(client)" section to be inside here!
            
}
        }
    }
}

public 
Action:OnLeftProtectedZone(zoneclient, const String:prefix[])
{
    static 
Handle:ShowZones   INVALID_HANDLE;
    if (!
ShowZonesShowZones FindConVar("sm_zones_show_messages");

    if (
<= client <= MaxClients)
    {
        
decl String:m_iName[MAX_NAME_LENGTH*2];
        
GetEntPropString(zoneProp_Data"m_iName"m_iNamesizeof(m_iName));

        if (
StrEqual(m_iName[8], "test"false))
        {
            if (
GetConVarBool(ShowZones) && IsPlayerAlive(client))
            {
                
PrintToChat(client"%sYou have left \"%s\" zone."prefixm_iName[8]);
                
SayHello(client);
            }
        }
    }
}

public 
OnClientPutInServer(client)
{
    
PrintToChat(client"Welcome!");
    
PrintToChat(client"Goodbye!");
    
TF2_RespawnPlayer(client)
    
    return 
Plugin_Handled;

I want the public OnClientPutInServer(client) area to be put right under the PrintToChat(client, "You have entered %s zone", a;sdfka;"); place. How would I do that?

I was thinking something like this.
I would change the public OnClientPutInServer(client) to:

public OnClientPutInServer(client, <makeupname>)

and then wherever I want the section to be, I put:

PrintToChat(client, "%sYou have entered \"%s\" zone.", prefix, m_iName[8]_;
Get(<nameimadeup>);

or something. Do you know the correct way to do this?
__________________
Hello

Last edited by Ibanezez; 10-04-2014 at 19:54.
Ibanezez is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 10-04-2014 , 20:19   Re: Function Calling API assistance
Reply With Quote #5

You would want to place the code you want run in multiple places into a stock. Then call that stock where ever you want that code ran.

Here's an example:
PHP Code:
public OnClientPutInServer(iClient)
{
    
Void_GreetClient(iClient);
}

stock Void_GreetClient(iClient)
{
    
PrintToChat(iClient"Hello %N!"iClient);
    
PrintToChat(iClient"Goodbye %N!"iClient);

Marcus_Brown001 is offline
Ibanezez
SourceMod Donor
Join Date: Aug 2014
Location: Earth
Old 10-04-2014 , 20:36   Re: Function Calling API assistance
Reply With Quote #6

This is starting to make a bit more sense.

I have a much bigger plugin where I have to put the taunt data inside that map zones plugin above. This is some of the script I need to put inside:
PHP Code:
public Action:playsound(clientargs)
{

}

public 
OnEntityCreated(entity, const String:classname[])
{

}

public 
SDKHookCB_OnSceneSpawnedPost(entity)
{

}

public 
Action:HUD(Handle:timerany:client)
{


I guess my main question is how can I put separate public actions and On<inserthere> and other things inside other commands?

Would I do something like this:
PHP Code:
public Action:HUD(Handle:timerstock:namehereany:client)
{

}

public 
Action:playsound(clientargsstock:namehere)
{

}

public 
OnEntityCreated(entity, const String:classname[], stock:namehere)
{


Would I add stock:<name> inside the parenthesis?
__________________
Hello
Ibanezez is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 10-04-2014 , 21:25   Re: Function Calling API assistance
Reply With Quote #7

No. You can create custom stocks with any parameters that you will need. With that being said, 'stock' is not a valid tag inside SourceMod (again, visit the wiki for more information). Following on that, if you add parameters into natives or default function headers that shouldn't be there the compiler will spit you an error telling you exactly that.

This is an example using the three (which turned into two) functions you posted above.
PHP Code:
public Action:HUD(Handle:hTimerany:iBuffer// This is an example of the header of a timer callback.
{
    
// When you create a timer it is considered good form to pass a client's userid or serial instead of the client's index.
    // The reason for this is in the time between when the timer is created and when the timer runs the client can leave the server, thus making that index invalid.

    
new iClient GetClientFromSerial(iBuffer); // It is my personal preference to use client serials. Userids work just as well, too.

    
SomeRandomStock(iClient);
}

// Using public when you create the function means that it can be accessed from other plugins.
// If you are not planning to use that function in multiple plugins then stock works as well.

public OnEntityCreated(entity, const String:classname[])
{
    
// This function doesn't have a client index. Sooo, I don't know what you want to do here.
}

stock SomeRandomStock(iClient// Do you need a client index inside this stock? If not, remove the iClient so it would be SomeRandomStock()
{
    
//Place the code that you want ran inside of the above functions.

I removed the middle function for a few reasons. I don't know what you want to do with it, but there are natives and includes around that allow you to play sounds to clients. I would suggest not trying to recreate a wheel, and use the natives that are inside SourceMod or use Powerlord's include: EmitSoundAny.

On a different note, you should take some time reading, rereading, and re-rereading the SourceMod wiki. Most of the answers to the questions you have asked can be found inside that wiki (recent questions including other threads you have posted as well). Also, there are so many plugins out there that you can download and look at for examples. My advice would be find someone who has the knowledge to, and doesn't mind, answering your questions. In my personal experience, one question can quickly turn into two, which turn into three, etc. Posting here is helpful in most cases, however, it can be very slow at times as well.
Marcus_Brown001 is offline
Ibanezez
SourceMod Donor
Join Date: Aug 2014
Location: Earth
Old 10-05-2014 , 12:02   Re: Function Calling API assistance
Reply With Quote #8

Okay, thanks. I'll look through the wiki and see what I find.
__________________
Hello
Ibanezez 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 01:27.


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