Jump to content

  •  





Basic Player vs Player Script

Posted by GmOcean, in 1. Beginner Scripts 25 November 2014 · 831 views

Basic Player vs Player Script ( 1 Part )
A Player vs Player script designed to introduce you to the basics needed to make them work.

Part 1
Okay this is going to be a short one. Despite what you may think, PvP scripts are actually very easy write and don't require much to get them to work.

Let's start off by making a floating NPC:
-    script    pvp_script    -1,{

So for this script, it is going to be a simple script that merely tells the player who it was that killed them. As well as giving he killer 1,000z. Simple right?
Let's start off by creating this label: OnPCKillEvent
OnPCKillEvent:

Now, this part is important. When a Player kills another player, 2 variables are set. killerrid (The Killer) and killedrid (The Dead one). Additionally, OnPCKillEvent automatically attaches the script to the killer.
So, before we decided to give them zeny, let's check to make sure they didn't commit suicide. Because that'd be cheating!
To do that we'll use the command: getcharid(<type>{,"<character name>"}) and check it against the id of the player killed. If they are the same, then the killer committed suicide, so we'll end the script early.
Let's add it in:
    if (getcharid(3) == killedrid) {
         end;
    }

Now that we've gotten that check out of the way, let's continue with the script and give the killer some zeny for doing a good job at slaying his opponent:
    Zeny += 1000;

Now we need to let the person who died know who killed him, so he can get revenge later. To do that we will use this command: attachrid(<account ID>).
Thankfully we already know what the dead person's account id is, because that is what killedrid is.
So let's add it in:
    attachrid(killedrid);

Now all that's left to do is let them know who killed them. We are going to use the command: dispbottom "<message>"; in combination with this command: rid2name(<rid>).
Now remember when I said there were 2 commands set, well we already used killedrid, so now we will be using killerrid to get the name of the killer.
Easy right? Let's add it in and end the script:
        dispbottom "You were killed by: "+ rid2name(killerrid) +"";
    end;
}

Once you've done that you are done. Your script should look something like this:
-	script	pvp_script	-1,{
OnPCKillEvent:
    if (getcharid(3) == killedrid) {
        end;
    }
    Zeny += 1000;
    attachrid( killedrid );
        dispbottom "You were killed by: "+ rid2name( killerrid ) +"";
    end;
}
I told you it was fast and simple.

Extra Information
There is just 1 more thing I want you to know about the label OnPCKillEvent and the variables killerrid and killedrid. If you read the link I gave you, it was very vague about what it does.
So let me explain in more detail:
1. When a player kills another player, the label OnPCKillEvent is triggered.
2. The script is automatically attached to the killer.
3. (Important) The variable ' killedrid ' holds the dead person's account_id number. BUT, only the killer has this variable.
4. (Important) The variable ' killerrid ' holds the killing person's account_id number. BUT, only the dead person has this variable.
So that's it, just remember that when writing your own scripts.