Raised This Month: $32 Target: $400
 8% 

SourcePawn beginner Help


Post New Thread Reply   
 
Thread Tools Display Modes
peenut
Member
Join Date: Nov 2013
Old 04-30-2017 , 15:34   Re: SourcePawn beginner Help
Reply With Quote #11

This is probably very obvious, but if you haven't checked youtube already; this series that helped me when i started. I was just as lost in the beginning but those videos helped me alot. Another good help is to look at the sourcecode for simple plugins. All plugins are required to release with source.
peenut is offline
VikingVrede
Junior Member
Join Date: Apr 2017
Old 04-30-2017 , 19:25   Re: SourcePawn beginner Help
Reply With Quote #12

Ok, assign function to variable did not know you could do that cool! Performing client checks.. Hmm i guess If statements is what you use for it? ( Im aware of code below being false, Just to show how i think rather then me trying to explain)

Code:
if IsClientInGame(int client)
	  {
	  	PrintToChat(client, "YOU HAVE %i frags.", frags);
	  }
When trying to compile code in Spedit i get error type 001 - Details:Expected ";" but found "}" ?
Looking at the sample code, i am going to explore the api a bit and try out some stuff
Quote:
Originally Posted by Kolapsicle View Post
I would recommend performing proper client checks such as IsClientInGame, but for the sake of simplicity I left it out. You could also compact the code by replacing the "frags" variable argument with GetClientFrags.

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

public void OnPluginStart()
{
    
RegConsoleCmd("sm_print"Command_Print);
}

public 
Action Command_Print(int clientint args)
{
    
int frags GetClientFrags(client);
    
PrintToChat(client"You have %i frags."frags);
    return 
Plugin_Handled;

Yes i believe i have seen some of his videos, Now when you brought that up i will have a look at it later!

Quote:
This is probably very obvious, but if you haven't checked youtube already; this series that helped me when i started. I was just as lost in the beginning but those videos helped me alot. Another good help is to look at the sourcecode for simple plugins. All plugins are required to release with source.
VikingVrede is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 04-30-2017 , 20:26   Re: SourcePawn beginner Help
Reply With Quote #13

Quote:
Originally Posted by VikingVrede View Post
-snip-
You're on the right track, you just have to wrap parenthesis around the if statement and remove that int there like this.

PHP Code:
    if (IsClientInGame(client))
    {
          
PrintToChat(client"YOU HAVE %i frags."frags);
    } 
You only have to put the "int" there if you are creating a function, not using it.

Your whole plugin can look like this

PHP Code:
#pragma semicolon 1 
#pragma newdecls required 

#include <sourcemod> 

 
public Plugin myinfo =
{
    
name "My First Plugin",
    
author "VikingVrede",
    
description "Get your frags!",
    
version "1.0",
    
url "https://forums.alliedmods.net/member.php?u=278840"
};

public 
void OnPluginStart() 

    
RegConsoleCmd("sm_frags"Command_Print); 


public 
Action Command_Print(int clientint args
{
    if (
IsClientInGame(client))
    {
        
int frags GetClientFrags(client); 
        
PrintToChat(client"You have %i frags."frags); 
    }
    
    return 
Plugin_Handled


Last edited by headline; 04-30-2017 at 20:29.
headline is offline
VikingVrede
Junior Member
Join Date: Apr 2017
Old 05-01-2017 , 12:33   Re: SourcePawn beginner Help
Reply With Quote #14

Thanks! I have now learned how to Grab values (GetFunctions)
as well as displaying them. But what about Forward functions like OnClientConnect? i want to make a client connect message.
https://sm.alliedmods.net/new-api/cl...nClientConnect
forward void bool OnClientConnect(int client); < Correct?
If i were to display player name i need to use GetClientName right and if so, looking at parameter on ( https://sm.alliedmods.net/new-api/clients/GetClientName ) I see char[]. Do i need to create a new string for name? My code looks like this at the moment
source that i've been looking at/observed ( https://wiki.alliedmods.net/Introduc...rceMod_Plugins )


if (OnClientConnect(client))
{
GetClientName(client, name, sizeof(name));
PrintToChatAll("Player %s Connected", name);
}
Quote:
Originally Posted by Headline View Post
You're on the right track, you just have to wrap parenthesis around the if statement and remove that int there like this.

PHP Code:
    if (IsClientInGame(client))
    {
          
PrintToChat(client"YOU HAVE %i frags."frags);
    } 
You only have to put the "int" there if you are creating a function, not using it.

Your whole plugin can look like this

PHP Code:
#pragma semicolon 1 
#pragma newdecls required 

#include <sourcemod> 

 
public Plugin myinfo =
{
    
name "My First Plugin",
    
author "VikingVrede",
    
description "Get your frags!",
    
version "1.0",
    
url "https://forums.alliedmods.net/member.php?u=278840"
};

public 
void OnPluginStart() 

    
RegConsoleCmd("sm_frags"Command_Print); 


public 
Action Command_Print(int clientint args
{
    if (
IsClientInGame(client))
    {
        
int frags GetClientFrags(client); 
        
PrintToChat(client"You have %i frags."frags); 
    }
    
    return 
Plugin_Handled


Last edited by VikingVrede; 05-01-2017 at 12:35.
VikingVrede is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 05-01-2017 , 14:09   Re: SourcePawn beginner Help
Reply With Quote #15


If you want to grab a players name there's two ways of doing it.

PHP Code:
char name[MAX_NAME_LENGTH];
GetClientName(clientnamesizeof(name)); 
or you can do it like this

PHP Code:
PrintToChat(client"Hello, %N"client); // %N is a shortcut for a player's name basically 
If you want to make a connect message, you should probably use OnClientPutInServer is stead of OnClientConnect. The reason is, OnClientConnect is SUPER early in their connection stage so if you were to print something to them immediately when they click the server on the browser, they'd not receive it. OnClientPutInServer is basically once they've finished downloading and have entered the game.

Also, there's a difference between forwards and natives. Forwards are like events, something that happens. Natives are like functions. If you wanted to use OnClientPutInServer, you'd have to do this. Then every time the client is put into the server they have this printed to them.

PHP Code:
public void OnClientPutInServer(int client)
{
    
PrintToChat(client"Hello, %N"client);


Last edited by headline; 05-01-2017 at 14:10.
headline is offline
B3none
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 05-01-2017 , 14:26   Re: SourcePawn beginner Help
Reply With Quote #16

The way I remember it, albeit unorthadox is just simply:

Plugin loads > Plugin waits for call (something to run code on) > Write the code that it must run.

I still have much to learn however with HookEvent I would suggest just looking how others do it, it's almost like translating something from CS:GO to pawn where you can manipulate the response...

Sorry if this was no help lol figured I would write it with as little jargon as possible since the guy is struggling
__________________
B3none is offline
VikingVrede
Junior Member
Join Date: Apr 2017
Old 05-01-2017 , 14:47   Re: SourcePawn beginner Help
Reply With Quote #17

I see, remember reading about Specifier "N" at Sourcemod scripting section. Totally forgot it even existed... Will have to read through the sourcemod scripting section again. I believe i might have missed some important information aswell
Quote:
Originally Posted by Headline View Post
If you want to grab a players name there's two ways of doing it.

PHP Code:
char name[MAX_NAME_LENGTH];
GetClientName(clientnamesizeof(name)); 
or you can do it like this

PHP Code:
PrintToChat(client"Hello, %N"client); // %N is a shortcut for a player's name basically 
If you want to make a connect message, you should probably use OnClientPutInServer is stead of OnClientConnect. The reason is, OnClientConnect is SUPER early in their connection stage so if you were to print something to them immediately when they click the server on the browser, they'd not receive it. OnClientPutInServer is basically once they've finished downloading and have entered the game.

Also, there's a difference between forwards and natives. Forwards are like events, something that happens. Natives are like functions. If you wanted to use OnClientPutInServer, you'd have to do this. Then every time the client is put into the server they have this printed to them.

PHP Code:
public void OnClientPutInServer(int client)
{
    
PrintToChat(client"Hello, %N"client);

VikingVrede 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 14:56.


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