SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   Little coding questions - For general minor queries 5 (https://forum.sa-mp.com/showthread.php?t=30938)

!damo!spiderman 21/03/2008 04:00 AM

Little coding questions - For general minor queries 5
 
The last topic was getting full so I decided to make a new one again.
Use the search on the forums to search for your question before posting here. Chances are its already be answered.

Part 1: Missing in action
Part 2: Missing in action
Part 3: Missing in action
Part 4: Missing in action

Don't paste big scripts in that topic, use pastebin for that.
If you don't know how to port your script to 0.2, post/ask in the 0.1 to 0.2 topic.

First help should be ALWAYS the IRC-channel irc.sa-mp.com #sa-mp.scripting. If you can't join use this thread as place to ask if you need some help with a code snippet or something doesn't work. Scripting Beginners should check the intro first.

Antironix 21/03/2008 12:02 PM

Re: Little coding questions - For general minor queries 5
 
Can filterscripts been called from a gm? Is there something that will get return the running FS?

!damo!spiderman 21/03/2008 12:05 PM

Re: Little coding questions - For general minor queries 5
 
You can load a fs from the gamemode using SendRconCommand

!damo!spiderman 21/03/2008 12:13 PM

Re: Little coding questions - For general minor queries 5
 
Yes there is.. native function.. GetServerVarAsString will do it..

GetServerVarAsString( "Filterscripts", buffer[], len );

Antironix 21/03/2008 01:02 PM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by !damo!spiderman
Yes there is.. native function.. GetServerVarAsString will do it..

GetServerVarAsString( "Filterscripts", buffer[], len );

Oke, thanks!

yom 21/03/2008 01:05 PM

Re: Little coding questions - For general minor queries 5
 
Ya, but when you use GetServerVarAsString("filterscripts".. it returns only the first on the line, as with gamemode0 etc, it doesn't return the 'repeat number', it seem to ignore all after the space

Redirect Left 21/03/2008 10:21 PM

Re: Little coding questions - For general minor queries 5
 
My script reboots itself upon the script ending and the team finishing the objective, sometimes the server crashes though whilst reloading the script, is this a SA:MP instability or a script erorr?

Pixels^ 22/03/2008 02:54 PM

Re: Little coding questions - For general minor queries 5
 
Script most likely.

ConTron 22/03/2008 09:03 PM

Re: Little coding questions - For general minor queries 5
 
Hi there :)

I have a menu option for my script
When i click the option nothing happens
Why is this?

pawn Code:
case 0:{
     SendClientMessage(playerid,COLOR_LIGHTBLUE,"[!]Teleported to: SF Biffin Bridge Hotel");
     HideMenuForPlayer(sftp, playerid);
     if(IsPlayerInAnyVehicle(playerid)) {
        new vid =GetPlayerVehicleID(playerid);
        SetVehiclePos(vid,-2456.4417,137.2120,34.8212);
     }else{
         SetPlayerPos(playerid,-2456.4417,137.2120,34.8212);
        }
      }
Is the option.

mabako 22/03/2008 11:13 PM

Re: Little coding questions - For general minor queries 5
 
[SCF]ConTron:

if it doesn't show the SendClientMessage, you're doing something wrong somewhere else. Plus you don't need HideMenu in the callback for when a row was selected. (however it may be called)

ConTron 23/03/2008 10:11 AM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by mabako
[SCF]ConTron:

if it doesn't show the SendClientMessage, you're doing something wrong somewhere else. Plus you don't need HideMenu in the callback for when a row was selected. (however it may be called)

I dont get it though, i copied it from a working bit of the menu. I just dont know why it dosent teleport me :(

Redirect Left 24/03/2008 02:05 AM

Re: Little coding questions - For general minor queries 5
 
Are there any known limits on how many people can be banned? I mean, surely eventually the samp ban file will become so big it'll be hard to read, and slow down stuff, yes/no?

(Sorry, I'm just trying to debug my servers instability and my SSH reporting weird errors)

!damo!spiderman 24/03/2008 05:03 AM

Re: Little coding questions - For general minor queries 5
 
We were just discussing this actually... a ban file of over 1000 you'll see a considerable amount of increase in cpu usage. For larger servers we'd probably suggest using a sqllite database to check for bans. Or just clear you ban file every couple of months

Dabombber 25/03/2008 01:27 AM

Re: Little coding questions - For general minor queries 5
 
For strings in enumerations, something like

Code:

enum e_test { bla[50] }
new test[e_test];
printf("sizeof bla = %i", sizeof(test[bla]));

works fine, but how would you get the size from a multidimensional array like

Code:

new test[10][e_test]

yom 25/03/2008 02:08 AM

Re: Little coding questions - For general minor queries 5
 
Edit: sorry misread.

!damo!spiderman 25/03/2008 06:40 AM

Re: Little coding questions - For general minor queries 5
 
pawn Code:
sizeof( test[0][bla] );
Replace 0 with whatever cell you want to check

Dabombber 25/03/2008 07:28 AM

Re: Little coding questions - For general minor queries 5
 
Code:

enum e_test { bla[50] }
new test[10][e_test];
printf("sizeof bla = %i", sizeof(test[0][bla]));

doesn't even compile

homie.pl 25/03/2008 02:39 PM

Re: Little coding questions - For general minor queries 5
 
Try
Code:

enum e_test { bla[50] }
new test[10][e_test];
printf("sizeof bla = %i", strlen(test[0][bla]));

I've got also question about multidimensional array but with enumeration. When I create for example array:
Code:

new ObjectInfo[200][oInfo];
that has enumeration:
Code:

enum oInfo
{
        realid[MAX_PLAYERS],
        modelid,
        Float:x,
        Float:y,
        Float:z,
        Float:rx,
        Float:ry,
        Float:rz,
        bool:isset[MAX_PLAYERS]
}

then I put numbers in and I print the modelid of first 8 dimensions from array
Code:

[15:57] 615
[15:57] 615
[15:57] 615
[15:57] 3249
[15:57] 3241
[15:57] 744
[15:57] 744
[15:57] 744

This is what I need. Everything is proper. But when I change

Code:

new ObjectInfo[200][oInfo];
to
Code:

new ObjectInfo[][oInfo];
I get printed
Code:

[15:58] 0
[15:58] 579
[15:58] 615
[15:58] 0
[15:58] 3241
[15:58] 744
[15:58] 744
[15:58] 744

As you can see few numbers are printed correctly, but rest not.

And here's my question, why does it happen. And I cannot use number to set number of dimensions, because I'd have to use 5000 which makes my script almost 2MB large.

homie.pl 25/03/2008 07:10 PM

Re: Little coding questions - For general minor queries 5
 
Ok but when I set number of dimensions I get 2MB amx... Is there any way to reduce this size?

Backwardsman97 28/03/2008 01:37 AM

Re: Little coding questions - For general minor queries 5
 
Did they clean up this topic?

!damo!spiderman 28/03/2008 03:49 AM

Re: Little coding questions - For general minor queries 5
 
Read the first page.. There's a link to old topics from this..

THoM 29/03/2008 12:23 PM

Re: Little coding questions - For general minor queries 5
 
What would be the easiest way to create a poker script?
I need to define all the cards at least, but how to make so that the cards will be randoms for every player?

Just give me the functions i need, and I'll try to set it up on my own.

Regards, Thom

!damo!spiderman 29/03/2008 12:27 PM

Re: Little coding questions - For general minor queries 5
 
You'd have to write all your own functions to do this basically... cus you need to make sure that the players only get cards which are still in the pack etc. You'll need an array of all the cards etc. There's actually a few tutorials for c++ etc which explain how this could be done on the internet.. you'd just need to get the idea of what needs to happen and convert it to pawn basically

THoM 29/03/2008 01:33 PM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by !damo!spiderman
You'd have to write all your own functions to do this basically... cus you need to make sure that the players only get cards which are still in the pack etc. You'll need an array of all the cards etc. There's actually a few tutorials for c++ etc which explain how this could be done on the internet.. you'd just need to get the idea of what needs to happen and convert it to pawn basically

Thanks.

I've got another question.
What would be the closest function to force someone to use filterscript ( or something similiar )

!damo!spiderman 29/03/2008 01:37 PM

Re: Little coding questions - For general minor queries 5
 
Force someone to use it? As in load it with the gamemode?

You can use SendRconCommand() and send the string "loadfs <insert your fs name here>"

THoM 30/03/2008 09:11 AM

Re: Little coding questions - For general minor queries 5
 
Thanks spiderman, that helped a lot. I'll add it, and figure out how to get it working.

The reason why i wanted to force someone to use filterscript was, well this might sound pretty stupid since there's probably an easier way, but i wanted so that OnPlayerDeath the player will be forced to use CAM, which is a filterscript made for spectating.
Just was too lazy to create my own lol

Regards, Thom.

MATT11504 03/04/2008 08:59 PM

Re: Little coding questions - For general minor queries 5
 
im having trouble using GetPlayerWeapon.
weaponid = GetPlayerWeapon(playerid)
if (weaponid = 35)
{
SendClientMessage(playerid,COLOR_RED,"TEST");
}
but it says the weaponid = line is an invalid function or decleration and the same for l the if (weaponid = 35) line
any examples of how GetPlayerWeapon is used?

Backwardsman97 05/04/2008 04:27 AM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by MATT11504
im having trouble using GetPlayerWeapon.
pawn Code:
weaponid = GetPlayerWeapon(playerid)
if (weaponid = 35)
{
SendClientMessage(playerid,COLOR_RED,"TEST");
}
but it says the weaponid = line is an invalid function or decleration and the same for l the if (weaponid = 35) line
any examples of how GetPlayerWeapon is used?

pawn Code:
if (weaponid == 35)

Shouldn't it be like that?

Redirect Left 05/04/2008 06:55 PM

Re: Little coding questions - For general minor queries 5
 
Is there a function I can use to clone a file, but change the file name, useful for cloning players that change name ingame.
Next, is there a delete file function in PAWN?

Redirect Left 07/04/2008 11:18 AM

Re: Little coding questions - For general minor queries 5
 
No, it's usually quicker to just ask. Seeing as people here usually reply quite quick.

Pixels^ 08/04/2008 12:31 AM

Re: Little coding questions - For general minor queries 5
 
Is there a way I can create a byte variable? In VB it's
Code:

Dim ByteVar As Byte
but I don't know how to do it in Pawn.

It might be an easy thing to figure out but I can't for some reason. Searching pawn-lang.pdf atm. Wiki has no documentation on single byte variables.

Simon 08/04/2008 05:06 AM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by Pixels^
Is there a way I can create a byte variable? In VB it's
Code:

Dim ByteVar As Byte
but I don't know how to do it in Pawn.

It might be an easy thing to figure out but I can't for some reason. Searching pawn-lang.pdf atm. Wiki has no documentation on single byte variables.

Pawno is a typeless language, all variables are the same size. If you want to create a byte then you can split a cell into four bytes and do some binary manipulation (binary and/or/xor). There's a set of symbols that can do the binary manipulation for you (it's precompiled) as a char for packed strings.

pawn Code:
new MyString[20 char] = !"aavi: Hey listen!";

MyString{0} = 'N';

Search for packed strings in pawn-lang.pdf, you could possibly use them like bytes.

ZarduK 12/04/2008 02:33 PM

Re: Little coding questions - For general minor queries 5
 
Is it possible to use a variable in a filterscript that is set in another (compiled) filterscript or a gamemode script?

Like this:

[code=Filterscript 1.pwn]
#include <a_samp>

gPlayerMoney[playerid];

public OnPlayerConnect(playerid)
{
gPlayerMoney[playerid] = 50000;
}
[/code]

[code=Filterscript 2.pwn]
#include <a_samp>

extern gPlayerMoney[playerid]; // maybe replace extern with a special declaration?!

public OnPlayerDeath(playerid)
{
gPlayerMoney[playerid] =- 1000;
}
[/code]

EDIT: Just found a workaround... Saving the variable to a File and then reading it from the other Filterscript...

Pixels^ 12/04/2008 04:14 PM

Re: Little coding questions - For general minor queries 5
 
Files are overkill, use CallRemoteFunction on a special function that gets or sets the variable to a specific value.

ZarduK 13/04/2008 08:01 PM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by Pixels^
CallRemoteFunction

Thats what I was looking for! Thanks!

Daddy01 14/04/2008 12:54 PM

Re: Little coding questions - For general minor queries 5
 
Can you help me:

new float:health;
GetPlayerHealth(killerid,health);
SetPlayerHealth(killerid,health +50);

The compiler is saying Tag mismatch

it is supposed to kive the killer 50 live back if he kills someone.

//I Just had to write float with a capital letter :D

Cueball 16/04/2008 03:32 AM

Re: Little coding questions - For general minor queries 5
 
I was wondering if there is a more efficient way to check the value of a variable: i (i is used in a for loop).

I am currently doing this:
pawn Code:
for(new i = 0; i <= MAX_PLAYERS; (i != playerid) ? i++ : i += 2)
{
  print("Simon is a nubzorz."); // Not actually doing this, but w/e.
}

This gives me the following errors:
Code:

C:\PROGRA~1\ROCKST~1\GTASAN~1\Samp\GAMEMO~1\para.pwn(263) : error 022: must be lvalue (non-constant)
C:\PROGRA~1\ROCKST~1\GTASAN~1\Samp\GAMEMO~1\para.pwn(263) : warning 215: expression has no effect
C:\PROGRA~1\ROCKST~1\GTASAN~1\Samp\GAMEMO~1\para.pwn(263) : error 001: expected token: ";", but found ")"
C:\PROGRA~1\ROCKST~1\GTASAN~1\Samp\GAMEMO~1\para.pwn(263) : error 029: invalid expression, assumed zero
C:\PROGRA~1\ROCKST~1\GTASAN~1\Samp\GAMEMO~1\para.pwn(263) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664                          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.

Line 263 is the for() line.

I know you can simply check with a continue statement, but I wondered if there was a 'safer' way.

The .pdf said that the variable must be non-constant, so that it can be modified, so I wasn't sure how that variable was not constant.

I did try asking on IRC, but it appeared that everybody was busy, idling, or perhaps just ignoring me :s

Thanks in advance,

~Cueball~

!damo!spiderman 16/04/2008 04:27 AM

Re: Little coding questions - For general minor queries 5
 
I just answered on irc but I'll answer here too so people can reference it later

pawn Code:
for( new i = 0; i < MAX_PLAYERS; (i==2) ? (i++):(i+=2)){}
You'll get a Warning about expression having no effect but it can be ignored

Cueball 16/04/2008 04:38 AM

Re: Little coding questions - For general minor queries 5
 
Thanks damo, I also tried that (placing the possible options in brackets), but I did recieve the warnings, so I moved on. Now it seems that I will be stuck with the warnings, so I'm wondering if there is a way to compile cleanly with this method (not using a continue statement)?

Thanks again,

~Cueball~

!damo!spiderman 16/04/2008 04:51 AM

Re: Little coding questions - For general minor queries 5
 
pawn Code:
for( new i = 0; i < MAX_PLAYERS; i=(i==2) ? (i++):(i+2))


All times are GMT. The time now is 06:32 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.