PDA

View Full Version : Beginner plugin help!


TheNeus
03-23-2015, 15:16
Hey, there! So, this is my first day learning sourcepawn, I am still learning, and I was wondering if anyone could help me with my first plugin. It's really simple, I tried to make that when player spawns, his FOV changes to maximum and then decreases to normal in medium speed. I saw it on one server but never seem to find the actual plugin so I tried to make it myself (using other plugins). Please excuse my mistakes however stupid they are because again this is my first day learning. Thanks in advance. :3

#include <sourcemod>
#include <sdkhooks>
public Plugin:myinfo ={
author = "---",
description = "---",
url = "---"
}
public OnPluginStart()
{
HookEvent("player_spawn", Player_Spawn, EventHookMode_PostNoCopy);
}
public Action:Player_Spawn(Handle:hEvent, String:strEventName[], bool:bDontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
new fov = 130;
for(fov > 75)
{
fov --;
SetEntProp(client, Prop_Send, "m_iFOV", fov);
SetEntProp(client, Prop_Send, "m_iDefaultFOV", fov);
}
}

Darkness_
03-23-2015, 15:53
That's not how you execute a for loop - in fact, that is very close to a while loop. A for loop is:
for(INITIALIZATION; CONDITION; INCREMENT/DECREMENT){
// Code for the for loop's body
// goes here.
}
In your case it would be something along the lines of
for (int fov = 130; fov > 75; fov--) {
SetEntProp(client, Prop_Send, "m_iFOV", fov);
SetEntProp(client, Prop_Send, "m_iDefaultFOV", fov)
}
Or if you want to use a while loop.
int fov = 130
while (fov > 75) {
SetEntProp(client, Prop_Send, "m_iFOV", fov);
SetEntProp(client, Prop_Send, "m_iDefaultFOV", fov)
fov--;
}

However, a for loop isn't want you are looking for if you are trying to make the FOV decresase at a 'medium speed'. What you need is a timer that repeats every second to two. Check out the timer documentation here https://wiki.alliedmods.net/Timers_(SourceMod_Scripting)

TheNeus
03-23-2015, 17:32
Thanks so much! :) <3

Franc1sco
03-23-2015, 17:35
You have all here http://wiki.alliedmods.net/index.php/Category:SourceMod_Scripting
Good luck!

Dr. Greg House
03-23-2015, 18:51
Old syntax...

Mitchell
03-24-2015, 00:23
Old syntax...

perhaps we should direct them to any other programming language new syntax source pawn resembles.

Dr. Greg House
03-24-2015, 01:54
Maybe we should just tell people that they're reading up on an old syntax and wasting their time until the wiki page has been updated.

xf117
03-24-2015, 03:44
Maybe we should just tell people that they're reading up on an old syntax and wasting their time until the wiki page has been updated.

And using new syntax which is same or less in functionality, not fully done and a subject of change is not wasting the time?

Drixevel
03-24-2015, 04:10
Learning old syntax is fine since changing how you use the new syntax from the old syntax is easy enough.

Dr. Greg House
03-24-2015, 14:03
And using new syntax which is same or less in functionality, not fully done and a subject of change is not wasting the time?

Since he is saving himself one transition by not learning the old syntax, yes. Do the math.

Learning old syntax is fine since changing how you use the new syntax from the old syntax is easy enough.

That's very subjective. Look at the first post, especially the code. Wouldn't you like to make him learn as few things as possible? Given that his problems are about syntax and conceptual thinking. He's a beginner on every possible level, you forget how not easy those first steps are, things that we have internalized to a level where we don't notice the effort.

Drixevel
03-24-2015, 21:09
Since he is saving himself one transition by not learning the old syntax, yes. Do the math.



That's very subjective. Look at the first post, especially the code. Wouldn't you like to make him learn as few things as possible? Given that his problems are about syntax and conceptual thinking. He's a beginner on every possible level, you forget how not easy those first steps are, things that we have internalized to a level where we don't notice the effort.

Learning old syntax is learning new syntax. You can say that's subjective but the old syntax has more of a structure to it where the new syntax has more of a creative structure with less boundaries. If you think that's my opinion then fine but you do have to at least uphold to the idea that him learning the old syntax is more beneficial right now since we have the most documentation for it and the wiki for tutorials on the language are still using the old syntax.

Since It's basically removing 'new' and making it so you use one operator and a space after sort of like how C does it as an example of one of the many changes, It's fairly easy to just cross over.

Dr. Greg House
03-24-2015, 22:02
Learning old syntax is learning new syntax.[...]

Fine, then learning any language is learning any other language.

[...]You can say that's subjective[...]

Yes. Which is why at this point I'd like to hear what the people upstairs say. So far a few months earlier their opinion was to use the new syntax, since it makes your life easier.

but the old syntax has more of a structure to it where the new syntax has more of a creative structure with less boundaries.[...]

Given that the new syntax introduces actual types whereas the old syntax had the "creative"/"structureless" usage of tags, I'd say the exact opposite is the case. The new syntax is way friendlier to people transitioning from other, modern languages, as well as for complete newbies.

[...]If you think that's my opinion then fine but you do have to at least uphold to the idea that him learning the old syntax is more beneficial right now since we have the most documentation for it and the wiki for tutorials on the language are still using the old syntax.[...]

Pull requests and edits are always welcome I guess. For now since the OP will be in the "I ask about everything"-phase he might as well get new syntax examples here, instead of old ones. Question is if he's learning for today or tomorrow, so to speak.

[...]Since It's basically removing 'new' and making it so you use one operator and a space after sort of like how C does it as an example of one of the many changes, It's fairly easy to just cross over.

No idea what you're trying to say here, but I'm sensing that youre saying transitioning between old and new syntax is "fairly easy". Then there would be no reason at all to learn the old syntax.

Drixevel
03-25-2015, 01:29
Fine, then learning any language is learning any other language.



Yes. Which is why at this point I'd like to hear what the people upstairs say. So far a few months earlier their opinion was to use the new syntax, since it makes your life easier.



Given that the new syntax introduces actual types whereas the old syntax had the "creative"/"structureless" usage of tags, I'd say the exact opposite is the case. The new syntax is way friendlier to people transitioning from other, modern languages, as well as for complete newbies.



Pull requests and edits are always welcome I guess. For now since the OP will be in the "I ask about everything"-phase he might as well get new syntax examples here, instead of old ones. Question is if he's learning for today or tomorrow, so to speak.



No idea what you're trying to say here, but I'm sensing that youre saying transitioning between old and new syntax is "fairly easy". Then there would be no reason at all to learn the old syntax.

I'm just suggesting we have him learn the new syntax whenever the Wiki is updated and the updates are finished but that might be a while since they're already working on Sourcemod 1.8 as well. It might be friendly for current programmers but it will confuse non-programmers, I know I heavily relied upon the wiki whenever I started. I'm gonna cut this conversation short since I'd rather not jack the guys thread and get all these posts deleted.