[Tutorial] Usage and explanation of miscellaneous functions - Part 1
#1

Usage and explanation of miscellaneous functions - Part 1


Hi there guys, Okay, So I've created this tutorial to explain how you can use miscellaneous functions and use them to make better servers, filterscripts and etc.


This tutorial will include:

1. CreatePickup - Everything about creating pickups
2. SetPlayerSkillLevel - Everything about weapon skill levels and etc.
3. PlayCrimeReportForPlayer - Interesting feature, But sadly, not much used due to unpopularity


__________________________________________________ __________________________________________________ ____________________________________



1. CreatePickup

Syntax: CreatePickup(model, type, Float:X, Float:Y, Float:Z, Virtualworld)

Models : https://sampwiki.blast.hk/wiki/Game_Object_ID_List
P.S: You can make a pickup out of any object, But if you're looking for the mainly used pickups, Have a look here too: http://weedarr.wikidot.com/pickups/

Pickup types: https://sampwiki.blast.hk/wiki/PickupTypes

Making:
Okay, So to make a simple pickup with CreatePickup, You start with declaring a variable.

pawn Код:
new Pickup;
This simple declares nothing. Yes, You can go on further and create something else with that name, Just naming it Pickup doesn't mean the compiler will itself make it a pickup. So, the next thing, You start with making it


pawn Код:
public OnGameModeInit()
{
    pickup = CreatePickup(model, type, Float:X, Float:Y, Float:Z, Virtualworld)
    return 1;
}
That just creates a pickup at your desired position. Now what I'm going to do is create a simple pickup in grove street which sets your armour to 100. First, You get grove street's coords. Go ingame and go to the place you want the pickup to be. Then do /save Pickup.

You'll have something like in savedpositions.txt in "Documents/GTA San Andreas Userfiles/SAMP"


pawn Код:
AddPlayerClass(playerid, 2491.7900, -1668.1653, 13.3438, 269.15, 0, 0, 0, 0, 0, 0);
Now, Here's the syntax for AddPlayerClass:

AddPlayerClass(skin, Float, Float:y, Float:z, Float:Angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)

What you need is the X, Y and Z

So you just take the


pawn Код:
2491.7900, -1668.1653, 13.3438
And put it in this


pawn Код:
public OnGameModeInit()
{
    pickup = CreatePickup(1242, 2 ,2491.7900, -1668.1653, 13.3438, 0)
    /// This creates a pickup with model 1242 (Armour) and Spawn type 2 (Respawns after some time) at coords 2491.7900, -1668.1653, 13.3438 with virtual world 0
    return 1;
}
Congrats! You've successfully created a pickup on the grove street! But guess what? This one doesn't do anything right now. We'll have to create a reaction to this.

Correction:
Quote:
Originally Posted by Vince
Посмотреть сообщение
What I've noticed in-game is that some pickups (health, armor) actually DO have their own effect. Or at least with some pickup types. I know this because I was messing around with a function I wrote, OnPlayerArmorChange. When the pickup gets picked up, the player's amor changes to 100.0. On the next tick it changes to 99.9, which is what I've set with SetPlayerArmour in OnPlayerPickUpPickup.
For this, We'll go to OnPlayerPickUpPickup and implement our code.

We're gonna be using a switch, SendClientMessage and SetPlayerArmour in this part, Make sure you get familiar with them :

SendClientMessage : https://sampwiki.blast.hk/wiki/SendClientMessage
Switch: https://sampwiki.blast.hk/wiki/Control_Structures#switch_2
SetPlayerArmour: https://sampwiki.blast.hk/wiki/SetPlayerArmour


Okay, so we start by creating a switch to switch between the pickup id's.

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    switch(pickupid)
    {
         case Pickup:
         {
              // We're gonna do our shit here
          }
    }
    return 1;
}
That's a switch. I'm gonna teach you how to use if-elseif-elseif thing because this method is way better BUT still some of you who are a bit too new to the scripting and programming part might find this difficult

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == Pickup)
    {
         // We're gonna do our shit here
    }
    return 1;
}
So the shit remains the same, The only thing that changes? It's the structure of detecting what pickup will do what.

So, We start doing some actual stuff now, Which is creating a reaction:


pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    switch(pickupid)
    {
         case Pickup:
         {
              SetPlayerArmour(playerid, 100); // We set the player armour to 100.
              SendClientMessage(playerid, -1, "Congrats! You just picked up my first pickup! Bonus armour for you! "); // We alerted the player that he just picked up our first bonus!
          }
    }
    return 1;
}
OR

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == Pickup)
    {
         SetPlayerArmour(playerid, 100); // We set the player armour to 100.
         SendClientMessage(playerid, -1, "Congrats! You just picked up my first pickup! Bonus armour for you! "); // We alerted the player that he just picked up our first bonus!
    }
    return 1;
}
Cool, no? Congrats man! You just created a pickup! It's quite easy to create pickups and create reactions to them, A ll you need to do is get more familiar with if-elseif-elseif or switch structures, They're the major parts


__________________________________________________ __________________________________________________ ____________________________________


2. SetPlayerSkillLevel


Syntax: SetPlayerSkillLevel(playerid, skill, level)
Skills: https://sampwiki.blast.hk/wiki/Skillweapons
Level : Ranging from 0 to 1000 , 1000 is hitman skill, which gives bonus
Alright, I'm sure all of you have played single player at SOME point. You should remember that killing random peds around got you weapon skills. Yep, That's what this function is about. It's about creating skills and limiting them.
You might want a simple skill system, or something for your server, which makes the player kill players before getting the bonus for that weapon. This function is meant exactly for that.

Ever wondered why you directly got 2 Tec 9's instead of 1 in SAMP? Because by default, If the scripter DOES NOT set the skill level, It's full by default. Which means you'll automatically get:

2 Sawn offs if you don't use SetSkillLevel
Moving bonus while shooting with many weapons if you don't use SetSkillLevel
And more!

Basically, It's a weapon skill system.
I'd suggest you get more familiar with the weapon skill system here before we proceed further: http://www.gtagaming.com/sanandreas/weaponskills

There's nothing real I can teach you but I'm sure it'll be fun to test this stuff, So, here's what we're gonna do:

We're gonna create 2 simple commands with ZCMD which set the skill of sawn off shotguns and we're gonna test them to know what makes a difference.

I'd like you to get familiar with SendClientMessage,ResetPlayerWeapons, GivePlayerWeapon, ZCMD and SetPlayerSkillLevel before we proceed:

SendClientMessage: https://sampwiki.blast.hk/wiki/SendClientMessage
ZCMD: https://sampwiki.blast.hk/wiki/Zcmd
SetPlayerSkillLevel : https://sampwiki.blast.hk/wiki/SetPlayerSkillLevel
ResetPlayerWeapon : https://sampwiki.blast.hk/wiki/ResetPlayerWeapons
GivePlayerWeapon: https://sampwiki.blast.hk/wiki/GivePlayerWeapon

Alright, I'm not gonna teach you how to create a CMD with ZCMD processor, I'm just gonna jump and straight away explain the code


pawn Код:
CMD:test1(playerid,params[])
{
    ResetPlayerWeapons(playerid);
    SetPlayerSkillLevel(playerid, WEAPONSKILL_SAWNOFF_SHOTGUN, 0);
    SendClientMessage(playerid, -1, "Sawn off skill set to 0and sawn off given ");
    GivePlayerWeapon(playerid, 26, 500);
    return 1;
}

CMD:test2(playerid,params[])
{
    ResetPlayerWeapons(playerid);
    SetPlayerSkillLevel(playerid, WEAPONSKILL_SAWNOFF_SHOTGUN, 1000);
    SendClientMessage(playerid, -1, "Sawn off skill set to 1000 and sawn off given ");
    GivePlayerWeapon(playerid, 26, 500);
    return 1;
}

Basically, when you type test1, It'll give you 1 sawn off with 1000 ammo, and when you type test2, It'll give you 2 sawn offs with 1000 ammo.

1000 skill level automatically sets your weapon skill to Double Weapon Hitman Skill Level or just Hitman Skill Level and 0 Skill level automatically sets your weapon skill to Poor (Means no bonus)


__________________________________________________ __________________________________________________ ____________________________________

3. PlayCrimeReportForPlayer


Syntax: PlayCrimeReportForPlayer(playerid, suspectid, crimeid)
Okay, lemme explain now
First of all, playerid is the guy who'll hear the report.
Second of all, suspectid is the guy who'll be the suspect in the report.
Third of all, Crimeid is the code/sound/report which will be played.
This function is VERY useful for cops and robbers servers and RP servers as it'll make them more realistic.

You can find the crime ID's here: https://sampwiki.blast.hk/wiki/Crime_List
And to make 'em more realistic, You can refer here too : http://www.linuxthefish.net/10-codes.html

Suppose you want to create a case in which a riot is happening, You'll be using CODE: 17 in SAMP or '10-34' code in police language.

pawn Код:
CMD:riot(playerid,params[])
{
    PlayCrimeReportForPlayer(playerid, playerid, 17);
    SendClientMessage(playerid, -1, "MOTHER OF GOD! NO SHIT, THERE'S A RIOT! ");
    return 1;
}
That simply declares a riot


I hope you guys enjoyed the tutorial

P.S: I'm sorry for the untidiness
Reply
#2

Good tutorial.. keep it up brotha!! ..

+Repped.
Reply
#3

nice tutorial good job mate
Reply
#4

What I've noticed in-game is that some pickups (health, armor) actually DO have their own effect. Or at least with some pickup types. I know this because I was messing around with a function I wrote, OnPlayerArmorChange. When the pickup gets picked up, the player's amor changes to 100.0. On the next tick it changes to 99.9, which is what I've set with SetPlayerArmour in OnPlayerPickUpPickup.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
What I've noticed in-game is that some pickups (health, armor) actually DO have their own effect. Or at least with some pickup types. I know this because I was messing around with a function I wrote, OnPlayerArmorChange. When the pickup gets picked up, the player's amor changes to 100.0. On the next tick it changes to 99.9, which is what I've set with SetPlayerArmour in OnPlayerPickUpPickup.
Wow, that's something I didn't know. Thanks for posting it, Added to the tutorial.
Reply
#6

Thank you! with your pickup tut i was able to create like a little event that notifies everyone that a player has found a money bag and picked up go kill him xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)