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

SourcePawn beginner Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
VikingVrede
Junior Member
Join Date: Apr 2017
Old 04-22-2017 , 08:57   SourcePawn beginner Help
Reply With Quote #1

Hello im new to SourcePawn, and im pretty lost and confused. I have been reading Wiki page and such
but when looking at GameEvents/Functions i don't know how to put them together and actually make an plugin out of it. Example, i would like to print out a message to client once event "player_death" gets fired.

Or let's say Function " int GetClientFrags(int client) " i want to return value and somehow store it so it could be used for ex, Rank stats. I have been getting a good understanding of varibles, Strings, arrays and so on (But don't understand how to use it/situations where i want to use it). I have also been learning a bit of Python because it was recommended for "Non programmers" I can definitely see patterns when looking at SourcePawn code/Events/Functions but i just don't know how to put them together.

I really want to learn sourcepawn (I have the motivation), im a big community player from way back in 1.6 and source. I have alot of good ides and i want to make them come true and share with the Community here at Alliedmodders. I can see that c++ is also recommended knowing. Worth learning? will it give me a better picture when coding/Scripting sourcepawn

*Posted in wrong section.. >Sourcemod*

//VikingVrede

Last edited by VikingVrede; 04-22-2017 at 10:55. Reason: Posted in wrong section... my apologies,
VikingVrede is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-22-2017 , 09:07   Re: SourcePawn beginner Help
Reply With Quote #2

For starters, you definitely won't learn it in the AMXX Pawn section.
__________________

Last edited by OciXCrom; 04-22-2017 at 09:08.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 04-22-2017 , 15:44   Re: SourcePawn beginner Help
Reply With Quote #3

Quote:
Originally Posted by VikingVrede View Post
Hello im new to SourcePawn, and im pretty lost and confused. I have been reading Wiki page and such
but when looking at GameEvents/Functions i don't know how to put them together and actually make an plugin out of it. Example, i would like to print out a message to client once event "player_death" gets fired.

Or let's say Function " int GetClientFrags(int client) " i want to return value and somehow store it so it could be used for ex, Rank stats. I have been getting a good understanding of varibles, Strings, arrays and so on (But don't understand how to use it/situations where i want to use it). I have also been learning a bit of Python because it was recommended for "Non programmers" I can definitely see patterns when looking at SourcePawn code/Events/Functions but i just don't know how to put them together.

I really want to learn sourcepawn (I have the motivation), im a big community player from way back in 1.6 and source. I have alot of good ides and i want to make them come true and share with the Community here at Alliedmodders. I can see that c++ is also recommended knowing. Worth learning? will it give me a better picture when coding/Scripting sourcepawn

*Posted in wrong section.. >Sourcemod*

//VikingVrede
C++ is closer to SourcePawn than python, but python is easier to learn. "int GetClientFrags(int client)" is a definition of a function and the "int" in front means that the function is going to return an integer. Learn how to declare variables so you can save the returned integer and then use it elsewhere.

PHP Code:
int GetClientFrags(int client) { 
 
//do stuff
 
return integer;
}

void AnotherFunction(int client) {
 
int frags;
 if (
IsValidClient(client)) {
 
frags GetClientFrags(client);
 
//do stuff
 
}

Useful links:
http://www.cplusplus.com/doc/tutorial/
http://sourcemod.net/new-api/
https://forums.alliedmods.net/forumdisplay.php?f=112
https://forums.alliedmods.net/forumdisplay.php?f=107
https://wiki.alliedmods.net/Introduc...rceMod_Plugins
You can also learn a lot by studying plugins made by skilled programmers here
__________________
luki1412 is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 04-22-2017 , 20:24   Re: SourcePawn beginner Help
Reply With Quote #4

SourceMod isn't similar to python. It's probably better to just pick one.

As you know in most languages there are what is called "primitive types" which you can think of as the most basic types. The following are the types that you'll likely use most in sourcemod.
Code:
int char float
Observe the function below.
PHP Code:
int AddTwoNumbers(int aint b
{
    return 
b;

The function header (or signature) tells us information about how we use the function. First it tells us that the return type is an int. Second, the name of the function is given, and then the parameter list. That means we can use this function like below.
PHP Code:
int sum;

sum AddTwoNumbers(32); 
Cool huh?

Now lets make it so it'll print the sum to chat!

PHP Code:
int sum;

sum AddTwoNumbers(32);

// The %i is a way to tell the program to insert an int
// and then we have to provide that integer after
PrintToChatAll("The sum is: %i"sum); 
Cool. Now put that in a command and you've done it!
This is a situation where we made a variable for a task. You'll definately use variables often when you need to store information.
headline is offline
VikingVrede
Junior Member
Join Date: Apr 2017
Old 04-27-2017 , 17:46   Re: SourcePawn beginner Help
Reply With Quote #5

Already visited those links, Still finding it hard to understand. Is there a more in depth tutorial out there somewhere? At the moment this is just a matter of Pasting stuff together in hope of getting it to work with out having an understanding of what im typing. Been following wiki from start to end yet i do not know how to make a plugin thats not just a copy on "Introduction to sourcemodPlugins wikiPage" It explains how to make admin commands and so on, but what if i would like to make a command that displays client frags in chat? ( Making the command itself is no issue, it was clearly explained )
Does the Sourcepawn wiki provide that? Feels like there is more to learn outside wiki

Functions from include ex, returning value from function. Been reading wiki allover again. But there is not much text/information about "declare variables"
Quote:
Originally Posted by luki1412 View Post
C++ is closer to SourcePawn than python, but python is easier to learn. "int GetClientFrags(int client)" is a definition of a function and the "int" in front means that the function is going to return an integer. Learn how to declare variables so you can save the returned integer and then use it elsewhere.

PHP Code:
int GetClientFrags(int client) { 
 
//do stuff
 
return integer;
}

void AnotherFunction(int client) {
 
int frags;
 if (
IsValidClient(client)) {
 
frags GetClientFrags(client);
 
//do stuff
 
}

Useful links:
http://www.cplusplus.com/doc/tutorial/
http://sourcemod.net/new-api/
https://forums.alliedmods.net/forumdisplay.php?f=112
https://forums.alliedmods.net/forumdisplay.php?f=107
https://wiki.alliedmods.net/Introduc...rceMod_Plugins
You can also learn a lot by studying plugins made by skilled programmers here

Last edited by VikingVrede; 04-27-2017 at 17:50.
VikingVrede is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 04-27-2017 , 17:59   Re: SourcePawn beginner Help
Reply With Quote #6

To hook events.

https://wiki.alliedmods.net/Events_(...Hooking_Events

Edit:

A list of events by game.

https://wiki.alliedmods.net/Game_Events_(Source)
__________________

Last edited by Neuro Toxin; 04-27-2017 at 18:00.
Neuro Toxin is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 04-27-2017 , 21:39   Re: SourcePawn beginner Help
Reply With Quote #7

Quote:
Originally Posted by VikingVrede View Post
Already visited those links, Still finding it hard to understand. Is there a more in depth tutorial out there somewhere? At the moment this is just a matter of Pasting stuff together in hope of getting it to work with out having an understanding of what im typing. Been following wiki from start to end yet i do not know how to make a plugin thats not just a copy on "Introduction to sourcemodPlugins wikiPage" It explains how to make admin commands and so on, but what if i would like to make a command that displays client frags in chat? ( Making the command itself is no issue, it was clearly explained )
Does the Sourcepawn wiki provide that? Feels like there is more to learn outside wiki

Functions from include ex, returning value from function. Been reading wiki allover again. But there is not much text/information about "declare variables"
I can definitely say I had a similar issue when I first started programming in SourcePawn. Outside of the wiki and people on here, there is very little help available. It may seem like its extremely difficult to dive in and start learning, but its definitely possible. I very highly recommend setting a goal of something you would like to make(not too big) and trying to figure it out on your own. The hardest part of coding for me was understanding that you have to code to learn to code. There is a very fine line between understanding/being able to read code and being able to write code(functional), and reading other code just simply isn't enough.

Good luck with whatever your are trying to do. Feel free to add me and ask me questions if you would like.
__________________
Taking paid plugin requests
africanspacejesus is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-28-2017 , 02:21   Re: SourcePawn beginner Help
Reply With Quote #8

Quote:
Originally Posted by VikingVrede View Post
But there is not much text/information about "declare variables"
Have you read https://wiki.alliedmods.net/Introduc...SourcePawn_1.7?

With an understanding of the language, plus the short tutorial on writing a first plugin, you're at the point where you need to start exploring the API and reading other plugins to see what is possible.
__________________

Last edited by asherkin; 04-30-2017 at 14:13.
asherkin is offline
VikingVrede
Junior Member
Join Date: Apr 2017
Old 04-29-2017 , 17:44   Re: SourcePawn beginner Help
Reply With Quote #9

Hello! yes i have been reading these
1# https://wiki.alliedmods.net/Introduc...SourcePawn_1.7
2# https://wiki.alliedmods.net/Introduction_to_sourcepawn

I have been re-reading alot and starting to see more patterns but im not at the point of being ready for API yet because once i enter a function i do not know what to do with it. I understand it's function but when looking at this reply

Code:
int GetClientFrags(int client) {  
 //do stuff 
 return integer; 
} 

void AnotherFunction(int client) { 
 int frags; 
 if (IsValidClient(client)) { 
 frags = GetClientFrags(client); 
 //do stuff 
 } 
}
When i saw this i got really confused, Been reading wiki quite a alot
and when i goto " https://sm.alliedmods.net/new-api/cl...GetClientFrags " Information says
Return value, Error and the line of code with type, Function name and parameter. At the example code above there is //Do stuff < Im not sure what to do. My way of thinking when looking at code is, Make a new function for a Function. Create a varible (frags) to store value from ClientFrags. then display its value by "%i", client/frags); < something in that style. I have been playing around with example codes but im not getting it to work, wont compile. I have a understanding of language, i have followed how to make first plugin guide. With help of wiki i was able to customize some of the example code to create a plugin that displayed a CenterHint message once a Teammate died. I did download some plugins and read its Sp. But with so much code all at once..




Quote:
Originally Posted by asherkin View Post
Have you read https://wiki.alliedmods.net/Introduc...SourcePawn_1.7 ?

With an understanding of the language, plus the short tutorial on writing a first plugin, you're at the point where you need to start exploring the API and reading other plugins to see what is possible.
Could someone write a plugin that displays player kills in chat when executing a console/Chat command so i can observe? From a scale of 1-10 how hard is it to write such a plugin?
VikingVrede is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 04-29-2017 , 19:07   Re: SourcePawn beginner Help
Reply With Quote #10

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;


Last edited by Kolapsicle; 04-29-2017 at 19:09.
Kolapsicle 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 15:49.


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